如何在编译时确定我的平台是小终端还是大端呢?我看到了许多在运行时使用强制转换来确定的方法,以及一些与平台相关的选项。是否有一种便携或标准的方法来做到这一点?
constexpr bool is_little_endian = ?;
发布于 2018-05-02 23:04:32
C++20在<bit>
*中添加了std::endian
,它可以在一个constexpr上下文中使用。
if constexpr (std::endian::native == std::endian::little) {
std::cout << "litle endian\n";
} else if constexpr(std::endian::native == std::endian::big) {
std::cout << "big endian\n";
} else {
std::cout << "something silly\n";
}
*它最初是<type_traits>
,将出现在较旧的实现中。
https://stackoverflow.com/questions/50144736
复制相似问题