std::byte is a distinct type that implements the concept of byte as specified in the C++ language definition. Shift operations all require unsigned integer types, instead of any integer type.
More...
#include <byte.hpp>
|
| byte () noexcept=default |
| Default constructor. This ensures the byte type is a POD type, allowing it to be constructed as a global resource. This is needed as aligned storage uses a bsl::byte as its base type, and aligned storage is needed as a global resource to support the bsl::manager. More...
|
|
constexpr | byte (value_type const val) noexcept |
| Creates a bsl::byte from a value_type. More...
|
|
template<typename T = value_type, enable_if_t< is_integral< T >::value, bool > = true> |
constexpr T | to_integer () const noexcept |
| Returns the bsl::byte as a given integer type using a static_cast to perform the conversion. More...
|
|
| ~byte () noexcept=default |
| Destroyes a previously created bsl::byte.
|
|
constexpr | byte (byte const &o) noexcept=default |
| copy constructor More...
|
|
constexpr | byte (byte &&o) noexcept=default |
| move constructor More...
|
|
constexpr byte & | operator= (byte const &o) &noexcept=default |
| copy assignment More...
|
|
constexpr byte & | operator= (byte &&o) &noexcept=default |
| move assignment More...
|
|
template<typename O > |
| byte (O val) noexcept=delete |
| This constructor allows for single argument constructors without the need to mark them as explicit as it will absorb any incoming potential implicit conversion and prevent it. More...
|
|
|
(Note that these are not member functions.)
|
constexpr bool | operator== (byte const &lhs, byte const &rhs) noexcept |
| The same as lhs.to_integer() == rhs.to_integer() More...
|
|
constexpr bool | operator!= (byte const &lhs, byte const &rhs) noexcept |
| The same as !(lhs == rhs) More...
|
|
constexpr byte & | operator<<= (byte &b, bsl::uint32 const shift) noexcept |
| The same as b = byte{b.to_integer() << shift}. More...
|
|
constexpr byte & | operator>>= (byte &b, bsl::uint32 const shift) noexcept |
| The same as b = byte{b.to_integer() >> shift}. More...
|
|
constexpr byte | operator<< (byte const &b, bsl::uint32 const shift) noexcept |
| The same as byte tmp{b}; tmp <<= shift;. More...
|
|
constexpr byte | operator>> (byte const &b, bsl::uint32 const shift) noexcept |
| The same as byte tmp{b}; tmp >>= shift;. More...
|
|
constexpr byte & | operator|= (byte &lhs, byte const &rhs) noexcept |
| The same as lhs = byte{lhs.to_integer() | rhs.to_integer()};. More...
|
|
constexpr byte & | operator&= (byte &lhs, byte const &rhs) noexcept |
| The same as lhs = byte{lhs.to_integer() & rhs.to_integer()};. More...
|
|
constexpr byte & | operator^= (byte &lhs, byte const &rhs) noexcept |
| The same as lhs = byte{lhs.to_integer() ^ rhs.to_integer()};. More...
|
|
constexpr byte | operator| (byte const &lhs, byte const &rhs) noexcept |
| The same as tmp{lhs}; tmp |= rhs;. More...
|
|
constexpr byte | operator & (byte const &lhs, byte const &rhs) noexcept |
| The same as tmp{lhs}; tmp &= rhs;. More...
|
|
constexpr byte | operator^ (byte const &lhs, byte const &rhs) noexcept |
| The same as tmp{lhs}; tmp ^= rhs;. More...
|
|
constexpr byte | operator~ (byte const &b) noexcept |
| The same as byte{~b.to_integer()}. More...
|
|
std::byte is a distinct type that implements the concept of byte as specified in the C++ language definition. Shift operations all require unsigned integer types, instead of any integer type.
namespace bsl
{
inline void
example_byte_overview() noexcept
{
bsl::byte const mybyte{static_cast<bsl::uint8>(42)};
bsl::print() <<
"success: " << mybyte.to_integer();
}
}
◆ byte() [1/5]
Default constructor. This ensures the byte type is a POD type, allowing it to be constructed as a global resource. This is needed as aligned storage uses a bsl::byte as its base type, and aligned storage is needed as a global resource to support the bsl::manager.
namespace bsl
{
inline void
example_byte_default_constructor() noexcept
{
if (b.to_integer() == expected) {
}
}
}
◆ byte() [2/5]
Creates a bsl::byte from a value_type.
namespace bsl
{
inline void
example_byte_by_value_constructor() noexcept
{
if (b.to_integer() == expected) {
}
}
}
SUPPRESSION: PRQA 2180 - exception required
- We suppress this because A12-1-4 states that all constructors that are callable from a fundamental type should be marked as explicit. This is a fundamental type, but all implicit conversions are disabled through the use of the implicit general template constructor that is deleted which absorbs all incoming potential implicit conversions.
- Parameters
-
val | the value of the integer to create the bsl::byte from. |
◆ byte() [3/5]
constexpr bsl::byte::byte |
( |
byte const & |
o | ) |
|
|
defaultnoexcept |
copy constructor
- Parameters
-
◆ byte() [4/5]
constexpr bsl::byte::byte |
( |
byte && |
o | ) |
|
|
defaultnoexcept |
move constructor
- Parameters
-
◆ byte() [5/5]
This constructor allows for single argument constructors without the need to mark them as explicit as it will absorb any incoming potential implicit conversion and prevent it.
SUPPRESSION: PRQA 2180 - false positive
- We suppress this because A12-1-4 states that all constructors that are callable from a fundamental type should be marked as explicit. This is callable with a fundamental type, but it is marked as "delete" which means it does not apply.
- Template Parameters
-
O | the type that could be implicitly converted |
- Parameters
-
val | the value that could be implicitly converted |
◆ to_integer()
template<typename T = value_type, enable_if_t< is_integral< T >::value, bool > = true>
constexpr T bsl::byte::to_integer |
( |
| ) |
const |
|
inlinenoexcept |
Returns the bsl::byte as a given integer type using a static_cast to perform the conversion.
namespace bsl
{
inline void
example_byte_to_integer() noexcept
{
if (b.to_integer() == expected) {
}
}
}
- Template Parameters
-
T | the type of integer to convert the bsl::byte to |
- Returns
- Returns the bsl::byte as a given integer type using a static_cast to perform the conversion.
◆ operator=() [1/2]
constexpr byte& bsl::byte::operator= |
( |
byte const & |
o | ) |
& |
|
defaultnoexcept |
copy assignment
- Parameters
-
- Returns
- a reference to *this
◆ operator=() [2/2]
constexpr byte& bsl::byte::operator= |
( |
byte && |
o | ) |
& |
|
defaultnoexcept |
move assignment
- Parameters
-
- Returns
- a reference to *this
◆ operator==()
constexpr bool operator== |
( |
byte const & |
lhs, |
|
|
byte const & |
rhs |
|
) |
| |
|
related |
The same as lhs.to_integer() == rhs.to_integer()
namespace bsl
{
inline void
example_byte_equal() noexcept
{
if (b1 == b2) {
}
}
}
- Parameters
-
lhs | the left hand side of the operator |
rhs | the right hand side of the operator |
- Returns
- returns lhs.to_integer() == rhs.to_integer()
◆ operator!=()
constexpr bool operator!= |
( |
byte const & |
lhs, |
|
|
byte const & |
rhs |
|
) |
| |
|
related |
The same as !(lhs == rhs)
namespace bsl
{
inline void
example_byte_not_equal() noexcept
{
if (b1 != b2) {
}
}
}
- Parameters
-
lhs | the left hand side of the operator |
rhs | the right hand side of the operator |
- Returns
- returns !(lhs == rhs)
◆ operator<<=()
The same as b = byte{b.to_integer() << shift}.
namespace bsl
{
inline void
example_byte_lshift_assign() noexcept
{
b <<= 1U;
if (b.to_integer() == expected) {
}
}
}
- Parameters
-
b | the bsl::byte to shift |
shift | the number of bits to shift b |
- Returns
- returns a reference to the provided "b"
◆ operator>>=()
The same as b = byte{b.to_integer() >> shift}.
namespace bsl
{
inline void
example_byte_rshift_assign() noexcept
{
b >>= 1U;
if (b.to_integer() == expected) {
}
}
}
- Parameters
-
b | the bsl::byte to shift |
shift | the number of bits to shift b |
- Returns
- returns a reference to the provided "b"
◆ operator<<()
The same as byte tmp{b}; tmp <<= shift;.
namespace bsl
{
inline void
example_byte_lshift() noexcept
{
}
}
}
- Parameters
-
b | the bsl::byte to shift |
shift | the number of bits to shift b |
- Returns
- returns byte tmp{b}; tmp <<= shift;
◆ operator>>()
The same as byte tmp{b}; tmp >>= shift;.
namespace bsl
{
inline void
example_byte_rshift() noexcept
{
}
}
}
- Parameters
-
b | the bsl::byte to shift |
shift | the number of bits to shift b |
- Returns
- returns byte tmp{b}; tmp >>= shift;
◆ operator|=()
constexpr byte & operator|= |
( |
byte & |
lhs, |
|
|
byte const & |
rhs |
|
) |
| |
|
related |
The same as lhs = byte{lhs.to_integer() | rhs.to_integer()};.
namespace bsl
{
inline void
example_byte_or_assign() noexcept
{
b1 |= b2;
if (b1.to_integer() == expected) {
}
}
}
- Parameters
-
lhs | the left hand side of the binary operation |
rhs | the right hand side of the binary operation |
- Returns
- returns a reference to the provided "lhs"
◆ operator&=()
constexpr byte & operator&= |
( |
byte & |
lhs, |
|
|
byte const & |
rhs |
|
) |
| |
|
related |
The same as lhs = byte{lhs.to_integer() & rhs.to_integer()};.
namespace bsl
{
inline void
example_byte_and_assign() noexcept
{
b1 &= b2;
if (b1.to_integer() == expected) {
}
}
}
- Parameters
-
lhs | the left hand side of the binary operation |
rhs | the right hand side of the binary operation |
- Returns
- returns a reference to the provided "lhs"
◆ operator^=()
constexpr byte & operator^= |
( |
byte & |
lhs, |
|
|
byte const & |
rhs |
|
) |
| |
|
related |
The same as lhs = byte{lhs.to_integer() ^ rhs.to_integer()};.
namespace bsl
{
inline void
example_byte_xor_assign() noexcept
{
b1 ^= b2;
if (b1.to_integer() == expected) {
}
}
}
- Parameters
-
lhs | the left hand side of the binary operation |
rhs | the right hand side of the binary operation |
- Returns
- returns a reference to the provided "lhs"
◆ operator|()
constexpr byte operator| |
( |
byte const & |
lhs, |
|
|
byte const & |
rhs |
|
) |
| |
|
related |
The same as tmp{lhs}; tmp |= rhs;.
namespace bsl
{
inline void
example_byte_or() noexcept
{
}
}
}
- Parameters
-
lhs | the left hand side of the binary operation |
rhs | the right hand side of the binary operation |
- Returns
- returns tmp{lhs}; tmp |= rhs;
◆ operator &()
constexpr byte operator & |
( |
byte const & |
lhs, |
|
|
byte const & |
rhs |
|
) |
| |
|
related |
The same as tmp{lhs}; tmp &= rhs;.
namespace bsl
{
inline void
example_byte_and() noexcept
{
}
}
}
- Parameters
-
lhs | the left hand side of the binary operation |
rhs | the right hand side of the binary operation |
- Returns
- returns tmp{lhs}; tmp &= rhs;
◆ operator^()
constexpr byte operator^ |
( |
byte const & |
lhs, |
|
|
byte const & |
rhs |
|
) |
| |
|
related |
The same as tmp{lhs}; tmp ^= rhs;.
namespace bsl
{
inline void
example_byte_xor() noexcept
{
}
}
}
- Parameters
-
lhs | the left hand side of the binary operation |
rhs | the right hand side of the binary operation |
- Returns
- returns tmp{lhs}; tmp ^= rhs;
◆ operator~()
constexpr byte operator~ |
( |
byte const & |
b | ) |
|
|
related |
The same as byte{~b.to_integer()}.
namespace bsl
{
inline void
example_byte_complement() noexcept
{
constexpr
bsl::uint8 expected{static_cast<bsl::uint8>(0xEF)};
}
}
}
- Parameters
-
- Returns
- returns byte{~b.to_integer()}
The documentation for this class was generated from the following file: