/usr/include/wibble/strongenumflags.h is in libwibble-dev 1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | // -*- C++ -*- (c) 2013 Vladimír Štill <xstill@fi.muni.cz>
#if __cplusplus < 201103L
#error "strongenumflag is only supported with c++11 or newer"
#endif
#include <type_traits>
#ifndef WIBBLE_STRONGENUMFLAG_H
#define WIBBLE_STRONGENUMFLAG_H
namespace wibble {
template< typename E >
using is_enum_class = std::integral_constant< bool,
std::is_enum< E >::value && !std::is_convertible< E, int >::value >;
template< typename Self >
struct StrongEnumFlags {
static_assert( is_enum_class< Self >::value, "Not an enum class." );
using This = StrongEnumFlags< Self >;
using UnderlyingType = typename std::underlying_type< Self >::type;
constexpr StrongEnumFlags() noexcept : store( 0 ) { }
constexpr StrongEnumFlags( Self flag ) noexcept :
store( static_cast< UnderlyingType >( flag ) )
{ }
explicit constexpr StrongEnumFlags( UnderlyingType st ) noexcept : store( st ) { }
constexpr explicit operator UnderlyingType() const noexcept {
return store;
}
This &operator|=( This o ) noexcept {
store |= o.store;
return *this;
}
This &operator&=( This o ) noexcept {
store &= o.store;
return *this;
}
friend constexpr This operator|( This a, This b ) noexcept {
return This( a.store | b.store );
}
friend constexpr This operator&( This a, This b ) noexcept {
return This( a.store & b.store );
}
friend constexpr bool operator==( This a, This b ) noexcept {
return a.store == b.store;
}
friend constexpr bool operator!=( This a, This b ) noexcept {
return a.store != b.store;
}
constexpr bool has( Self x ) const noexcept {
return (*this) & x;
}
constexpr operator bool() const noexcept {
return store;
}
private:
UnderlyingType store;
};
// don't catch integral types and classical enum!
template< typename Self, typename = typename
std::enable_if< is_enum_class< Self >::value >::type >
constexpr StrongEnumFlags< Self > operator|( Self a, Self b ) noexcept {
using Ret = StrongEnumFlags< Self >;
return Ret( a ) | Ret( b );
}
template< typename Self, typename = typename
std::enable_if< is_enum_class< Self >::value >::type >
constexpr StrongEnumFlags< Self > operator&( Self a, Self b ) noexcept {
using Ret = StrongEnumFlags< Self >;
return Ret( a ) & Ret( b );
}
}
#endif // WIBBLE_STRONGENUMFLAG_H
|