SUNphi  1.0
Flags.hpp
Go to the documentation of this file.
1 #ifndef _FLAGS_HPP
2 #define _FLAGS_HPP
3 
4 /// \file Flags.hpp
5 ///
6 /// \brief Defines collectable flags
7 ///
8 /// A flag is an integral value specifying the number of bits
9 
10 #include <ints/IntSeq.hpp>
11 
12 namespace SUNphi
13 {
14  /// Create a mask for a given flag
15  ///
16  /// Shift right by the amount of bits
17  template <auto Flag>
18  [[ maybe_unused ]]
19  constexpr int flagMask=
20  1<<static_cast<int>(Flag);
21 
22  /// Combine flags to form a mask at compile time
23  ///
24  /// Internal implementation to catch error
25  template <auto...Flags> // Flags to be combined
26  [[ maybe_unused ]]
27  constexpr int _combineFlags()
28  {
29  STATIC_ASSERT_ARE_SAME(decltype(Flags)...);
30 
31  return (flagMask<Flags>|...);
32  }
33 
34  /// Combine flags to form a mask at compile time
35  ///
36  /// Gives visibility to internal implementation
37  template <auto...Flags> // Flags to be combined
38  [[ maybe_unused ]]
39  constexpr int combineFlags=
40  _combineFlags<Flags...>();
41 
42  /// Add flags to a mask at compile time
43  template <int InMask, // Incoming mask
44  auto...Flags> // Flags to be added
45  [[ maybe_unused ]]
46  constexpr int addFlags=
47  InMask | combineFlags<Flags...>;
48 
49  /// Remove flags to a mask at compile time
50  template <int InMask, // Incoming mask
51  auto...Flags> // Flags to be removed
52  [[ maybe_unused ]]
53  constexpr int remFlags=
54  InMask & ~combineFlags<Flags...>;
55 
56  /// Get a given flag from a mask
57  template <int Mask,
58  auto Flag>
59  [[ maybe_unused ]]
60  constexpr bool getFlag=
61  Mask & flagMask<Flag>;
62 }
63 
64 #endif
constexpr int addFlags
Add flags to a mask at compile time.
Definition: Flags.hpp:46
constexpr int flagMask
Definition: Flags.hpp:19
constexpr bool getFlag
Get a given flag from a mask.
Definition: Flags.hpp:60
#define STATIC_ASSERT_ARE_SAME(...)
Assert if types are not the same.
Definition: TypeTraits.hpp:168
constexpr int _combineFlags()
Definition: Flags.hpp:27
constexpr int combineFlags
Definition: Flags.hpp:39
constexpr int remFlags
Remove flags to a mask at compile time.
Definition: Flags.hpp:53