Questions tagged [std-byte]

27 questions
3
votes
2 answers

Can std::byte replace std::aligned_storage?

C++17 introduced a new type, std::byte, so now we finally have a first-class citizen type to represent bytes in memory. Besides being a novelty in the standard, the C++ rules for object creation, start and end of life, aliasing etc. are fairly…
bolov
  • 72,283
  • 15
  • 145
  • 224
3
votes
2 answers

std::byte is not member of 'std'

I'm trying to learn new features/gimmicks of c++17, but then I got to std::byte and for some unknown reason I can't seem to be able to compile even most basic "hello world" type program with the type. entire program: #include int main(int…
DFDark
  • 219
  • 1
  • 2
  • 14
2
votes
1 answer

std::is_enum_v evaluates to true

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 enum struct. In wrote the following…
Mohammed Li
  • 823
  • 2
  • 7
  • 22
2
votes
0 answers

Serializing data into a C++17 std::byte vector

I'm trying to serialize/deserialize data to/from std::vector. The code below shows one solution with boost::serialization, but I think this applies to other serialization libraries. The problem with the solution is that it uses use…
2
votes
2 answers

Why I can't static_cast char* to std::byte*?

I know I can use reinterpret_cast, but it seems weird that I can not go from char to "universal" type like std::byte. Is this just unfortunate mistake/limitation, or there is a reason for this? Example: int main(){ std::string s{"abc"}; …
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
1
vote
1 answer

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++?
wimalopaan
  • 4,838
  • 1
  • 21
  • 39
1
vote
1 answer

std::byte bitwise operators |, &, ^, ~: why cast to unsigned int?

According to std::byte's documentation on cppreference, the implementation of operator| for std::byte should be equivalent to constexpr std::byte operator|(std::byte l, std::byte r) noexcept { return std::byte{ static_cast(l) |…
paolo
  • 2,345
  • 1
  • 3
  • 17
0
votes
0 answers

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 = 2, INT_CONSTANT_SYMBOL_TYPE = 3, …
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
0
votes
1 answer

C++ Copy Raw std::bytes to std::vector

I have an FILE_NOTIFY_INFORMATION struct which i have filled like this: FILE_NOTIFY_INFORMATION* fni = new FILE_NOTIFY_INFORMATION; fni->Action = 1; wcscpy_s(fni->FileName,12, L"example.txt"); fni->FileNameLength = 12; fni->NextEntryOffset = 0; I…
Kevin
  • 785
  • 2
  • 10
  • 32
0
votes
0 answers

Passing std::byte* through JNI to java

Tried this: void sendInfo(std::byte* something, long dataSize) { JavaVM* vm = nsCtx.javaVM; JNIEnv* env; int envState = getEnvState(&env, vm); if (envState == JNI_OK || envState == JNI_EDETACHED) { LOGD("Environment…
0
votes
1 answer

How do we initialize a std::byte with a double?

I'm attempting to use std::byte for the first time but I'm failing to initialize the value. #include double red_double = 0.5; auto red_byte = std::byte(red_double * 255); Results in: error C2440: '': cannot convert…
Flux
  • 1
  • 2
0
votes
2 answers

Are bit flags an intended use of std::byte?

As of C++17 there are the following types representing an 8-bit unit of storage: char, unsigned char int8_t, uint8_t std::byte As I understand it the intent is that char's should now be used when the byte is actually representing a character, for…
jwezorek
  • 8,592
  • 1
  • 29
  • 46
1
2