SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
add_enum_bitwise_operators.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <type_traits>
13
15
16namespace seqan3
17{
76
88template <typename t>
89inline constexpr bool add_enum_bitwise_operators = false;
90
101template <typename t>
102constexpr t operator&(t lhs, t rhs) noexcept
103 requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
104{
105 return static_cast<t>(static_cast<std::underlying_type_t<t>>(lhs) & static_cast<std::underlying_type_t<t>>(rhs));
106}
107
108template <typename t>
109constexpr t operator|(t lhs, t rhs) noexcept
110 requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
111{
112 return static_cast<t>(static_cast<std::underlying_type_t<t>>(lhs) | static_cast<std::underlying_type_t<t>>(rhs));
113}
114
115template <typename t>
116constexpr t operator^(t lhs, t rhs) noexcept
117 requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
118{
119 return static_cast<t>(static_cast<std::underlying_type_t<t>>(lhs) ^ static_cast<std::underlying_type_t<t>>(rhs));
120}
121
122template <typename t>
123constexpr t operator~(t lhs) noexcept
124 requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
125{
126 return static_cast<t>(~static_cast<std::underlying_type_t<t>>(lhs));
127}
128
129template <typename t>
130constexpr t & operator&=(t & lhs, t rhs) noexcept
131 requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
132{
133 lhs = lhs & rhs;
134 return lhs;
135}
136
137template <typename t>
138constexpr t & operator|=(t & lhs, t rhs) noexcept
139 requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
140{
141 lhs = lhs | rhs;
142 return lhs;
143}
144
145template <typename t>
146constexpr t & operator^=(t & lhs, t rhs) noexcept
147 requires std::is_enum_v<t> && add_enum_bitwise_operators<t>
148{
149 lhs = lhs ^ rhs;
150 return lhs;
151}
154
155} // namespace seqan3
auto operator|(validator1_type &&vali1, validator2_type &&vali2)
Enables the chaining of validators.
Definition validators.hpp:1117
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides platform and dependency checks.
Hide me