libhatchet
Loading...
Searching...
No Matches
hxutility.h File Reference

Go to the source code of this file.

Classes

class  hxnil_t
struct  hxtrue_t
struct  hxfalse_t

Concepts

concept  hxconvertible_to
concept  hxsame_as

Typedefs

template<typename T>
using hxremove_cv_t = typename hxremove_cv_<T>::type
template<typename T>
using hxremove_pointer_t = typename hxremove_pointer_<T>::type
template<typename T>
using hxremove_reference_t = typename hxremove_reference_<T>::type
template<typename T>
using hxremove_cvref_t = hxremove_cv_t<hxremove_reference_t<T>>
template<typename T>
using hxrestrict_t = typename hxrestrict_t_<T>::type

Functions

HX_C_BEGIN_ void hxfloat_view (const float *address_, size_t size_)
void hxhex_view (const void *address_, size_t bytes_, bool pretty_)
template<typename T, hxsize_t N_>
HX_C_END_ HX_NS_BEGIN_ constexpr hxsize_t hxsize (T(&)[N_])
template<typename T>
T && hxdeclval (void) noexcept
template<typename T, typename U_>
constexpr bool hxbinds_directly (void)
template<typename T>
constexpr bool hxis_array (void)
template<typename T>
constexpr bool hxis_const (void)
template<typename T>
constexpr bool hxis_floating_point (void)
template<typename T>
constexpr bool hxis_integral (void)
template<typename T>
constexpr bool hxis_lvalue_reference (void)
template<typename T>
constexpr bool hxis_pointer (void)
template<typename T>
constexpr bool hxis_reference (void)
template<typename T>
constexpr bool hxis_rvalue_reference (void)
template<typename A_, typename B_>
constexpr bool hxis_same (void)
template<typename T>
constexpr bool hxis_void (void)
constexpr bool hxisgraph (char ch_)
constexpr bool hxisspace (char ch_)
int hxlog2i (uint32_t i_)
template<typename T>
constexpr T hxabs (T x_)
template<typename T>
constexpr T hxclamp (T x_, T minimum_, T maximum_)
template<typename T>
constexpr T && hxforward (hxremove_reference_t< T > &&x_)
template<typename T>
constexpr T && hxforward (hxremove_reference_t< T > &x_)
template<typename like_t_, typename value_t_>
constexpr hxforward_like_t_< like_t_, value_t_ > hxforward_like (value_t_ &value_)
template<typename T>
constexpr T hxmax (T x_, T y_)
template<typename T>
constexpr T hxmin (T x_, T y_)
template<typename T>
constexpr hxremove_reference_t< T > && hxmove (T &&t_)
template<typename T>
constexpr void hxswap (T &x_, T &y_)
template<typename T>
void hxswap_memcpy (T &x_, T &y_)

Variables

constexpr hxnil_t hxnil {}

Detailed Description

A few utility functions and most standard C++ meta programming functions.

Typedef Documentation

◆ hxremove_cv_t

template<typename T>
using hxremove_cv_t = typename hxremove_cv_<T>::type

hxremove_cv_t - Removes const and volatile from a type.

Implements std::remove_cv_t. This is used to maintain semantic compatibility with the standard.

◆ hxremove_cvref_t

template<typename T>
using hxremove_cvref_t = hxremove_cv_t<hxremove_reference_t<T>>

hxremove_cvref_t<T> - Returns T with const, volatile, and references removed.

◆ hxremove_pointer_t

template<typename T>
using hxremove_pointer_t = typename hxremove_pointer_<T>::type

hxremove_pointer_t<T> - Returns T with one pointer level removed.

◆ hxremove_reference_t

template<typename T>
using hxremove_reference_t = typename hxremove_reference_<T>::type

hxremove_reference_t<T> - Returns T with references removed.

◆ hxrestrict_t

template<typename T>
using hxrestrict_t = typename hxrestrict_t_<T>::type

hxrestrict_t - Adds the __restrict keyword to C++ pointers.

(Non-standard.)

Function Documentation

◆ hxabs()

template<typename T>
T hxabs ( T x_)
constexpr

hxabs - Returns the absolute value of x using a < comparison.

  • x : The value to compute the absolute value for.

◆ hxbinds_directly()

template<typename T, typename U_>
bool hxbinds_directly ( void )
constexpr

hxbinds_directly<T, U> - Returns true when an lvalue of type U binds to T& without creating a temporary.

  • T : The referenced type.
  • U : The type of the lvalue being bound.

◆ hxclamp()

template<typename T>
T hxclamp ( T x_,
T minimum_,
T maximum_ )
constexpr

hxclamp - Returns x clamped between the minimum and maximum using < comparisons.

  • x : The value to clamp.
  • minimum : The minimum allowable value.
  • maximum : The maximum allowable value.

◆ hxdeclval()

template<typename T>
T && hxdeclval ( void )
noexcept

hxdeclval - Implements std::declval.

Returns a T&& reference for use in unevaluated contexts such as decltype. Must not be called or defined.

◆ hxfloat_view()

HX_C_BEGIN_ void hxfloat_view ( const float * address_,
size_t size_ )

hxfloat_view - Prints an array of floating point values.

  • address : Non-null pointer to the start of the float array.
  • size : The number of floats to print.

◆ hxforward() [1/2]

template<typename T>
T && hxforward ( hxremove_reference_t< T > && x_)
constexpr

hxforward - Implements std::forward.

Call as hxforward<T>(x) from inside a templated forwarding function where the parameter was declared T&& and T was deduced. T must be explicitly specified. E.g.,

