blob: a5678f33facd731ab366911f4c8b91f785dcc2d7 [file] [log] [blame]
William A. Kennington IIIeac9d472020-08-03 13:57:14 -07001#pragma once
2#include <utility>
3
4namespace stdplus
5{
6
7template <typename Int, typename Flag = Int>
8class BitFlags
9{
10 public:
Patrick Williamsd1984dd2023-05-10 16:12:44 -050011 inline explicit BitFlags(Int val = 0) noexcept : val(val) {}
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070012
13 inline BitFlags& set(Flag flag) & noexcept
14 {
15 val |= static_cast<Int>(flag);
16 return *this;
17 }
18 inline BitFlags&& set(Flag flag) && noexcept
19 {
20 val |= static_cast<Int>(flag);
21 return std::move(*this);
22 }
23
24 inline BitFlags& unset(Flag flag) & noexcept
25 {
26 val &= ~static_cast<Int>(flag);
27 return *this;
28 }
29 inline BitFlags&& unset(Flag flag) && noexcept
30 {
31 val &= ~static_cast<Int>(flag);
32 return std::move(*this);
33 }
34
35 explicit inline operator Int() const noexcept
36 {
37 return val;
38 }
39
40 private:
41 Int val;
42};
43
44} // namespace stdplus