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

Go to the source code of this file.

Classes

class  hxnullptr_t
struct  hxtrue_t
struct  hxfalse_t
struct  hxbinds_directly< T, U_ >
struct  hxis_array< T >
struct  hxis_array< T[size_]>
struct  hxis_array< T[]>
struct  hxis_const< T >
struct  hxis_const< const T >
struct  hxis_floating_point< T >
struct  hxis_integral< T >
struct  hxis_lvalue_reference< T >
struct  hxis_lvalue_reference< T & >
struct  hxis_pointer< T >
struct  hxis_reference< T >
struct  hxis_reference< T & >
struct  hxis_reference< T && >
struct  hxis_rvalue_reference< T >
struct  hxis_rvalue_reference< T && >
struct  hxis_same< A_, B_ >
struct  hxis_same< A_, A_ >
struct  hxis_void< T >

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

void hxfloat_dump (const float *address_, size_t floats_)
void hxhex_dump (const void *address_, size_t bytes_, bool pretty_)
template<typename T, hxsize_t N_>
HX_NS_BEGIN_ constexpr hxsize_t hxsize (T(&)[N_])
template<typename T>
T && hxdeclval (void) noexcept
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 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 hxnullptr_t hxnullptr {}

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

Internal.

Implements std::remove_cv. 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.

◆ 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_dump()

void hxfloat_dump ( const float * address_,
size_t floats_ )

hxfloat_dump - Prints an array of floating point values.

  • address : Non-null pointer to the start of the float array.
  • floats : 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:304

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&&.

◆ hxhex_dump()

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

hxhex_dump - 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.

◆ 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 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_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

◆ hxnullptr

hxnullptr_t hxnullptr {}
inlineconstexpr

hxnullptr - An instance of a class that will only convert to a null pointer.

Useful when an integer constant arg would be ambiguous or otherwise break template code. hxnullptr is a hxnullptr_t. Use plain hxnull for == and != comparisons.