template<typename T>
void forwards_temp(T&&x) { requires_temp(hxforward<T>(x)); }
constexpr T && hxforward(hxremove_reference_t< T > &&x_)
hxforward - Implements std::forward.
Definition hxutility.h:353

This is the T&& version of hxforward<T>.

◆ hxforward() [2/2]

template<typename T>
T && hxforward ( hxremove_reference_t< T > & x_)
constexpr

hxforward - This is the T& version of hxforward<T>.

It gets invoked when T turns out to be an l-value. This happens when a T& is passed as a T&&.

◆ hxforward_like()

template<typename like_t_, typename value_t_>
hxforward_like_t_< like_t_, value_t_ > hxforward_like ( value_t_ & value_)
constexpr

hxforward_like<T> - Returns value with the constness and value category of T.

T must be explicitly specified.

  • value : The value to forward.

◆ hxhex_view()

void hxhex_view ( const void * address_,
size_t bytes_,
bool pretty_ )

hxhex_view - Prints an array of bytes formatted in hexadecimal.

Additional information provided when pretty is non-zero.

  • address : Non-null pointer to the start of the byte array.
  • bytes : The number of bytes to print.
  • pretty : Set non-zero to include extended visualization.

◆ hxis_array()

template<typename T>
bool hxis_array ( void )
constexpr

hxis_array<T> - Implements std::is_array.

◆ hxis_const()

template<typename T>
bool hxis_const ( void )
constexpr

hxis_const<T> - Implements std::is_const.

◆ hxis_floating_point()

template<typename T>
bool hxis_floating_point ( void )
constexpr

hxis_floating_point<T> - Implements std::is_floating_point.

◆ hxis_integral()

template<typename T>
bool hxis_integral ( void )
constexpr

hxis_integral<T> - Implements std::is_integral.

◆ hxis_lvalue_reference()

template<typename T>
bool hxis_lvalue_reference ( void )
constexpr

hxis_lvalue_reference<T> - Implements std::is_lvalue_reference.

◆ hxis_pointer()

template<typename T>
bool hxis_pointer ( void )
constexpr

hxis_pointer<T> - Implements std::is_pointer.

◆ hxis_reference()

template<typename T>
bool hxis_reference ( void )
constexpr

hxis_reference<T> - Implements std::is_reference.

◆ hxis_rvalue_reference()

template<typename T>
bool hxis_rvalue_reference ( void )
constexpr

hxis_rvalue_reference<T> - Implements std::is_rvalue_reference.

◆ hxis_same()

template<typename A_, typename B_>
bool hxis_same ( void )
constexpr

hxis_same<A, B> - Implements std::is_same.

◆ hxis_void()

template<typename T>
bool hxis_void ( void )
constexpr

hxis_void<T> - Implements std::is_void.

◆ hxisgraph()

bool hxisgraph ( char ch_)
constexpr

hxisgraph - Implements standard isgraph for a locale where all non-ASCII characters are considered graphical or mark making.

This is compatible with scanf-style parsing of UTF-8 string parameters. However, this is not en_US.UTF-8, the default C locale or the POSIX locale.

◆ hxisspace()

bool hxisspace ( char ch_)
constexpr

hxisspace - Implements standard isspace for a locale where all non-ASCII characters are considered graphical or mark making.

Returns nonzero for space and \t \n \v \f \r. This is compatible with scanf-style parsing of UTF-8 string parameters. However, this is not en_US.UTF-8. It does match the default C locale and the POSIX locale.

◆ hxlog2i()

int hxlog2i ( uint32_t i_)
inline

hxlog2i - Returns log2(n) as an integer which is the power of 2 of the largest bit in n.

WARNING: hxlog2i(0) is UB. The fallback implementation returns -127 for 0 and rounds up for i >= 2^32-128 returning an incorrect result.

  • i : A uint32_t.

◆ hxmax()

template<typename T>
T hxmax ( T x_,
T y_ )
constexpr

hxmax - Returns the maximum value of x and y using a < comparison.

  • x : The first value.
  • y : The second value.

◆ hxmin()

template<typename T>
T hxmin ( T x_,
T y_ )
constexpr

hxmin - Returns the minimum value of x and y using a < comparison.

  • x : The first value.
  • y : The second value.

◆ hxmove()

template<typename T>
hxremove_reference_t< T > && hxmove ( T && t_)
constexpr

hxmove - Implements std::move.

Converts either a T& or a T&& to a T&&. Do not specify T explicitly as it will not work as expected. This uses the rules about reference collapsing to handle both T& and T&&.

◆ hxsize()

template<typename T, hxsize_t N_>
HX_C_END_ HX_NS_BEGIN_ constexpr hxsize_t hxsize ( T(&) [N_])
constexpr

hxsize - Returns the size of a C array.

Rejects pointer arguments at compile time.

◆ hxswap()

template<typename T>
void hxswap ( T & x_,
T & y_ )
constexpr

hxswap - Exchanges the contents of x and y using a temporary.

If T has T::T(T&&) or T::operator=(T&&) then those will be used.

◆ hxswap_memcpy()

template<typename T>
void hxswap_memcpy ( T & x_,
T & y_ )

hxswap_memcpy - Exchanges the contents of x and y using memcpy and a stack temporary.

This is intended for internal use where T is known to be trivially copyable.

  • x : First T&.
  • y : Second T&.

Variable Documentation

◆ hxnil

hxnil_t hxnil {}
inlineconstexpr

hxnil - An instance of hxnil_t useful as a shorthand.

Also used as a tag for nothing. Use plain hxnull for == and != comparisons.