Добавлены операторы
This commit is contained in:
parent
d96ee1ee57
commit
395ffb080a
@ -16,14 +16,49 @@ struct EnableBitMaskOperators
|
|||||||
};
|
};
|
||||||
|
|
||||||
template< typename Enum >
|
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 )
|
operator |( Enum lhs, Enum rhs )
|
||||||
{
|
{
|
||||||
using Underlying = typename std::underlying_type< Enum >::type;
|
using Underlying = typename std::underlying_type< Enum >::type;
|
||||||
return( static_cast< Enum >(
|
return( static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) ) );
|
||||||
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
|
} // namespace base
|
||||||
|
Loading…
Reference in New Issue
Block a user