Since C++20 we can have:
constexpr bool is_little_endian = std::endian::native == std::endian::little;
I would like to have code that does this if it is available, otherwise does runtime detection. Is this possible?
Maybe the code would look like:
template<bool b = std_endian_exists_v> constexpr bool is_little_endian;
template<> constexpr bool is_little_endian<true> = std::endian::native == std::endian::little;
template<> constexpr bool is_little_endian<false> = runtime_detection();
I am aware that testing __cplusplus via preprocessor is possible, however compilers phase in C++20 support in various stages so this is not a reliable indicator in either direction.