StormByte 2.0.0
C++26 foundation of the StormByte suite
 
Loading...
Searching...
No Matches
StormByte::Type::Detail Namespace Reference

Functions

template<typename VariantT , typename U , std::size_t... I>
constexpr bool variant_has_type_impl (std::index_sequence< I... > seq) noexcept
 Fold: is stripped U one of VariantT's alternatives?
 
Endian
template<typename U >
requires TriviallyCopyable<U> && (sizeof(U) > 0)
constexpr U swap_endian (U val) noexcept
 Reverses the object-representation byte order of val.
 

Variables

template<typename T >
constexpr bool ArrayV = false
 Primary: T is not std::array.
 
template<typename T >
constexpr bool is_variant_v = false
 true when T is exactly std::variant after stripping cv and references.
 
template<typename VariantT , typename U >
constexpr bool variant_has_type_v
 Convenience wrapper around StormByte::Type::Detail::variant_has_type_impl.
 

Function Documentation

◆ swap_endian()

template<typename U >
requires TriviallyCopyable<U> && (sizeof(U) > 0)
constexpr U StormByte::Type::Detail::swap_endian ( U  val)
constexprnoexcept

Reverses the object-representation byte order of val.

Template Parameters
UTrivially copyable value type.
Parameters
[in]valValue whose bytes are reversed.
Returns
val with endianness swapped.

This always reverses bytes. Whether the caller should invoke it (host ≠ little-endian) is Serializable's job. Integrals go through std::byteswap; every other trivial type goes through std::bit_cast + reverse so float, enum and small POD structs stay defined.

Warning
Not a format detector. No BOM, no std::endian test.

◆ variant_has_type_impl()

template<typename VariantT , typename U , std::size_t... I>
constexpr bool StormByte::Type::Detail::variant_has_type_impl ( std::index_sequence< I... >  seq)
constexprnoexcept

Fold: is stripped U one of VariantT's alternatives?

Template Parameters
VariantTA std::variant (already stripped by the caller).
UCandidate alternative.
IIndex pack over std::variant_size_v<VariantT>.
Parameters
[in]seqIndex sequence; unused except to expand I.
Returns
true if U matches any alternative.

Variable Documentation

◆ ArrayV

template<typename T >
constexpr bool StormByte::Type::Detail::ArrayV = false
inlineconstexpr

Primary: T is not std::array.

Template Parameters
TDecayed type.

◆ is_variant_v

template<typename T >
constexpr bool StormByte::Type::Detail::is_variant_v< std::variant< Ts... > > = false
constexpr

true when T is exactly std::variant after stripping cv and references.

Specialization for every std::variant alternative list.

Template Parameters
TType to test.

Partial specialization of a variable template — not SFINAE. Needed because there is no standard std::is_variant.

Template Parameters
TsVariant alternatives.

◆ variant_has_type_v

template<typename VariantT , typename U >
constexpr bool StormByte::Type::Detail::variant_has_type_v
constexpr
Initial value:
=
variant_has_type_impl<VariantT, U>(
std::make_index_sequence<std::variant_size_v<VariantT>>()
)

Convenience wrapper around StormByte::Type::Detail::variant_has_type_impl.

Template Parameters
VariantTA std::variant.
UCandidate alternative.