OmniSciDB  2e3a973ef4
EnumBitmaskOps.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <type_traits>
20 
41 template <typename T>
43  static const bool enable = false;
44 };
45 
46 template <typename T>
47 typename std::enable_if_t<EnableBitmaskOps<T>::enable, T> operator&(T lhs, T rhs) {
48  using type = typename std::underlying_type_t<T>;
49  return static_cast<T>(static_cast<type>(lhs) & static_cast<type>(rhs));
50 }
51 template <typename T>
52 typename std::enable_if_t<EnableBitmaskOps<T>::enable, T> operator|(T lhs, T rhs) {
53  using type = typename std::underlying_type_t<T>;
54  return static_cast<T>(static_cast<type>(lhs) | static_cast<type>(rhs));
55 }
56 template <typename T>
57 typename std::enable_if_t<EnableBitmaskOps<T>::enable, T> operator~(T t) {
58  return static_cast<T>(~static_cast<std::underlying_type_t<T>>(t));
59 }
60 template <typename T>
61 typename std::enable_if_t<EnableBitmaskOps<T>::enable, T> operator|=(T& lhs, T rhs) {
62  lhs = lhs | rhs;
63  return lhs;
64 }
65 template <typename T>
66 typename std::enable_if_t<EnableBitmaskOps<T>::enable, T> operator&=(T& lhs, T rhs) {
67  lhs = lhs & rhs;
68  return lhs;
69 }
70 
71 #define ENABLE_BITMASK_OPS(x) \
72  template <> \
73  struct EnableBitmaskOps<x> { \
74  static const bool enable = true; \
75  };
std::enable_if_t< EnableBitmaskOps< T >::enable, T > operator~(T t)
std::enable_if_t< EnableBitmaskOps< T >::enable, T > operator &=(T &lhs, T rhs)
std::enable_if_t< EnableBitmaskOps< T >::enable, T > operator|(T lhs, T rhs)
static const bool enable
std::enable_if_t< EnableBitmaskOps< T >::enable, T > operator|=(T &lhs, T rhs)
std::enable_if_t< EnableBitmaskOps< T >::enable, T > operator &(T lhs, T rhs)