SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
add_enum_bitwise_operators.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <type_traits>
16 
17 #include <seqan3/core/platform.hpp>
18 
19 namespace seqan3
20 {
79 
91 template <typename t>
92 constexpr bool add_enum_bitwise_operators = false;
93 
104 template <typename t>
105 constexpr t operator& (t lhs, t rhs) noexcept
106  requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
107 {
108  return static_cast<t>(static_cast<std::underlying_type_t<t>>(lhs) & static_cast<std::underlying_type_t<t>>(rhs));
109 }
110 
111 template <typename t>
112 constexpr t operator| (t lhs, t rhs) noexcept
113  requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
114 {
115  return static_cast<t>(static_cast<std::underlying_type_t<t>>(lhs) | static_cast<std::underlying_type_t<t>>(rhs));
116 }
117 
118 template <typename t>
119 constexpr t operator^ (t lhs, t rhs) noexcept
120  requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
121 {
122  return static_cast<t>(static_cast<std::underlying_type_t<t>>(lhs) ^ static_cast<std::underlying_type_t<t>>(rhs));
123 }
124 
125 template <typename t>
126 constexpr t operator~ (t lhs) noexcept
127  requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
128 {
129  return static_cast<t>(~static_cast<std::underlying_type_t<t>>(lhs));
130 }
131 
132 template <typename t>
133 constexpr t & operator&= (t & lhs, t rhs) noexcept
134  requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
135 {
136  lhs = lhs & rhs;
137  return lhs;
138 }
139 
140 template <typename t>
141 constexpr t & operator|= (t & lhs, t rhs) noexcept
142  requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
143 {
144  lhs = lhs | rhs;
145  return lhs;
146 }
147 
148 template <typename t>
149 constexpr t & operator^= (t & lhs, t rhs) noexcept
150  requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
151 {
152  lhs = lhs ^ rhs;
153  return lhs;
154 }
157 
158 } // namespace seqan3
auto operator|(validator1_type &&vali1, validator2_type &&vali2)
Enables the chaining of validators.
Definition: validators.hpp:1103
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides platform and dependency checks.