28 #ifndef VC_COMMON_MASKENTRY_H_
29 #define VC_COMMON_MASKENTRY_H_
33 namespace Vc_VERSIONED_NAMESPACE
40 template<
size_t Bytes>
struct MaskBoolStorage;
43 template<>
struct MaskBoolStorage<1> {
typedef std::int8_t type; };
44 template<>
struct MaskBoolStorage<2> {
typedef std::int16_t type; };
45 template<>
struct MaskBoolStorage<4> {
typedef std::int32_t type; };
46 template<>
struct MaskBoolStorage<8> {
typedef std::int64_t type; };
49 template<
size_t Bytes>
class MaskBool
51 typedef typename MaskBoolStorage<Bytes>::type storage_type Vc_MAY_ALIAS;
54 constexpr MaskBool(
bool x) noexcept : data(x ? -1 : 0) {}
55 Vc_ALWAYS_INLINE MaskBool &operator=(
bool x) noexcept { data = x ? -1 : 0;
return *
this; }
56 template <
typename T,
typename = enable_if<(!std::is_same<T,
bool>::value &&
57 std::is_fundamental<T>::value)>>
58 Vc_ALWAYS_INLINE MaskBool &operator=(T x) noexcept
60 data =
reinterpret_cast<const storage_type &
>(x);
64 Vc_ALWAYS_INLINE MaskBool(
const MaskBool &) noexcept =
default;
65 Vc_ALWAYS_INLINE MaskBool &operator=(
const MaskBool &) noexcept =
default;
67 template <
typename T,
typename = enable_if<(std::is_same<T,
bool>::value ||
68 (std::is_fundamental<T>::value &&
69 sizeof(storage_type) == sizeof(T)))>>
70 constexpr
operator T() const noexcept
72 return std::is_same<T, bool>::value ? T((data & 1) != 0) : aliasing_cast<T>(data);
78 typename std::enable_if<
79 std::is_convertible<A, bool>::value &&std::is_convertible<B, bool>::value,
83 return static_cast<bool>(a) ==
static_cast<bool>(b);
87 typename std::enable_if<
88 std::is_convertible<A, bool>::value &&std::is_convertible<B, bool>::value,
92 return static_cast<bool>(a) !=
static_cast<bool>(b);
98 #endif // VC_COMMON_MASKENTRY_H_