10#ifndef M5_UTILITY_STL_ENDIANNESS_HPP
11#define M5_UTILITY_STL_ENDIANNESS_HPP
13#if __cplusplus >= 202002L
16#elif __has_include(<endian.h>)
19#elif __has_include(<machine/endian.h>)
21#include <machine/endian.h>
31#if __cplusplus >= 202002L || DOXYGEN_PROCESS
36#elif __has_include(<endian.h>) || __has_include(<machine/endian.h>)
39#if defined(__BYTE_ORDER)
43#elif defined(_BYTE_ORDER)
47#elif defined(BYTE_ORDER)
58#elif defined(__BYTE_ORDER__)
60enum class endian {
little = __ORDER_LITTLE_ENDIAN__,
big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
65#elif defined(_MSC_VER)
71 "Cannot determine byte order at compile time. Falling back to runtime detection (strict aliasing violation).")
73constexpr uint32_t val32 = 0x11223344;
74constexpr uint8_t ref8 =
static_cast<const uint8_t&
>(val32);
87constexpr bool little = m5::stl::endian::native == m5::stl::endian::little;
88constexpr bool big = m5::stl::endian::native == m5::stl::endian::big;
92static_assert(
little ||
big ||
other,
"Unable to determine endianness");
93static_assert(((int)little + (
int)
big + (int)other) == 1,
"Endian matches more than one");
constexpr bool little
true if little endian.
Definition endianness.hpp:87
constexpr bool other
true if other endian.
Definition endianness.hpp:89
constexpr bool big
true if big endian.
Definition endianness.hpp:88
Top level namespace of M5.
Definition base64.cpp:39
STL compatibility functions and classes.