std::endian - cppreference.com (original) (raw)

| Defined in header | | | | ------------------------------------------------------------------------------------------------------------------------------------------------ | | ------------- | | enum class endian{ little = /* implementation-defined */, big = /* implementation-defined */, native = /* implementation-defined */, }; | | (since C++20) |

Indicates the endianness of all scalar types:

Corner case platforms are also supported:

[edit] Possible implementation

enum class endian { #if defined(_MSC_VER) && !defined(clang) little = 0, big = 1, native = little #else little = ORDER_LITTLE_ENDIAN, big = ORDER_BIG_ENDIAN, native = BYTE_ORDER #endif };

[edit] Notes

Feature-test macro Value Std Feature
__cpp_lib_endian 201907L (C++20) std::endian

[edit] Example

#include #include   int main() { if constexpr (std::endian::native == std::endian::big) std::cout << "big-endian\n"; else if constexpr (std::endian::native == std::endian::little) std::cout << "little-endian\n"; else std::cout << "mixed-endian\n"; }

Possible output:

[edit] See also