mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
enum_ops.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <type_traits>
5
6
7namespace m {
8
9
10template<typename T>
11requires std::is_enum_v<T> and
12 requires (std::underlying_type_t<T> x) {
13 { x | x } -> std::same_as<std::underlying_type_t<T>>;
14 T(x);
15 }
16constexpr T operator|(T left, T right)
17{
18 using U = std::underlying_type_t<T>;
19 return T( U(left) | U(right) );
20}
21
22template<typename T>
23requires std::is_enum_v<T> and
24 requires (std::underlying_type_t<T> x) {
25 { x | x } -> std::same_as<std::underlying_type_t<T>>;
26 T(x);
27 }
28constexpr T operator&(T left, T right)
29{
30 using U = std::underlying_type_t<T>;
31 return T( U(left) & U(right) );
32}
33
34template<typename T>
35requires std::is_enum_v<T> and
36 requires (std::underlying_type_t<T> x) {
37 { ~x } -> std::same_as<std::underlying_type_t<T>>;
38 { x & x } -> std::same_as<std::underlying_type_t<T>>;
39 T(x);
40 }
41constexpr T operator-(T left, T right)
42{
43 using U = std::underlying_type_t<T>;
44 return T( U(left) & ~U(right) );
45}
46
47template<typename T>
48requires std::is_enum_v<T> and
49 requires (std::underlying_type_t<T> x) {
50 { ~x } -> std::same_as<std::underlying_type_t<T>>;
51 T(x);
52 }
53constexpr T operator~(T t)
54{
55 using U = std::underlying_type_t<T>;
56 return T( ~U(t) );
57}
58
59template<typename T>
60requires std::is_enum_v<T> and requires (T x) { { x | x } -> std::same_as<T>; }
61constexpr T & operator|=(T &left, T right)
62{
63 return left = left | right;
64}
65
66template<typename T>
67requires std::is_enum_v<T> and requires (T x) { { x & x } -> std::same_as<T>; }
68constexpr T & operator&=(T &left, T right)
69{
70 return left = left & right;
71}
72
73template<typename T>
74requires std::is_enum_v<T> and requires (T x) { { x - x } -> std::same_as<T>; }
75constexpr T & operator-=(T &left, T right)
76{
77 return left = left - right;
78}
79
80}
‍mutable namespace
Definition: Backend.hpp:10
constexpr T & operator|=(T &left, T right)
Definition: enum_ops.hpp:61
Schema operator&(const Schema &left, const Schema &right)
Computes the set intersection of two Schemas.
Definition: Schema.hpp:258
T(x)
constexpr T & operator-=(T &left, T right)
Definition: enum_ops.hpp:75
Schema operator|(const Schema &left, const Schema &right)
Definition: Schema.hpp:272
and
Definition: enum_ops.hpp:12
constexpr T & operator&=(T &left, T right)
Definition: enum_ops.hpp:68
constexpr T operator~(T t)
Definition: enum_ops.hpp:53
constexpr T operator-(T left, T right)
Definition: enum_ops.hpp:41
and arithmetic< U > and same_signedness< T, U > U
Definition: concepts.hpp:90