Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EnumBitwiseOperators.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EnumBitwiseOperators.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <type_traits>
12 
13 #define ACTS_DEFINE_ENUM_BITWISE_OPERATORS(enum_t) \
14  constexpr auto operator|(enum_t lhs, enum_t rhs) { \
15  return static_cast<enum_t>( \
16  static_cast<std::underlying_type_t<enum_t>>(lhs) | \
17  static_cast<std::underlying_type_t<enum_t>>(rhs)); \
18  } \
19  \
20  constexpr auto operator&(enum_t lhs, enum_t rhs) { \
21  return static_cast<enum_t>( \
22  static_cast<std::underlying_type_t<enum_t>>(lhs) & \
23  static_cast<std::underlying_type_t<enum_t>>(rhs)); \
24  } \
25  \
26  constexpr auto operator^(enum_t lhs, enum_t rhs) { \
27  return static_cast<enum_t>( \
28  static_cast<std::underlying_type_t<enum_t>>(lhs) ^ \
29  static_cast<std::underlying_type_t<enum_t>>(rhs)); \
30  } \
31  \
32  constexpr auto operator~(enum_t op) { \
33  return static_cast<enum_t>( \
34  ~static_cast<std::underlying_type_t<enum_t>>(op)); \
35  } \
36  \
37  constexpr auto& operator|=(enum_t& lhs, enum_t rhs) { \
38  lhs = lhs | rhs; \
39  return lhs; \
40  } \
41  \
42  constexpr auto& operator&=(enum_t& lhs, enum_t rhs) { \
43  lhs = lhs & rhs; \
44  return lhs; \
45  } \
46  \
47  constexpr enum_t& operator^=(enum_t& lhs, enum_t rhs) { \
48  lhs = lhs ^ rhs; \
49  return lhs; \
50  }