36 questions
Score of 2
2 answers
232 views
Aliasing concerns for custom std::byte-like type
I am working in an environment which does not have access to the compiler's normal stdlib, mostly due to disabled exceptions, instead using a custom port for the same functionality. For example, ...
Score of 0
1 answer
626 views
Including Windows.h is producing errors of: 'byte': ambiguous symbol [duplicate]
I'm getting many errors of the following type. Clearly, Microsoft has a definition of byte that clashes with Standard C++'s definition of std::byte (after a using namespace std, that I use in ...
Score of 4
1 answer
267 views
Why were charN_t designed as built-in types, but std::byte was not?
Why were char8_t, char16_t, char32_t designed as built-in types, but std::byte was not?
As per the C++ philosophy, if something can be implemented in the library, we almost always prefer doing so to ...
Score of -1
1 answer
205 views
Unwanted implicit object creation in an array of std::byte VS char
It seems that std::byte is generally meant to replace the use of char in buffers for allocating blocks of raw memory.
But I'm worried about the fact that std::byte can implicitly create objects in an ...
Score of 5
1 answer
235 views
Is there a reason that 8 byte std::array comparisons seem to be producing different assembly for char vs. std::byte?
I noticed 8 byte std::array comparisons seem to be producing assembly different from bit_casting. GCC seems to do what I expect for a char array, but clang generates an extra mov instruction (spilling ...
Score of 3
1 answer
147 views
Non-uniform byte initialization
Is there a reason, simple enough to explain to non language lawyers, why the initializations commented out fail to compile while the first one succeeds?
#include <cstddef>
void test() {
std::...
Score of 3
1 answer
175 views
Does std::byte constructor extract LSB or MSB from integer?
I'm struggling to understand the following line of code:
if constexpr (std::is_same_v<T, bool>)
{
std::byte change = std::byte(static_cast<uint32_t>(in) << m_addr[1]);
std::...
Score of 19
1 answer
11497 views
A byte type: std::byte vs std::uint8_t vs unsigned char vs char vs std::bitset<8>
C++ has a lot of types that vaguely describe the same thing. Assuming that we are compiling for an architecture where a byte is 8-bit, all of the following types are vaguely similar:
std::byte
std::...
Score of 2
1 answer
713 views
std::is_enum_v<std::byte> evaluates to true [duplicate]
According to the standard reference, std::is_enum_v evaluates to true for enumeration types and to false otherwise. An enumeration type starts with an enum key, i.e. either one of enum, enum class or ...
Score of 1
1 answer
379 views
How to create an octet type similar to std::byte in C++?
The type std::byte comprises CHAR_BIT bits, and that may be more than 8.
So, how do I declare a true octet in C++?
Score of 15
1 answer
1237 views
Only bitwise operations for std::byte in C++17?
In CPP Reference it is stated that:
std::byte is a distinct type that implements the concept of byte as specified in the C++ language definition.
Like char and unsigned char, it can be used to access ...
Score of 5
2 answers
392 views
Is it possible to backport std::byte to C++14
std::byte is defined in C++17 as:
enum class byte : unsigned char {};
I'm currently stuck at using C++14, and I wonder if I add the same definition in C++14 (in some non-std namespace, along with the ...
Score of 6
0 answers
162 views
std::byte overhead from integer promotion
Consider an unsigned char v that goes through a series of bit-wise operations with the result stored back to v. Under the hood, it is integer promoted once, undergoes a series of operations, and the ...
Score of 5
1 answer
590 views
C++17 std::byte produces less optimized code with the standard algorithms in GCC
I really like std::byte as a distinct type that implements the concept of byte as specified in the C++ language definition. What I don't like is the fact that modern C++ compilers will produce less ...
Score of 0
0 answers
220 views
upgrading byte enums to c++17
I have a codebase with byte defined like so:
typedef unsigned char byte;
And this enum:
enum SymbolTypes
{
VARIABLE_SYMBOL_TYPE = 0,
IDENTIFIER_SYMBOL_TYPE = 1,
STR_CONSTANT_SYMBOL_TYPE = ...