ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
arithmetical.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_enums of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_ENUMS_ARITHMETICAL
9#define HPP_ALIB_ENUMS_ARITHMETICAL 1
10
11#if !defined(HPP_ALIB) && !defined(ALIB_DOX)
12# include "alib/alib.hpp"
13#endif
14
16
17#if !defined (HPP_ALIB_LANG_TMP) && !defined(ALIB_DOX)
18# include "alib/lang/tmp.hpp"
19#endif
20
21namespace alib { namespace enums {
22
23// #################################################################################################
24// struct T_EnumIsArithmetical
25// #################################################################################################
26
27
28#if defined(ALIB_DOX)
29/** ************************************************************************************************
30 * Simple TMP struct that inherits <c>std::false_type</c> by default. If specialized for an
31 * enumeration type \p{TEnum} to inherit <c>std::true_type</c>, the following operators set of
32 * \alib operators become applicable to elements of \p{TEnum}:
33 *
34 * - \alib{enums::arithmetical;operator<}
35 * - \alib{enums::arithmetical;operator<=}
36 * - \alib{enums::arithmetical;operator>}
37 * - \alib{enums::arithmetical;operator>=}
38 * - \alib{enums::arithmetical;operator+}
39 * - \alib{enums::arithmetical;operator-}
40 * - \alib{enums::arithmetical;operator++}
41 * - \alib{enums::arithmetical;operator++(TEnum&;int)}
42 * - \alib{enums::arithmetical;operator--}
43 * - \alib{enums::arithmetical;operator--(TEnum&;int)}
44 * - \alib{enums::arithmetical;operator+=}
45 * - \alib{enums::arithmetical;operator-=}
46 *
47 * \attention
48 * Likewise with the operators introduced with TMP struct \alib{enums;T_EnumIsBitwise},
49 * this documentation "fakes" the operators into namespace <c>alib::enums</c>,
50 * while in fact they are defined in the global namespace!<br>
51 * See \ref alib_enums_arithmetic_standard "corresponding note" in the Programmer's Manual
52 * for details.
53 *
54 * <b>Restrictions</b><br>
55 * For technical reasons, this concept is not applicable to enum types that are defined as
56 * \c private or \c protected inner types of structs or classes.
57 *
58 * \see
59 * - Macro \ref ALIB_ENUMS_MAKE_ARITHMETICAL, which specializes this TMP struct for a given
60 * enumeration type.
61 * - For details and a source code sample see chapter \ref alib_enums_arithmetic_standard
62 * of the Programmer's Manual of module \alib_enums.
63 *
64 * @tparam TEnum The enum type to enable arithmetical operators for.
65 * @tparam TEnableIf This parameter has a default expressions and <b>must not</b> be provided
66 * with specializations of this struct.
67 * It is used to ensure that template parameter \p{TEnum} is an enumeration type.
68 **************************************************************************************************/
69template<typename TEnum,typename TEnableIf>
70struct T_EnumIsArithmetical : public std::false_type {};
71#else
72template<typename TEnum,
73 typename TEnableIf= ATMP_VOID_IF(std::is_enum<TEnum>::value)>
74struct T_EnumIsArithmetical : public std::false_type {};
75#endif
76
77
78} // namespace alib[::enums]
79/// Type alias in namespace \b alib.
80template<typename TEnum>
82
83} // namespace [alib]
84
85
86// #################################################################################################
87// Helper Macros
88// #################################################################################################
89
90#define ALIB_ENUMS_MAKE_ARITHMETICAL(TEnum) \
91namespace alib::enums { \
92template<> struct T_EnumIsArithmetical<TEnum> : public std::true_type {}; } \
93
94
95// #################################################################################################
96// Arithmetic Operators
97// #################################################################################################
98
99// For documentation, all operators and enum related template functions are faked into namespace
100// alib::enums
101#if defined(ALIB_DOX)
102namespace alib { namespace enums {
103
104/**
105 * Operators available to elements of enumerations if \alib{enums;T_EnumIsArithmetical} is
106 * specialized.
107 *
108 * \note
109 * This namespace exits only in the documentation to collect the operators.
110 * When parsed by a C++ compiler, <b>the operators reside in the global namespace</b>.
111 */
112namespace arithmetical {
113#endif
114
115
116/**
117 * Comparison operator \e less between an enum element and an integral value of underlying type.
118 *
119 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
120 * template enum type \p{TEnum} to inherit \c std::true_type.
121 *
122 * @tparam TEnum Enumeration type.
123 * @param lhs First operand.
124 * @param rhs Second operand.
125 * @return The result of the comparison.
126 */
127template<typename TEnum>
128constexpr
129#if defined(ALIB_DOX)
130bool
131#else
133#endif
134operator< (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
135{
136 using TValue= typename std::underlying_type<TEnum>::type;
137 return TValue(lhs) < rhs ;
138}
139
140/**
141 * Comparison operator <em>less or equal</em> between an enum element and an integral value of
142 * underlying type.
143 *
144 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
145 * template enum type \p{TEnum} to inherit \c std::true_type.
146 *
147 * @tparam TEnum Enumeration type.
148 * @param lhs First operand.
149 * @param rhs Second operand.
150 * @return The result of the comparison.
151 */
152template<typename TEnum>
153constexpr
154#if defined(ALIB_DOX)
155bool
156#else
158#endif
159operator<= (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
160{
161 using TValue= typename std::underlying_type<TEnum>::type;
162 return TValue(lhs) <= rhs;
163}
164
165/**
166 * Comparison operator <em>greater</em> between an enum element and an integral value of
167 * underlying type.
168 *
169 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
170 * template enum type \p{TEnum} to inherit \c std::true_type.
171 *
172 * @tparam TEnum Enumeration type.
173 * @param lhs First operand.
174 * @param rhs Second operand.
175 * @return The result of the comparison.
176 */
177template<typename TEnum>
178constexpr
179#if defined(ALIB_DOX)
180bool
181#else
183#endif
184operator> (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
185{
186 using TValue= typename std::underlying_type<TEnum>::type;
187 return TValue(lhs) > rhs;
188}
189
190
191
192/**
193 * Comparison operator <em>greater or equal</em> between an enum element and an integral value of
194 * underlying type.
195 *
196 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
197 * template enum type \p{TEnum} to inherit \c std::true_type.
198 *
199 * @tparam TEnum Enumeration type.
200 * @param lhs First operand.
201 * @param rhs Second operand.
202 * @return The result of the comparison.
203 */
204template<typename TEnum>
205constexpr
206#if defined(ALIB_DOX)
207bool
208#else
210#endif
211operator>= (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
212{
213 using TValue= typename std::underlying_type<TEnum>::type;
214 return TValue(lhs) >= rhs ;
215}
216
217
218/**
219 * Add operator between two enum elements.
220 *
221 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
222 * template enum type \p{TEnum} to inherit \c std::true_type.
223 *
224 * @tparam TEnum Enumeration type.
225 * @param lhs First operand.
226 * @param rhs Second operand.
227 * @return The resulting enum element.
228 */
229template<typename TEnum>
230constexpr
231#if defined(ALIB_DOX)
232TEnum
233#else
235#endif
236operator+ (TEnum lhs, TEnum rhs) noexcept(true)
237{
238 using TValue= typename std::underlying_type<TEnum>::type;
239 return TEnum( TValue(lhs) + TValue(rhs) );
240}
241
242/**
243 * Add operator between an enum element and an integral value of underlying type.
244 *
245 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
246 * template enum type \p{TEnum} to inherit \c std::true_type.
247 *
248 * @tparam TEnum Enumeration type.
249 * @param lhs First operand.
250 * @param rhs Second operand.
251 * @return The resulting enum element.
252 */
253template<typename TEnum>
254constexpr
255#if defined(ALIB_DOX)
256TEnum
257#else
259#endif
260operator+ (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
261{
262 using TValue= typename std::underlying_type<TEnum>::type;
263 return TEnum( TValue(lhs) + rhs );
264}
265
266
267/**
268 * Add assignment operator between two enum elements.
269 *
270 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
271 * template enum type \p{TEnum} to inherit \c std::true_type.
272 *
273 * @tparam TEnum Enumeration type.
274 * @param lhs First operand.
275 * @param rhs Second operand.
276 * @return The new value of \p{lhs} which is set the resulting enum element.
277 */
278template<typename TEnum>
279constexpr
280#if defined(ALIB_DOX)
281TEnum
282#else
284#endif
285operator+= (TEnum& lhs, TEnum rhs) noexcept(true)
286{
287 using TValue= typename std::underlying_type<TEnum>::type;
288 return lhs= TEnum( TValue(lhs) + TValue(rhs) );
289}
290
291/**
292 * Add assignment operator between an enum element and an integral value of underlying type.
293 *
294 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
295 * template enum type \p{TEnum} to inherit \c std::true_type.
296 *
297 * @param[in,out] lhs Reference to the first operand. Receives the result.
298 * @tparam TEnum Enumeration type.
299 * @param rhs Second operand.
300 * @return The new value of \p{lhs} which is set the resulting enum element.
301 */
302template<typename TEnum>
303constexpr
304#if defined(ALIB_DOX)
305TEnum
306#else
308#endif
309operator+= (TEnum& lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
310{
311 using TValue= typename std::underlying_type<TEnum>::type;
312 return lhs= TEnum( TValue(lhs) + rhs );
313}
314
315/**
316 * Prefix increment operator.
317 *
318 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
319 * template enum type \p{TEnum} to inherit \c std::true_type.
320 *
321 * @tparam TEnum Enumeration type.
322 * @param[in,out] arg Reference to the enum value to be incremented.
323 * @return The new value of \p{lhs} which is set the resulting enum element.
324 */
325template<typename TEnum>
326constexpr
327#if defined(ALIB_DOX)
328TEnum
329#else
331#endif
332operator++ (TEnum& arg) noexcept(true)
333{
334 using TValue= typename std::underlying_type<TEnum>::type;
335 return arg= TEnum( TValue(arg) + 1 );
336}
337
338/**
339 * Postfix increment operator.
340 *
341 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
342 * template enum type \p{TEnum} to inherit \c std::true_type.
343 *
344 * @tparam TEnum Enumeration type.
345 * @param[in,out] arg Reference to the enum value to be incremented.
346 * @return The old value of \p{arg}.
347 */
348template<typename TEnum>
349constexpr
350#if defined(ALIB_DOX)
351TEnum
352#else
354#endif
355operator++ (TEnum& arg, int) noexcept(true)
356{
357 using TValue= typename std::underlying_type<TEnum>::type;
358 TEnum tmp= arg;
359 arg= TEnum( TValue(arg) + 1 );
360 return tmp;
361}
362
363/**
364 * Subtract operator between two enum elements.
365 *
366 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
367 * template enum type \p{TEnum} to inherit \c std::true_type.
368 *
369 * @tparam TEnum Enumeration type.
370 * @param lhs First operand.
371 * @param rhs Second operand.
372 * @return The resulting enum element.
373 */
374template<typename TEnum>
375constexpr
376#if defined(ALIB_DOX)
377TEnum
378#else
380#endif
381operator- (TEnum lhs, TEnum rhs) noexcept(true)
382{
383 using TValue= typename std::underlying_type<TEnum>::type;
384 return TEnum( TValue(lhs) - TValue(rhs) );
385}
386
387
388/**
389 * Subtract operator between an enum element and an integral value of underlying type.
390 *
391 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
392 * template enum type \p{TEnum} to inherit \c std::true_type.
393 *
394 * @tparam TEnum Enumeration type.
395 * @param lhs First operand.
396 * @param rhs Second operand.
397 * @return The resulting enum element.
398 */
399template<typename TEnum>
400constexpr
401#if defined(ALIB_DOX)
402TEnum
403#else
405#endif
406operator- (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
407{
408 using TValue= typename std::underlying_type<TEnum>::type;
409 return TEnum( TValue(lhs) - rhs );
410}
411
412/**
413 * Subtract assignment operator between two enum elements.
414 *
415 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
416 * template enum type \p{TEnum} to inherit \c std::true_type.
417 *
418 * @tparam TEnum Enumeration type.
419 * @param lhs First operand.
420 * @param rhs Second operand.
421 * @return The new value of \p{lhs} which is set the resulting enum element.
422 */
423template<typename TEnum>
424constexpr
425#if defined(ALIB_DOX)
426TEnum
427#else
429#endif
430operator-= (TEnum& lhs, TEnum rhs) noexcept(true)
431{
432 using TValue= typename std::underlying_type<TEnum>::type;
433 return lhs= TEnum( TValue(lhs) - TValue(rhs) );
434}
435
436/**
437 * Subtract assignment operator between an enum element and an integral value of underlying type.
438 *
439 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
440 * template enum type \p{TEnum} to inherit \c std::true_type.
441 *
442 * @tparam TEnum Enumeration type.
443 * @param[in,out] lhs Reference to the first operand. Receives the result.
444 * @param rhs Second operand.
445 * @return The new value of \p{lhs} which is set the resulting enum element.
446 */
447template<typename TEnum>
448constexpr
449#if defined(ALIB_DOX)
450TEnum
451#else
453#endif
454operator-= (TEnum& lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
455{
456 using TValue= typename std::underlying_type<TEnum>::type;
457 return lhs= TEnum( TValue(lhs) - rhs );
458}
459
460/**
461 * Prefix decrement operator.
462 *
463 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
464 * template enum type \p{TEnum} to inherit \c std::true_type.
465 *
466 * @tparam TEnum Enumeration type.
467 * @param[in,out] arg Reference to the enum value to be decremented.
468 * @return The new value of \p{lhs} which is set the resulting enum element.
469 */
470template<typename TEnum>
471constexpr
472#if defined(ALIB_DOX)
473TEnum
474#else
476#endif
477operator-- (TEnum& arg) noexcept(true)
478{
479 using TValue= typename std::underlying_type<TEnum>::type;
480 return arg= TEnum( TValue(arg) - 1 );
481}
482
483
484/**
485 * Postfix decrement operator.
486 *
487 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
488 * template enum type \p{TEnum} to inherit \c std::true_type.
489 *
490 * @tparam TEnum Enumeration type.
491 * @param[in,out] arg Reference to the enum value to be decremented.
492 * @return The old value of \p{arg}.
493 */
494template<typename TEnum>
495constexpr
496#if defined(ALIB_DOX)
497TEnum
498#else
500#endif
501operator-- (TEnum& arg, int) noexcept(true)
502{
503 using TValue= typename std::underlying_type<TEnum>::type;
504 TEnum tmp= arg;
505 arg= TEnum( TValue(arg) - 1 );
506 return tmp;
507}
508
509/**
510 * Unary plus operator for enum elements.
511 *
512 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
513 * template enum type \p{TEnum} to inherit \c std::true_type.
514 *
515 * @tparam TEnum Enumeration type.
516 * @param arg Operand.
517 * @return Parameter \p{arg} (identical value).
518 */
519template<typename TEnum>
520constexpr
521#if defined(ALIB_DOX)
522TEnum
523#else
525#endif
526operator+ (TEnum arg) noexcept(true)
527{
528 return arg;
529}
530
531/**
532 * Unary minus operator for enum elements.
533 *
534 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
535 * template enum type \p{TEnum} to inherit \c std::true_type.
536 *
537 * @tparam TEnum Enumeration type.
538 * @param arg Operand.
539 * @return The resulting enum element.
540 */
541template<typename TEnum>
542constexpr
543#if defined(ALIB_DOX)
544TEnum
545#else
547#endif
548operator- (TEnum arg) noexcept(true)
549{
550 using TValue= typename std::underlying_type<TEnum>::type;
551 return TEnum( - TValue(arg) );
552}
553
554
555/**
556 * Multiplication operator between an enum element and an integral value of underlying type.
557 *
558 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
559 * template enum type \p{TEnum} to inherit \c std::true_type.
560 *
561 * @tparam TEnum Enumeration type.
562 * @param lhs First operand.
563 * @param rhs Second operand.
564 * @return The resulting enum element.
565 */
566template<typename TEnum>
567constexpr
568#if defined(ALIB_DOX)
569TEnum
570#else
572#endif
573operator* (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
574{
575 using TValue= typename std::underlying_type<TEnum>::type;
576 return TEnum( TValue(lhs) * rhs );
577}
578
579/**
580 * Multiplication assignment operator between an enum element and an integral value of underlying
581 * type.
582 *
583 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
584 * template enum type \p{TEnum} to inherit \c std::true_type.
585 *
586 * @tparam TEnum Enumeration type.
587 * @param[in,out] lhs Reference to the first operand. Receives the result.
588 * @param rhs Second operand.
589 * @return The resulting enum element.
590 */
591template<typename TEnum>
592constexpr
593#if defined(ALIB_DOX)
594TEnum
595#else
597#endif
598operator*= (TEnum& lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
599{
600 using TValue= typename std::underlying_type<TEnum>::type;
601 return lhs= TEnum( TValue(lhs) * rhs );
602}
603
604/**
605 * Division operator between an enum element and an integral value of underlying type.
606 *
607 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
608 * template enum type \p{TEnum} to inherit \c std::true_type.
609 *
610 * @tparam TEnum Enumeration type.
611 * @param lhs First operand.
612 * @param rhs Second operand.
613 * @return The resulting enum element.
614 */
615template<typename TEnum>
616constexpr
617#if defined(ALIB_DOX)
618TEnum
619#else
621#endif
622operator/ (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
623{
624 using TValue= typename std::underlying_type<TEnum>::type;
625 return TEnum( TValue(lhs) / rhs );
626}
627
628/**
629 * Division assignment operator between an enum element and an integral value of underlying
630 * type.
631 *
632 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
633 * template enum type \p{TEnum} to inherit \c std::true_type.
634 *
635 * @tparam TEnum Enumeration type.
636 * @param[in,out] lhs Reference to the first operand. Receives the result.
637 * @param rhs Second operand.
638 * @return The resulting enum element.
639 */
640template<typename TEnum>
641constexpr
642#if defined(ALIB_DOX)
643TEnum
644#else
646#endif
647operator/= (TEnum& lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
648{
649 using TValue= typename std::underlying_type<TEnum>::type;
650 return lhs= TEnum( TValue(lhs) / rhs );
651}
652
653
654/**
655 * Modulo operator between an enum element and an integral value of underlying type.
656 *
657 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
658 * template enum type \p{TEnum} to inherit \c std::true_type.
659 *
660 * @tparam TEnum Enumeration type.
661 * @param lhs First operand.
662 * @param rhs Second operand.
663 * @return The resulting enum element.
664 */
665template<typename TEnum>
666constexpr
667#if defined(ALIB_DOX)
668TEnum
669#else
671#endif
672operator% (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
673{
674 using TValue= typename std::underlying_type<TEnum>::type;
675 return TEnum( TValue(lhs) % rhs );
676}
677
678/**
679 * Modulo assignment operator between an enum element and an integral value of underlying
680 * type.
681 *
682 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
683 * template enum type \p{TEnum} to inherit \c std::true_type.
684 *
685 * @tparam TEnum Enumeration type.
686 * @param[in,out] lhs Reference to the first operand. Receives the result.
687 * @param rhs Second operand.
688 * @return The resulting enum element.
689 */
690template<typename TEnum>
691constexpr
692#if defined(ALIB_DOX)
693TEnum
694#else
696#endif
697operator%= (TEnum& lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
698{
699 using TValue= typename std::underlying_type<TEnum>::type;
700 return lhs= TEnum( TValue(lhs) % rhs );
701}
702
703
704/**
705 * Shift-left operator between an enum element and an integral value of underlying type.
706 *
707 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
708 * template enum type \p{TEnum} to inherit \c std::true_type.
709 *
710 * @tparam TEnum Enumeration type.
711 * @param lhs First operand.
712 * @param rhs Second operand.
713 * @return The resulting enum element.
714 */
715template<typename TEnum>
716constexpr
717#if defined(ALIB_DOX)
718TEnum
719#else
721#endif
722operator<< (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
723{
724 using TValue= typename std::underlying_type<TEnum>::type;
725 return TEnum( TValue(lhs) << rhs );
726}
727
728/**
729 * Shift-left assignment operator between an enum element and an integral value of underlying type.
730 *
731 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
732 * template enum type \p{TEnum} to inherit \c std::true_type.
733 *
734 * @tparam TEnum Enumeration type.
735 * @param[in,out] lhs Reference to the first operand. Receives the result.
736 * @param rhs Second operand.
737 * @return The resulting enum element.
738 */
739template<typename TEnum>
740constexpr
741#if defined(ALIB_DOX)
742TEnum
743#else
745#endif
746operator<<= (TEnum& lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
747{
748 using TValue= typename std::underlying_type<TEnum>::type;
749 return lhs= TEnum( TValue(lhs) << rhs );
750}
751
752
753/**
754 * Shift-right operator between an enum element and an integral value of underlying type.
755 *
756 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
757 * template enum type \p{TEnum} to inherit \c std::true_type.
758 *
759 * @tparam TEnum Enumeration type.
760 * @param lhs First operand.
761 * @param rhs Second operand.
762 * @return The resulting enum element.
763 */
764template<typename TEnum>
765constexpr
766#if defined(ALIB_DOX)
767TEnum
768#else
770#endif
771operator>> (TEnum lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
772{
773 using TValue= typename std::underlying_type<TEnum>::type;
774 return TEnum( TValue(lhs) << rhs );
775}
776
777/**
778 * Shift-right assignment operator between an enum element and an integral value of underlying type.
779 *
780 * Selected by the compiler only if \alib{enums;T_EnumIsArithmetical} is specialized for
781 * template enum type \p{TEnum} to inherit \c std::true_type.
782 *
783 * @tparam TEnum Enumeration type.
784 * @param[in,out] lhs Reference to the first operand. Receives the result.
785 * @param rhs Second operand.
786 * @return The resulting enum element.
787 */
788template<typename TEnum>
789constexpr
790#if defined(ALIB_DOX)
791TEnum
792#else
794#endif
795operator>>= (TEnum& lhs, typename std::underlying_type<TEnum>::type rhs) noexcept(true)
796{
797 using TValue= typename std::underlying_type<TEnum>::type;
798 return lhs= TEnum( TValue(lhs) >> rhs );
799}
800
801
802// Reset documentation fake
803#if defined(ALIB_DOX)
804}}}} // doxygen namespace [alib::enums::arithmetical]
805#endif
806
807
808#endif // HPP_ALIB_ENUMS_ARITHMETICAL
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ATMP_VOID_IF(Cond)
Definition tmp.hpp:52
#define ATMP_T_IF(T, Cond)
Definition tmp.hpp:53
constexpr bool operator<=(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator<<=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator-=(TEnum &lhs, TEnum rhs) noexcept(true)
constexpr bool operator>(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator*(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator<<(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator/(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator*=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator>>=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr bool operator<(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator++(TEnum &arg) noexcept(true)
constexpr TEnum operator--(TEnum &arg) noexcept(true)
constexpr TEnum operator%=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator/=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator+(TEnum lhs, TEnum rhs) noexcept(true)
constexpr TEnum operator>>(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr bool operator>=(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator-(TEnum lhs, TEnum rhs) noexcept(true)
constexpr TEnum operator%(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept(true)
constexpr TEnum operator+=(TEnum &lhs, TEnum rhs) noexcept(true)
Definition alib.cpp:57