[SG10] Example for __cpp_lib_byte
Richard Smith
richard at metafoo.co.uk
Sat Oct 21 00:22:53 CEST 2017
On 20 October 2017 at 10:46, Jonathan Wakely <cxx at kayari.org> wrote:
> Would something like this be suitable?
>
> #if __cpp_lib_byte >= 201603
> using byte_type = std::byte;
> #else
> using byte_type = unsigned char;
> #endif
> alignas(T) byte_type rawbytes[sizeof(T)];
> // ...
>
> Both forms will work, but the std::byte version might be preferred to
> ensure that no arithmetic operations are accidentally performed on the
> values. The desired type-safety would only be enforced on
> implementations that support std::byte, but if the rest of the code is
> the same you can be fairly confident there's no arithmetic even when
> the type is unsigned char.
Seems reasonable to me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open-std.org/pipermail/features/attachments/20171020/0f6258c2/attachment.html
More information about the Features
mailing list