constexpr and endianness

后端 未结 8 550
無奈伤痛
無奈伤痛 2020-12-24 12:42

A common question that comes up from time to time in the world of C++ programming is compile-time determination of endianness. Usually this is done with barely portable #if

8条回答
  •  梦谈多话
    2020-12-24 12:59

    There is std::endian in the upcoming C++20.

    #include 
    
    constexpr bool little_endian() noexcept
    {
        return std::endian::native == std::endian::little;
    }
    

提交回复
热议问题