SeqAn3 3.1.0
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
18
19namespace seqan3
20{
79
91template <typename t>
92constexpr bool add_enum_bitwise_operators = false;
93
104template <typename t>
105constexpr 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
111template <typename t>
112constexpr 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
118template <typename t>
119constexpr 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
125template <typename t>
126constexpr 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
132template <typename t>
133constexpr 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
140template <typename t>
141constexpr 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
148template <typename t>
149constexpr 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:1120
The main SeqAn3 namespace.
Definition: cigar_operation_table.hpp:2
Provides platform and dependency checks.