LIDL Soundboard  1.9.0
A simple soundboard, yet better than EXP Soundboard forsenE
bitmask_operators.h
Go to the documentation of this file.
1 #ifndef JSS_BITMASK_HPP
2 #define JSS_BITMASK_HPP
3 
4 // (C) Copyright 2015 Just Software Solutions Ltd
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 //
8 // Boost Software License - Version 1.0 - August 17th, 2003
9 //
10 // Permission is hereby granted, free of charge, to any person or
11 // organization obtaining a copy of the software and accompanying
12 // documentation covered by this license (the "Software") to use,
13 // reproduce, display, distribute, execute, and transmit the
14 // Software, and to prepare derivative works of the Software, and
15 // to permit third-parties to whom the Software is furnished to
16 // do so, all subject to the following:
17 //
18 // The copyright notices in the Software and this entire
19 // statement, including the above license grant, this restriction
20 // and the following disclaimer, must be included in all copies
21 // of the Software, in whole or in part, and all derivative works
22 // of the Software, unless such copies or derivative works are
23 // solely in the form of machine-executable object code generated
24 // by a source language processor.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
27 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
28 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
29 // PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
30 // COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE
31 // LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
32 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 // THE SOFTWARE.
35 
36 #include<type_traits>
37 
38 template<typename E>
40  static const bool enable=false;
41 };
42 
43 template<typename E>
44 typename std::enable_if<enable_bitmask_operators<E>::enable,E>::type
45 operator|(E lhs,E rhs){
46  typedef typename std::underlying_type<E>::type underlying;
47  return static_cast<E>(
48  static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
49 }
50 
51 template<typename E>
52 typename std::enable_if<enable_bitmask_operators<E>::enable,E>::type
53 operator&(E lhs,E rhs){
54  typedef typename std::underlying_type<E>::type underlying;
55  return static_cast<E>(
56  static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
57 }
58 
59 template<typename E>
60 typename std::enable_if<enable_bitmask_operators<E>::enable,E>::type
61 operator^(E lhs,E rhs){
62  typedef typename std::underlying_type<E>::type underlying;
63  return static_cast<E>(
64  static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
65 }
66 
67 template<typename E>
68 typename std::enable_if<enable_bitmask_operators<E>::enable,E>::type
69 operator~(E lhs){
70  typedef typename std::underlying_type<E>::type underlying;
71  return static_cast<E>(
72  ~static_cast<underlying>(lhs));
73 }
74 
75 template<typename E>
76 typename std::enable_if<enable_bitmask_operators<E>::enable,E&>::type
77 operator|=(E& lhs,E rhs){
78  typedef typename std::underlying_type<E>::type underlying;
79  lhs=static_cast<E>(
80  static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
81  return lhs;
82 }
83 
84 template<typename E>
85 typename std::enable_if<enable_bitmask_operators<E>::enable,E&>::type
86 operator&=(E& lhs,E rhs){
87  typedef typename std::underlying_type<E>::type underlying;
88  lhs=static_cast<E>(
89  static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
90  return lhs;
91 }
92 
93 template<typename E>
94 typename std::enable_if<enable_bitmask_operators<E>::enable,E&>::type
95 operator^=(E& lhs,E rhs){
96  typedef typename std::underlying_type<E>::type underlying;
97  lhs=static_cast<E>(
98  static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
99  return lhs;
100 }
101 
102 #endif
std::enable_if< enable_bitmask_operators< E >::enable, E >::type operator &(E lhs, E rhs)
Definition: bitmask_operators.h:53
std::enable_if< enable_bitmask_operators< E >::enable, E >::type operator~(E lhs)
Definition: bitmask_operators.h:69
static const bool enable
Definition: bitmask_operators.h:40
Definition: bitmask_operators.h:39
std::enable_if< enable_bitmask_operators< E >::enable, E >::type operator|(E lhs, E rhs)
Definition: bitmask_operators.h:45
std::enable_if< enable_bitmask_operators< E >::enable, E & >::type operator^=(E &lhs, E rhs)
Definition: bitmask_operators.h:95
std::enable_if< enable_bitmask_operators< E >::enable, E & >::type operator&=(E &lhs, E rhs)
Definition: bitmask_operators.h:86
std::enable_if< enable_bitmask_operators< E >::enable, E >::type operator^(E lhs, E rhs)
Definition: bitmask_operators.h:61
std::enable_if< enable_bitmask_operators< E >::enable, E & >::type operator|=(E &lhs, E rhs)
Definition: bitmask_operators.h:77