.. _program_listing_file_sockets_include_sockets_detail_byteswap.hpp: Program Listing for File byteswap.hpp ===================================== |exhale_lsh| :ref:`Return to documentation for file ` (``sockets/include/sockets/detail/byteswap.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include #include template constexpr T byteswap(T value) noexcept { #ifdef __cpp_lib_byteswap return std::byteswap(value); #else static_assert(std::has_unique_object_representations_v, "T may not have padding bits"); auto value_representation = std::bit_cast >(value); std::reverse(value_representation.begin(), value_representation.end()); return std::bit_cast(value_representation); #endif }