LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
bitflags.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <type_traits>
12 
13 namespace LC::Util
14 {
15  template<typename T>
16  requires std::is_enum_v<T>
17  class BitFlags
18  {
19  using St_t = std::underlying_type_t<T>;
20  St_t Storage_ = 0;
21  public:
22  BitFlags () = default;
23 
24  explicit (false) BitFlags (T t)
25  : Storage_ { static_cast<St_t> (t) }
26  {
27  }
28 
29  explicit operator bool () const
30  {
31  return Storage_;
32  }
33 
35  {
36  Storage_ &= other.Storage_;
37  return *this;
38  }
39 
41  {
42  Storage_ |= other.Storage_;
43  return *this;
44  }
45 
46  friend BitFlags operator& (BitFlags left, BitFlags right)
47  {
48  left &= right;
49  return left;
50  }
51 
52  friend BitFlags operator| (BitFlags left, BitFlags right)
53  {
54  left |= right;
55  return left;
56  }
57  };
58 }
59 
60 #define DECLARE_BIT_FLAGS(F) \
61  inline LC::Util::BitFlags<F> operator& (F left, F right) \
62  { \
63  return LC::Util::BitFlags<F> { left } & right; \
64  } \
65  inline LC::Util::BitFlags<F> operator| (F left, F right) \
66  { \
67  return LC::Util::BitFlags<F> { left } | right; \
68  }
BitFlags & operator|=(BitFlags other)
Definition: bitflags.h:40
friend BitFlags operator &(BitFlags left, BitFlags right)
Definition: bitflags.h:46
requires(Tup1Size==Tup2Size) const expr auto ZipWith(Tup1 &&tup1
friend BitFlags operator|(BitFlags left, BitFlags right)
Definition: bitflags.h:52
BitFlags & operator &=(BitFlags other)
Definition: bitflags.h:34