co_usb
Loading...
Searching...
No Matches
flag_type.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
6{
7
14template <typename E, typename Tag> struct flag_type
15{
16 using storage_t = std::underlying_type_t<E>;
18
19 constexpr flag_type() = default;
20 constexpr explicit flag_type (storage_t b) : bits(b)
21 {
22 }
23
24 friend constexpr flag_type operator~(flag_type f) noexcept
25 {
26 return flag_type{static_cast<storage_t>(~f.bits)};
27 }
28
29 friend constexpr flag_type operator&(flag_type a, flag_type b) noexcept
30 {
31 return flag_type{static_cast<storage_t>(a.bits & b.bits)};
32 }
33 friend constexpr flag_type operator|(flag_type a, flag_type b) noexcept
34 {
35 return flag_type{static_cast<storage_t>(a.bits | b.bits)};
36 }
37 friend constexpr flag_type operator^(flag_type a, flag_type b) noexcept
38 {
39 return flag_type{static_cast<storage_t>(a.bits ^ b.bits)};
40 }
41
42 constexpr flag_type &operator&=(flag_type other) noexcept
43 {
44 bits &= other.bits;
45 return *this;
46 }
47 constexpr flag_type &operator|=(flag_type other) noexcept
48 {
49 bits |= other.bits;
50 return *this;
51 }
52 constexpr flag_type &operator^=(flag_type other) noexcept
53 {
54 bits ^= other.bits;
55 return *this;
56 }
57
58 friend constexpr bool operator==(flag_type a, flag_type b) noexcept
59 {
60 return a.bits == b.bits;
61 }
62 friend constexpr bool operator!=(flag_type a, flag_type b) noexcept
63 {
64 return a.bits != b.bits;
65 }
66};
67
68} // namespace co_usb::detail
Definition flag_type.hpp:6
Generic struct for flag types.
Definition flag_type.hpp:15
friend constexpr flag_type operator&(flag_type a, flag_type b) noexcept
Definition flag_type.hpp:29
constexpr flag_type()=default
friend constexpr bool operator!=(flag_type a, flag_type b) noexcept
Definition flag_type.hpp:62
constexpr flag_type(storage_t b)
Definition flag_type.hpp:20
friend constexpr flag_type operator~(flag_type f) noexcept
Definition flag_type.hpp:24
friend constexpr flag_type operator^(flag_type a, flag_type b) noexcept
Definition flag_type.hpp:37
std::underlying_type_t< E > storage_t
Definition flag_type.hpp:16
friend constexpr bool operator==(flag_type a, flag_type b) noexcept
Definition flag_type.hpp:58
constexpr flag_type & operator|=(flag_type other) noexcept
Definition flag_type.hpp:47
storage_t bits
Definition flag_type.hpp:17
constexpr flag_type & operator&=(flag_type other) noexcept
Definition flag_type.hpp:42
friend constexpr flag_type operator|(flag_type a, flag_type b) noexcept
Definition flag_type.hpp:33
constexpr flag_type & operator^=(flag_type other) noexcept
Definition flag_type.hpp:52