DebugServer2
Loading...
Searching...
No Matches
Enums.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include <type_traits>
14
15template <typename Enum> struct EnableBitMaskOperators {
16 static const bool enable = false;
17};
18
19template <typename Enum>
20typename std::enable_if<EnableBitMaskOperators<Enum>::enable,
21 Enum>::type constexpr
22operator|(Enum lhs, Enum rhs) {
23 using Underlying = typename std::underlying_type<Enum>::type;
24 return static_cast<Enum>(static_cast<Underlying>(lhs) |
25 static_cast<Underlying>(rhs));
26}
27
28template <typename Enum>
29typename std::enable_if<EnableBitMaskOperators<Enum>::enable,
30 Enum>::type constexpr
31operator&(Enum lhs, Enum rhs) {
32 using Underlying = typename std::underlying_type<Enum>::type;
33 return static_cast<Enum>(static_cast<Underlying>(lhs) &
34 static_cast<Underlying>(rhs));
35}
36
37template <typename Enum>
38typename std::enable_if<EnableBitMaskOperators<Enum>::enable,
39 Enum>::type constexpr
40operator~(Enum e) {
41 using Underlying = typename std::underlying_type<Enum>::type;
42 return static_cast<Enum>(~static_cast<Underlying>(e));
43}
44
45template <typename Enum>
46typename std::enable_if<EnableBitMaskOperators<Enum>::enable,
47 Enum>::type constexpr
48operator!(Enum e) {
49 using Underlying = typename std::underlying_type<Enum>::type;
50 return static_cast<Enum>(!static_cast<Underlying>(e));
51}
52
53#define ENABLE_BITMASK_OPERATORS(x) \
54 template <> struct EnableBitMaskOperators<x> { \
55 static const bool enable = true; \
56 }
Definition Enums.h:15