This is a suggestion to make absl/base/internal/endian.h more constexpr. If the feature test macro __cpp_lib_byteswap is present then std::byteswap (which is already constexpr) can be used instead of the compiler builtins (e.g. __builtin_bswap64 and whatnot). If __cpp_lib_byteswap is not present then it's still possible to implement a constexpr byte swap using only C++11 features (and Clang/GCC should still emit code that use the bswap instruction for runtime calls), see https://stackoverflow.com/a/36937049/7897084 . By doing this all the gbswap* functions can be marked constexpr.
Likewise the other utility functions defined in endian.h that just call byte swap routines (e.g. the ToHost* and FromHost* functions) can also be marked constexpr.
Tangentially related, absl/base/config.h should consider using std::endian from C++20 if available (feature test macro __cpp_lib_endian) to check for system endianness instead of the compiler builtins.
This is a suggestion to make
absl/base/internal/endian.hmore constexpr. If the feature test macro__cpp_lib_byteswapis present thenstd::byteswap(which is already constexpr) can be used instead of the compiler builtins (e.g.__builtin_bswap64and whatnot). If__cpp_lib_byteswapis not present then it's still possible to implement a constexpr byte swap using only C++11 features (and Clang/GCC should still emit code that use thebswapinstruction for runtime calls), see https://stackoverflow.com/a/36937049/7897084 . By doing this all thegbswap*functions can be marked constexpr.Likewise the other utility functions defined in
endian.hthat just call byte swap routines (e.g. theToHost*andFromHost*functions) can also be marked constexpr.Tangentially related,
absl/base/config.hshould consider usingstd::endianfrom C++20 if available (feature test macro__cpp_lib_endian) to check for system endianness instead of the compiler builtins.