Checking availability of std :: byte

I would like to use the C ++ 17 type std::byte

if available, and fall back to use unsigned char

if not, then there is something like strings

#include <cstddef>

namespace my {
#if SOMETHING
using byte = std::byte;
#else
using byte = unsigned char;
#endif
}

      

Unfortunately, it looks like it std::byte

didn't come with a normal function check macro, so it's not obvious what should be SOMETHING

above. (AFAIK the value __cplusplus

for '17 hasn't been set yet, so I can't test that either.)

So, does anyone know of a way to determine if the std::byte

big three compilers are available?

+3


source to share


1 answer


For C ++ 17, the meaning __cplusplus

201703L

.

SD-6 recommends adding __cpp_lib_byte

as a function check macro for this, although this document is not standardized and remains to see what the standardization committee decides to do along these lines. For example gcc 7.2 supports std::byte

, but there is no macro for it. So the future ... is not now.



Note that usage unsigned char

gives you almost the same behavior as std::byte

- the only difference is that it unsigned char

supports additional arithmetic operations. So having an imprecise support check std::byte

is okay - as long as you test some compiler that supports std::byte

it to make sure you don't do anything, you are fine.

0


source







All Articles