M5Utility 0.3.0 git rev:41a629c
Loading...
Searching...
No Matches
byteswap.hpp File Reference

std::byteswap for less than C++23 More...

#include <stdint.h>
#include <type_traits>
#include <cstring>

Go to the source code of this file.

Classes

struct  m5::stl::detail::is_int128< T >
 
struct  m5::stl::detail::is_integer_or_enum< T >
 
struct  m5::stl::detail::is_unsigned_ex< T >
 
struct  m5::stl::detail::make_unsigned_impl< T >
 
struct  m5::stl::detail::make_unsigned_ex< T >
 

Namespaces

namespace  m5
 Top level namespace of M5.
 
namespace  m5::stl::detail
 \exclude
 

Functions

template<typename T , typename std::enable_if< detail::is_integer_or_enum< T >::value, std::nullptr_t >::type = nullptr>
constexpr T m5::stl::byteswap (T v) noexcept
 byteswap for integral type
 
template<typename T , typename std::enable_if< detail::is_integer_or_enum< T >::value, std::nullptr_t >::type = nullptr>
constexpr T m5::stl::byteswap_with_portable (T v) noexcept
 byteswap using portable bit manipulation (always available, for testing both paths)
 
template<typename T , typename std::enable_if<!detail::is_integer_or_enum< T >::value, std::nullptr_t >::type = nullptr>
T m5::stl::byteswap (T)=delete
 byteswap for integral type
 
template<typename T , typename std::enable_if< detail::byteswap_value_supported< T >::value, std::nullptr_t >::type = nullptr>
T m5::stl::byteswap_value (T v) noexcept
 byteswap for integral, enum and floating-point types
 

Detailed Description

std::byteswap for less than C++23

Function Documentation

◆ byteswap_value()

template<typename T , typename std::enable_if< detail::byteswap_value_supported< T >::value, std::nullptr_t >::type = nullptr>
T m5::stl::byteswap_value ( T v)
inlinedeletenoexcept

byteswap for integral, enum and floating-point types

Parameters
vValue to reverse
Returns
v with its bytes reversed
Note
Integral and enum types are handed to byteswap(). A floating-point value is bit-cast to a same-size unsigned integer, reversed, and bit-cast back; special values (NaN, +/-inf, +/-0) are reversed as raw bit patterns without special-casing
Aggregates stay prohibited, as with byteswap(): reversing the bytes of a whole object is not meaningful, and letting it through would hide the mistake