tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
is_bitmask_type.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_BIT_IS_BITMASK_TYPE_HPP
5#define TETL_BIT_IS_BITMASK_TYPE_HPP
6
7#include <etl/_type_traits/bool_constant.hpp>
8#include <etl/_type_traits/underlying_type.hpp>
9
10namespace etl {
11template <typename T>
12struct is_bitmask_type : false_type { };
13
14template <typename T>
15inline constexpr auto is_bitmask_type_v = is_bitmask_type<T>::value;
16
17template <typename T>
18concept bitmask_type = is_bitmask_type_v<T>;
19
20template <bitmask_type T>
21[[nodiscard]] constexpr auto operator&(T x, T y) -> T
22{
23 using type = underlying_type_t<T>;
24 return T{static_cast<type>(static_cast<type>(x) & static_cast<type>(y))};
25}
26
27template <bitmask_type T>
28[[nodiscard]] constexpr auto operator|(T x, T y) -> T
29{
30 using type = underlying_type_t<T>;
31 return T{static_cast<type>(static_cast<type>(x) | static_cast<type>(y))};
32}
33
34template <bitmask_type T>
35[[nodiscard]] constexpr auto operator^(T x, T y) -> T
36{
37 using type = underlying_type_t<T>;
38 return T{static_cast<type>(static_cast<type>(x) ^ static_cast<type>(y))};
39}
40
41template <bitmask_type T>
42[[nodiscard]] constexpr auto operator~(T x) -> T
43{
44 using type = underlying_type_t<T>;
45 return T{static_cast<type>(~static_cast<type>(x))};
46}
47
48template <bitmask_type T>
49constexpr auto operator|=(T& x, T y) noexcept -> T const&
50{
51 return x = x | y;
52}
53
54template <bitmask_type T>
55constexpr auto operator&=(T& x, T y) noexcept -> T const&
56{
57 return x = x & y;
58}
59
60template <bitmask_type T>
61constexpr auto operator^=(T& x, T y) noexcept -> T const&
62{
63 return x = x ^ y;
64}
65
66} // namespace etl
67#endif // TETL_BIT_IS_BITMASK_TYPE_HPP
Definition adjacent_find.hpp:9
constexpr auto operator&=(T &x, T y) noexcept -> T const &
Definition is_bitmask_type.hpp:55
constexpr auto operator~(T x) -> T
Definition is_bitmask_type.hpp:42
constexpr auto operator|(T x, T y) -> T
Definition is_bitmask_type.hpp:28
constexpr auto operator^(T x, T y) -> T
Definition is_bitmask_type.hpp:35
constexpr auto operator&(T x, T y) -> T
Definition is_bitmask_type.hpp:21
constexpr auto operator^=(T &x, T y) noexcept -> T const &
Definition is_bitmask_type.hpp:61
constexpr auto is_bitmask_type_v
Definition is_bitmask_type.hpp:15
constexpr auto operator|=(T &x, T y) noexcept -> T const &
Definition is_bitmask_type.hpp:49
Definition is_bitmask_type.hpp:12