From 395ffb080a5a917d45ee9ea403267efdad4b918e Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Mon, 25 May 2020 17:24:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/base/enum_bitmask_operations.hpp | 45 +++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/myx/base/enum_bitmask_operations.hpp b/src/myx/base/enum_bitmask_operations.hpp index 573bac1..e7cf829 100644 --- a/src/myx/base/enum_bitmask_operations.hpp +++ b/src/myx/base/enum_bitmask_operations.hpp @@ -16,14 +16,49 @@ struct EnableBitMaskOperators }; template< typename Enum > -typename std::enable_if< EnableBitMaskOperators< Enum >::k_Enable, Enum >::type +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type +operator ~( Enum e ) +{ + using Underlying = typename std::underlying_type< Enum >::type; + return( static_cast< Enum >( ~static_cast< Underlying >( e ) ) ); +} + + +template< typename Enum > +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type operator |( Enum lhs, Enum rhs ) { using Underlying = typename std::underlying_type< Enum >::type; - return( static_cast< Enum >( - static_cast< Underlying >( lhs ) | - static_cast< Underlying >( rhs ) - ) ); + return( static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) ) ); +} + + +template< typename Enum > +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, typename std::add_lvalue_reference< Enum >::type >::type +operator |=( Enum& lhs, Enum rhs ) +{ + using Underlying = typename std::underlying_type< Enum >::type; + lhs = static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) ); + return( lhs ); +} + + +template< typename Enum > +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type +operator &( Enum lhs, Enum rhs ) +{ + using Underlying = typename std::underlying_type< Enum >::type; + return( static_cast< Enum >( static_cast< Underlying >( lhs ) & static_cast< Underlying >( rhs ) ) ); +} + + +template< typename Enum > +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, typename std::add_lvalue_reference< Enum >::type >::type +operator &=( Enum& lhs, Enum rhs ) +{ + using Underlying = typename std::underlying_type< Enum >::type; + lhs = static_cast< Enum >( static_cast< Underlying >( lhs ) & static_cast< Underlying >( rhs ) ); + return( lhs ); } } // namespace base