Use std :: byte cases

A recent addition std::bytein C ++ 17 made me wonder why this type was even added to the standard at all. Even after reading the cppreference link , this use of cases does not seem clear to me.

The only use case that I can come up with is that it expresses the intention more clearly, since std::byteit should be considered only as a set of bits instead of the type of character, such as charthat which we used for both purposes before, This means that:

std::vector<std::byte> memory;

Clearer than this:

std::vector<char> memory;

Is this the only use case and the reason it was added to the standard, or I don’t see a big point here?

+4
source share
1

, , ,

, . std::byte char:

- . char, char, unsigned char . " ". , . - , , - , . , - . .

( ). , , .

, std:: byte , :

char unsigned char, ( ), type, . - , .

which provides additional type security, as indicated in the above article.

+8
source

Source: https://habr.com/ru/post/1692452/


All Articles