8#ifndef HPP_ALIB_ENUMS_ARITHMETICAL
9#define HPP_ALIB_ENUMS_ARITHMETICAL 1
17#include "alib/lang/tmp.hpp"
19namespace alib {
namespace enums {
67template<
typename TEnum,
typename TEnableIf>
70template<
typename TEnum,
71 typename TEnableIf=
ATMP_VOID_IF(std::is_enum<TEnum>::value)>
78template<
typename TEnum>
88#define ALIB_ENUMS_MAKE_ARITHMETICAL(TEnum) \
89namespace alib::enums { \
90template<> struct T_EnumIsArithmetical<TEnum> : public std::true_type {}; } \
100namespace alib {
namespace enums {
108namespace arithmetical {
121template<
typename TEnum>
128operator< (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
130 using TValue=
typename std::underlying_type<TEnum>::type;
131 return TValue(lhs) < rhs ;
144template<
typename TEnum>
151operator<= (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
153 using TValue=
typename std::underlying_type<TEnum>::type;
154 return TValue(lhs) <= rhs;
167template<
typename TEnum>
174operator> (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
176 using TValue=
typename std::underlying_type<TEnum>::type;
177 return TValue(lhs) > rhs;
192template<
typename TEnum>
199operator>= (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
201 using TValue=
typename std::underlying_type<TEnum>::type;
202 return TValue(lhs) >= rhs ;
215template<
typename TEnum>
224 using TValue=
typename std::underlying_type<TEnum>::type;
225 return TEnum( TValue(lhs) + TValue(rhs) );
237template<
typename TEnum>
244operator+ (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
246 using TValue=
typename std::underlying_type<TEnum>::type;
247 return TEnum( TValue(lhs) + rhs );
260template<
typename TEnum>
269 using TValue=
typename std::underlying_type<TEnum>::type;
270 return lhs= TEnum( TValue(lhs) + TValue(rhs) );
282template<
typename TEnum>
289operator+= (TEnum& lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
291 using TValue=
typename std::underlying_type<TEnum>::type;
292 return lhs= TEnum( TValue(lhs) + rhs );
303template<
typename TEnum>
312 using TValue=
typename std::underlying_type<TEnum>::type;
313 return arg= TEnum( TValue(arg) + 1 );
324template<
typename TEnum>
331operator++ (TEnum& arg,
typename std::underlying_type<TEnum>::type)
noexcept
333 using TValue=
typename std::underlying_type<TEnum>::type;
335 arg= TEnum( TValue(arg) + 1 );
348template<
typename TEnum>
357 using TValue=
typename std::underlying_type<TEnum>::type;
358 return TEnum( TValue(lhs) - TValue(rhs) );
371template<
typename TEnum>
378operator- (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
380 using TValue=
typename std::underlying_type<TEnum>::type;
381 return TEnum( TValue(lhs) - rhs );
393template<
typename TEnum>
402 using TValue=
typename std::underlying_type<TEnum>::type;
403 return lhs= TEnum( TValue(lhs) - TValue(rhs) );
415template<
typename TEnum>
422operator-= (TEnum& lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
424 using TValue=
typename std::underlying_type<TEnum>::type;
425 return lhs= TEnum( TValue(lhs) - rhs );
436template<
typename TEnum>
445 using TValue=
typename std::underlying_type<TEnum>::type;
446 return arg= TEnum( TValue(arg) - 1 );
458template<
typename TEnum>
465operator-- (TEnum& arg,
typename std::underlying_type<TEnum>::type)
noexcept
467 using TValue=
typename std::underlying_type<TEnum>::type;
469 arg= TEnum( TValue(arg) - 1 );
481template<
typename TEnum>
501template<
typename TEnum>
510 using TValue=
typename std::underlying_type<TEnum>::type;
511 return TEnum( - TValue(arg) );
524template<
typename TEnum>
531operator* (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
533 using TValue=
typename std::underlying_type<TEnum>::type;
534 return TEnum( TValue(lhs) * rhs );
547template<
typename TEnum>
554operator*= (TEnum& lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
556 using TValue=
typename std::underlying_type<TEnum>::type;
557 return lhs= TEnum( TValue(lhs) * rhs );
569template<
typename TEnum>
576operator/ (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
578 using TValue=
typename std::underlying_type<TEnum>::type;
579 return TEnum( TValue(lhs) / rhs );
592template<
typename TEnum>
599operator/= (TEnum& lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
601 using TValue=
typename std::underlying_type<TEnum>::type;
602 return lhs= TEnum( TValue(lhs) / rhs );
615template<
typename TEnum>
622operator% (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
624 using TValue=
typename std::underlying_type<TEnum>::type;
625 return TEnum( TValue(lhs) % rhs );
638template<
typename TEnum>
645operator%= (TEnum& lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
647 using TValue=
typename std::underlying_type<TEnum>::type;
648 return lhs= TEnum( TValue(lhs) % rhs );
661template<
typename TEnum>
668operator<< (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
670 using TValue=
typename std::underlying_type<TEnum>::type;
671 return TEnum( TValue(lhs) << rhs );
683template<
typename TEnum>
690operator<<= (TEnum& lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
692 using TValue=
typename std::underlying_type<TEnum>::type;
693 return lhs= TEnum( TValue(lhs) << rhs );
706template<
typename TEnum>
713operator>> (TEnum lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
715 using TValue=
typename std::underlying_type<TEnum>::type;
716 return TEnum( TValue(lhs) << rhs );
728template<
typename TEnum>
735operator>>= (TEnum& lhs,
typename std::underlying_type<TEnum>::type rhs)
noexcept
737 using TValue=
typename std::underlying_type<TEnum>::type;
738 return lhs= TEnum( TValue(lhs) >> rhs );
#define ALIB_ASSERT_MODULE(modulename)
#define ATMP_VOID_IF(Cond)
#define ATMP_T_IF(T, Cond)
constexpr TEnum operator<<=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator+(TEnum lhs, TEnum rhs) noexcept
constexpr TEnum operator*=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator>>=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator>>(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator/=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator/(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr bool operator>(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator++(TEnum &arg) noexcept
constexpr bool operator>=(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator%(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator-=(TEnum &lhs, TEnum rhs) noexcept
constexpr TEnum operator<<(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator+=(TEnum &lhs, TEnum rhs) noexcept
constexpr TEnum operator%=(TEnum &lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator-(TEnum lhs, TEnum rhs) noexcept
constexpr TEnum operator*(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr bool operator<(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr bool operator<=(TEnum lhs, typename std::underlying_type< TEnum >::type rhs) noexcept
constexpr TEnum operator--(TEnum &arg) noexcept