]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_translocate/lib/SecTranslocateEnumUtils.hpp
Security-59754.41.1.tar.gz
[apple/security.git] / OSX / libsecurity_translocate / lib / SecTranslocateEnumUtils.hpp
1 //
2 // SecTranslocateEnumUtils.h
3 // Security
4 //
5 //
6
7 #ifndef SecTranslocateEnumUtils_h
8 #define SecTranslocateEnumUtils_h
9
10 #include <type_traits>
11
12 template<typename Enum>
13 Enum operator |(Enum lhs, Enum rhs)
14 {
15 static_assert(std::is_enum<Enum>::value,
16 "template parameter is not an enum type");
17
18 using underlying = typename std::underlying_type<Enum>::type;
19
20 return static_cast<Enum> (
21 static_cast<underlying>(lhs) |
22 static_cast<underlying>(rhs)
23 );
24 }
25
26 template<typename Enum>
27 Enum operator &(Enum lhs, Enum rhs)
28 {
29 static_assert(std::is_enum<Enum>::value,
30 "template parameter is not an enum type");
31
32 using underlying = typename std::underlying_type<Enum>::type;
33
34 return static_cast<Enum> (
35 static_cast<underlying>(lhs) &
36 static_cast<underlying>(rhs)
37 );
38 }
39
40 #endif /* SecTranslocateEnumUtils_h */