CVB++ 15.0
Loading...
Searching...
No Matches
flag.hpp
1#pragma once
2
3#include "namespace.hpp"
4#include <type_traits>
5
6namespace Cvb
7{
8 CVB_BEGIN_INLINE_NS
9
10 template <typename T>
11 struct enum_flag_type : std::false_type
12 {
13 };
14
15 template <typename T, typename std::enable_if_t<enum_flag_type<T>::value> * = nullptr>
16 inline constexpr T operator|(T lhs, T rhs) noexcept
17 {
18 return static_cast<T>(static_cast<std::underlying_type_t<T>>(lhs) | static_cast<std::underlying_type_t<T>>(rhs));
19 }
20
21 template <typename T, typename std::enable_if_t<enum_flag_type<T>::value> * = nullptr>
22 inline constexpr T &operator|=(T &lhs, T rhs) noexcept
23 {
24 lhs = operator|(lhs, rhs);
25 return lhs;
26 }
27
28 template <typename T, typename std::enable_if_t<enum_flag_type<T>::value> * = nullptr>
29 inline constexpr T operator&(T lhs, T rhs) noexcept
30 {
31 return static_cast<T>(static_cast<std::underlying_type_t<T>>(lhs) & static_cast<std::underlying_type_t<T>>(rhs));
32 }
33
34 template <typename T, typename std::enable_if_t<enum_flag_type<T>::value> * = nullptr>
35 inline constexpr T &operator&=(T &lhs, T rhs) noexcept
36 {
37 lhs = operator&(lhs, rhs);
38 return lhs;
39 }
40
41 template <typename T, typename std::enable_if_t<enum_flag_type<T>::value> * = nullptr>
42 inline constexpr T operator~(T lhs) noexcept
43 {
44 return static_cast<T>(~static_cast<std::underlying_type_t<T>>(lhs));
45 }
46
47 template <typename T, typename std::enable_if_t<enum_flag_type<T>::value> * = nullptr>
48 inline constexpr T operator^(T lhs, T rhs) noexcept
49 {
50 return static_cast<T>(static_cast<std::underlying_type_t<T>>(lhs) ^ static_cast<std::underlying_type_t<T>>(rhs));
51 }
52
53 template <typename T, typename std::enable_if_t<enum_flag_type<T>::value> * = nullptr>
54 inline constexpr T &operator^=(T &lhs, T rhs) noexcept
55 {
56 lhs = operator^(lhs, rhs);
57 return lhs;
58 }
59
60 CVB_END_INLINE_NS
61} // namespace Cvb
62
63using Cvb::operator|;
64using Cvb::operator|=;
65using Cvb::operator&;
66using Cvb::operator&=;
67using Cvb::operator~;
68using Cvb::operator^;
69using Cvb::operator^=;
Root namespace for the Image Manager interface.
Definition version.hpp:11