Bitcoin Core 28.99.0
P2P Digital Currency
Functions
util::hex_literals Namespace Reference

""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseHex(). More...

Functions

template<util::detail::Hex str>
constexpr auto operator""_hex ()
 
template<util::detail::Hex str>
constexpr auto operator""_hex_u8 ()
 
template<util::detail::Hex str>
constexpr auto operator""_hex_v ()
 
template<util::detail::Hex str>
auto operator""_hex_v_u8 ()
 

Detailed Description

""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseHex().

Variants provided:

Warning
It could be necessary to use vector instead of array variants when serializing, or vice versa, because vectors are assumed to be variable- length and serialized with a size prefix, while arrays are considered fixed length and serialized with no prefix.
It may be preferable to use vector variants to save stack space when declaring local variables if hex strings are large. Alternatively variables could be declared constexpr to avoid using stack space.
Avoid uint8_t variants when not necessary, as the codebase migrates to use std::byte instead of unsigned char and uint8_t.
Note
One reason ""_hex uses std::array instead of std::vector like ParseHex() does is because heap-based containers cannot cross the compile- time/runtime barrier.

Function Documentation

◆ operator""_hex()

template<util::detail::Hex str>
constexpr auto util::hex_literals::operator""_hex ( )
constexpr

Definition at line 430 of file strencodings.h.

◆ operator""_hex_u8()

template<util::detail::Hex str>
constexpr auto util::hex_literals::operator""_hex_u8 ( )
constexpr

Definition at line 433 of file strencodings.h.

◆ operator""_hex_v()

template<util::detail::Hex str>
constexpr auto util::hex_literals::operator""_hex_v ( )
constexpr

Definition at line 436 of file strencodings.h.

◆ operator""_hex_v_u8()

template<util::detail::Hex str>
auto util::hex_literals::operator""_hex_v_u8 ( )
inline

Definition at line 439 of file strencodings.h.