cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
Public Member Functions | Public Attributes | List of all members
byte Struct Reference

Implements the backport for std::byte. More...

Public Member Functions

 operator unsigned char () const noexcept
 Explicit conversion to unsigned char (implementation-defined).
 

Public Attributes

__implementation_defined_t value
 Stored value corresponding to one "byte" (implementation-defined).
 

Detailed Description

Implements the backport for std::byte.

C++17 Backports:
Standard declaration of a raw data, non-integral byte type.
See also
WG21 index p0298r3 byte type
types/byte @ cppreference

This implementation-defined struct implements the functionality for std::byte where required (eg.: in C++03 mode).

In general, a byte is structured as follows:

enum class byte : unsigned char {};
unsigned to_integral (byte); // implementation_defined
byte b = to_byte('c');
unsigned char uc = explicit_cast<unsigned char>(b);

Only comparison operator, bit operations (via bitmask operators) and explicit conversion to unsigned char are defined for it. Just like std::byte, it has no value-taking constructors.

The implementation changes according to the language features that cxxomfort can find. In C++11 onwards mode, an actual enum class is used.

In general, the following operations are allowed on a byte :

byte b = to_byte(0xnn);
b | c;
b & c;
b ^ c;
b >>= 2;
c <<= 3;
c= ~b;
int cint = to_integer<int>(c);
byte d { 0x23 }; // c++17 only

Except where explicitly indicated, all operations on byte are nothrow and (C++14) constexpr, including conversions to integrals.

The helper function to_byte() is used to construct a byte pre-C++17.

The helper functions to_integer() and to_value() can recover the value stored by a byte into an integral or unsigned char variable respectively.

If cxxomfort has to activate this backport, the SD6 macro __cpp_lib_byte is defined.

See std::byte for more information.


The documentation for this struct was generated from the following file: