tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
byte.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CSTDDEF_BYTE_HPP
4#define TETL_CSTDDEF_BYTE_HPP
5
6#include <etl/_config/all.hpp>
7
9
10namespace etl {
11
21enum struct TETL_MAY_ALIAS byte : unsigned char {
22};
23
25template <etl::integral Int>
26[[nodiscard]] constexpr auto to_integer(etl::byte b) noexcept -> Int
27{
28 return static_cast<Int>(b);
29}
30
32template <etl::integral Int>
33[[nodiscard]] TETL_ALWAYS_INLINE constexpr auto operator<<(etl::byte b, Int shift) noexcept -> etl::byte
34{
35 return etl::byte(static_cast<unsigned int>(b) << shift);
36}
37
39template <etl::integral Int>
40[[nodiscard]] TETL_ALWAYS_INLINE constexpr auto operator>>(etl::byte b, Int shift) noexcept -> etl::byte
41{
42 return etl::byte(static_cast<unsigned int>(b) >> shift);
43}
44
46template <etl::integral Int>
47TETL_ALWAYS_INLINE constexpr auto operator<<=(etl::byte& b, Int shift) noexcept -> etl::byte&
48
49{
50 return b = b << shift;
51}
52
54template <etl::integral Int>
55TETL_ALWAYS_INLINE constexpr auto operator>>=(etl::byte& b, Int shift) noexcept -> etl::byte&
56{
57 return b = b >> shift;
58}
59
61[[nodiscard]] TETL_ALWAYS_INLINE constexpr auto operator|(etl::byte lhs, etl::byte rhs) noexcept -> etl::byte
62{
63 return etl::byte(static_cast<unsigned int>(lhs) | static_cast<unsigned int>(rhs));
64}
65
67[[nodiscard]] TETL_ALWAYS_INLINE constexpr auto operator&(etl::byte lhs, etl::byte rhs) noexcept -> etl::byte
68{
69 return etl::byte(static_cast<unsigned int>(lhs) & static_cast<unsigned int>(rhs));
70}
71
73[[nodiscard]] TETL_ALWAYS_INLINE constexpr auto operator^(etl::byte lhs, etl::byte rhs) noexcept -> etl::byte
74{
75 return etl::byte(static_cast<unsigned int>(lhs) ^ static_cast<unsigned int>(rhs));
76}
77
79[[nodiscard]] TETL_ALWAYS_INLINE constexpr auto operator~(etl::byte b) noexcept -> etl::byte
80{
81 return etl::byte(~static_cast<unsigned int>(b));
82}
83
85TETL_ALWAYS_INLINE constexpr auto operator|=(etl::byte& lhs, etl::byte rhs) noexcept -> etl::byte&
86{
87 return lhs = lhs | rhs;
88}
89
91TETL_ALWAYS_INLINE constexpr auto operator&=(etl::byte& lhs, etl::byte rhs) noexcept -> etl::byte&
92{
93 return lhs = lhs & rhs;
94}
95
97TETL_ALWAYS_INLINE constexpr auto operator^=(etl::byte& lhs, etl::byte rhs) noexcept -> etl::byte&
98{
99 return lhs = lhs ^ rhs;
100}
101
102} // namespace etl
103
104#endif // TETL_CSTDDEF_BYTE_HPP
#define TETL_MAY_ALIAS
Definition attributes.hpp:31
#define TETL_ALWAYS_INLINE
Definition attributes.hpp:11
Definition adjacent_find.hpp:8
constexpr auto to_integer(etl::byte b) noexcept -> Int
Equivalent to: return Int(b);
Definition byte.hpp:26
constexpr auto operator&=(T &x, T y) noexcept -> T const &
Definition is_bitmask_type.hpp:56
TETL_ALWAYS_INLINE constexpr auto operator<<(etl::byte b, Int shift) noexcept -> etl::byte
Equivalent to: return etl::byte(static_cast<unsigned int>(b) << shift);
Definition byte.hpp:33
TETL_ALWAYS_INLINE constexpr auto operator>>(etl::byte b, Int shift) noexcept -> etl::byte
Equivalent to: return etl::byte(static_cast<unsigned int>(b) >> shift);
Definition byte.hpp:40
TETL_ALWAYS_INLINE constexpr auto operator>>=(etl::byte &b, Int shift) noexcept -> etl::byte &
Equivalent to: return b = b >> shift;
Definition byte.hpp:55
constexpr auto operator~(T x) -> T
Definition is_bitmask_type.hpp:43
constexpr auto operator|(T x, T y) -> T
Definition is_bitmask_type.hpp:29
constexpr auto operator^(T x, T y) -> T
Definition is_bitmask_type.hpp:36
constexpr auto operator&(T x, T y) -> T
Definition is_bitmask_type.hpp:22
constexpr auto operator^=(T &x, T y) noexcept -> T const &
Definition is_bitmask_type.hpp:62
enum TETL_MAY_ALIAS byte
etl::byte is a distinct type that implements the concept of byte as specified in the C++ language def...
Definition byte.hpp:21
TETL_ALWAYS_INLINE constexpr auto operator<<=(etl::byte &b, Int shift) noexcept -> etl::byte &
Equivalent to: return b = b << shift;
Definition byte.hpp:47
constexpr auto operator|=(T &x, T y) noexcept -> T const &
Definition is_bitmask_type.hpp:50