std::endian

Header: <bit>

Indicates the endianness of all scalar types:

# Declarations

enum class endian
{
little = /* implementation-defined */,
big = /* implementation-defined */,
native = /* implementation-defined */,
};

(since C++20)

# Notes

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

# Example

#include <bit>
#include <iostream>
 
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";
}

# See also