12#if HX_USE_MACROS_WITH_MODULE
13#error Header does not provide macros alone.
47template<
bool condition_,
typename type_=
void>
struct hxenable_if_ { };
48template<
typename type_>
struct hxenable_if_<true, type_> {
using type = type_; };
49template<
bool condition_,
typename type_=
void>
50using hxenable_if_t =
typename hxenable_if_<condition_, type_>::type;
60 template<
typename T_>
hxinline constexpr operator T_*()
const {
return 0; }
62 template<
typename T_,
typename M_>
hxinline constexpr operator M_ T_::*()
const {
return 0; }
70template<
typename T_>
struct hxremove_cv_ {
using type = T_; };
71template<
typename T_>
struct hxremove_cv_<const T_> {
using type = T_; };
72template<
typename T_>
struct hxremove_cv_<volatile T_> {
using type = T_; };
73template<
typename T_>
struct hxremove_cv_<const volatile T_> {
using type = T_; };
79template<
typename T_>
using hxremove_cv_t =
typename hxremove_cv_<T_>::type;
82template<
typename T_>
struct hxremove_pointer_ {
using type = T_; };
83template<
typename T_>
struct hxremove_pointer_<T_*> {
using type = T_; };
84template<
typename T_>
struct hxremove_pointer_<T_*
const> {
using type = T_; };
85template<
typename T_>
struct hxremove_pointer_<T_*
volatile> {
using type = T_; };
86template<
typename T_>
struct hxremove_pointer_<T_*
const volatile> {
using type = T_; };
93template<
typename T_>
struct hxremove_reference_ {
using type = T_; };
94template<
typename T_>
struct hxremove_reference_<T_&> {
using type = T_; };
95template<
typename T_>
struct hxremove_reference_<T_&&> {
using type = T_; };
115template<
typename T_,
typename U_>
116struct hxbinds_directly_ {
124#pragma warning(disable: 4244 4267)
126 constexpr static bool value =
decltype(test_(
hxdeclval<U_&>()))::value;
137template<
typename T_,
typename U_>
141template<
typename T_>
struct hxis_array_ :
public hxfalse_t { };
142template<
typename T_,
size_t size_>
struct hxis_array_<T_[size_]> :
public hxtrue_t { };
143template<
typename T_>
struct hxis_array_<T_[]> :
public hxtrue_t { };
151template<
typename T_>
struct hxis_const_ :
public hxfalse_t { };
152template<
typename T_>
struct hxis_const_<const T_> :
public hxtrue_t { };
160template<
typename T_>
struct hxis_floating_point_ :
public hxfalse_t { };
161template<>
struct hxis_floating_point_<float> :
public hxtrue_t { };
162template<>
struct hxis_floating_point_<double> :
public hxtrue_t { };
163template<>
struct hxis_floating_point_<long double> :
public hxtrue_t { };
169 return hxis_floating_point_<hxremove_cv_t<T_>>::value;
173template<
typename T_>
struct hxis_integral_ :
public hxfalse_t { };
174template<>
struct hxis_integral_<bool> :
public hxtrue_t { };
175template<>
struct hxis_integral_<char> :
public hxtrue_t { };
176template<>
struct hxis_integral_<signed char> :
public hxtrue_t { };
177template<>
struct hxis_integral_<unsigned char> :
public hxtrue_t { };
178template<>
struct hxis_integral_<wchar_t> :
public hxtrue_t { };
179template<>
struct hxis_integral_<char16_t> :
public hxtrue_t { };
180template<>
struct hxis_integral_<char32_t> :
public hxtrue_t { };
181#if HX_CPLUSPLUS >= 202002L
182template<>
struct hxis_integral_<char8_t> :
public hxtrue_t { };
184template<>
struct hxis_integral_<short> :
public hxtrue_t { };
185template<>
struct hxis_integral_<unsigned short> :
public hxtrue_t { };
186template<>
struct hxis_integral_<int> :
public hxtrue_t { };
187template<>
struct hxis_integral_<unsigned int> :
public hxtrue_t { };
188template<>
struct hxis_integral_<long> :
public hxtrue_t { };
189template<>
struct hxis_integral_<unsigned long> :
public hxtrue_t { };
190template<>
struct hxis_integral_<long long> :
public hxtrue_t { };
191template<>
struct hxis_integral_<unsigned long long> :
public hxtrue_t { };
197 return hxis_integral_<hxremove_cv_t<T_>>::value;
201template<
typename T_>
struct hxis_lvalue_reference_ :
public hxfalse_t { };
202template<
typename T_>
struct hxis_lvalue_reference_<T_&> :
public hxtrue_t { };
210template<
typename T_>
struct hxis_pointer_ :
public hxfalse_t { };
211template<
typename T_>
struct hxis_pointer_<T_*> :
public hxtrue_t { };
217 return hxis_pointer_<hxremove_cv_t<T_>>::value;
221template<
typename T_>
struct hxis_reference_ :
public hxfalse_t { };
222template<
typename T_>
struct hxis_reference_<T_&> :
public hxtrue_t { };
223template<
typename T_>
struct hxis_reference_<T_&&> :
public hxtrue_t { };
231template<
typename T_>
struct hxis_rvalue_reference_ :
public hxfalse_t { };
232template<
typename T_>
struct hxis_rvalue_reference_<T_&&> :
public hxtrue_t { };
240template<
typename A_,
typename B_>
struct hxis_same_ :
public hxfalse_t { };
241template<
typename A_>
struct hxis_same_<A_, A_> :
public hxtrue_t { };
245template<
typename A_,
typename B_>
248#if HX_CPLUSPLUS >= 202002L
254template<
typename from_t_,
typename to_t_>
256 requires requires {
static_cast<to_t_
>(from_()); };
264template<
typename from_t_,
typename to_t_>
269template<
typename T_>
struct hxis_void_ :
public hxfalse_t { };
270template<>
struct hxis_void_<void> :
public hxtrue_t { };
276 return hxis_void_<hxremove_cv_t<T_>>::value;
280template<
typename T_>
struct hxrestrict_t_ {
using type = T_; };
281template<
typename T_>
struct hxrestrict_t_<T_*> {
using type = T_*
hxrestrict; };
282template<
typename T_>
struct hxrestrict_t_<T_*
const> {
using type = T_*
const hxrestrict; };
287template<
typename T_>
using hxrestrict_t =
typename hxrestrict_t_<T_>::type;
294 return ((
static_cast<unsigned char>(ch_) - 0x21u) < 0x5eu)
295 || ((
static_cast<unsigned char>(ch_) & 0x80u) != 0u);
304 return ch_ ==
' ' || (
static_cast<unsigned char>(ch_) - 0x09u) < 0x05u;
314 unsigned long index_ = 0ul;
315 ::_BitScanReverse(&index_, i_);
316 return static_cast<int>(index_);
317#elif defined __GNUC__ || defined __clang__
318 return 31 - __builtin_clz(i_);
320 float f_ =
static_cast<float>(i_);
321 uint32_t bits_ = 0u; ::memcpy(&bits_, &f_,
sizeof f_);
322 return static_cast<int>((bits_ >> 23) & 0xffu) - 127;
338#if HX_CPLUSPLUS >= 201402L
339 hxassertf(!(maximum_ < minimum_),
"bad_span inversion");
341 return (x_ < minimum_) ? minimum_ : ((maximum_ < x_) ? maximum_ : x_);
355 return static_cast<T_&&
>(x_);
363 return static_cast<T_&&
>(x_);
367template<
typename value_t_>
369template<
typename value_t_>
371template<
typename value_t_>
373template<
typename value_t_>
376template<
typename like_t_,
typename value_t_>
377using hxforward_like_t_ =
decltype(hxforward_like_result_(
379 hxis_lvalue_reference_<like_t_>(),
386template<
typename like_t_,
typename value_t_>
388 return static_cast<hxforward_like_t_<like_t_, value_t_>
>(value_);
428 ::memcpy(t_, &y_,
sizeof x_);
429 ::memcpy(
static_cast<void*
>(&y_), &x_,
sizeof x_);
430 ::memcpy(
static_cast<void*
>(&x_), t_,
sizeof x_);
440#define hxsize(x_) (sizeof(x_) / sizeof(x_)[0])
445#define hxabs(x_) ((x_) < 0 ? (0 - (x_)) : (x_))
452#define hxclamp(x_, minimum_, maximum_) \
453 ((x_) < (minimum_) ? (minimum_) : ((maximum_) < (x_) ? (maximum_) : (x_)))
459#define hxmax(x_, y_) ((y_) < (x_) ? (x_) : (y_))
465#define hxmin(x_, y_) ((x_) < (y_) ? (x_) : (y_))
472#define hxswap_memcpy(x_,y_) do { \
473 char t_[sizeof(x_) == sizeof(y_) ? (int)sizeof(x_) : -1]; \
474 memcpy(t_, &(y_), sizeof(x_)); \
475 memcpy(&(y_), &(x_), sizeof(x_)); \
476 memcpy(&(x_), t_, sizeof(x_)); } while(0)
hxnil_t - A class that will only convert to a null T pointer or a null hxhandle_t.
Definition hxutility.h:57
hxconvertible_to - A concept that requires one type to be convertible to another.
Definition hxutility.h:255
hxsame_as - A concept that requires two types to be the same.
Definition hxutility.h:265
#define hxinline
hxinline - Force a function to be inlined into its callers.
Definition hxsettings.h:125
#define hxrestrict
hxrestrict - A pointer attribute indicating that for the lifetime of that pointer,...
Definition hxsettings.h:75
#define hxinline_constexpr
hxinline_constexpr - Enables C++17 compatable "inline constexpr" usage for variables so they can be e...
Definition hxsettings.h:275
#define hxattr_nonnull(...)
hxattr_nonnull - Indicates that a function has args that should not be null.
Definition hxsettings.h:106
#define hxattr_nodiscard
hxattr_nodiscard - Indicates the caller should not discard the return value.
Definition hxsettings.h:98
#define hxattr_cold
hxattr_cold - Optimize a function for size.
Definition hxsettings.h:86
#define hxconstexpr
hxconstexpr - Enables C++23 compatable constexpr usage for functions as that has support for destruct...
Definition hxsettings.h:266
void hxhex_view(const void *address_, size_t bytes_, bool pretty_)
hxhex_view - Prints an array of bytes formatted in hexadecimal.
constexpr bool hxisgraph(char ch_)
hxisgraph - Implements standard isgraph for a locale where all non-ASCII characters are considered gr...
Definition hxutility.h:293
constexpr bool hxis_same(void)
hxis_same<A, B> - Implements std::is_same.
Definition hxutility.h:246
typename hxremove_cv_< T >::type hxremove_cv_t
hxremove_cv_t - Removes const and volatile from a type.
Definition hxutility.h:79
typename hxrestrict_t_< T >::type hxrestrict_t
hxrestrict_t - Adds the __restrict keyword to C++ pointers.
Definition hxutility.h:287
constexpr void hxswap(T &x_, T &y_)
hxswap - Exchanges the contents of x and y using a temporary.
Definition hxutility.h:414
constexpr T && hxforward(hxremove_reference_t< T > &&x_)
hxforward - Implements std::forward.
Definition hxutility.h:353
constexpr bool hxis_rvalue_reference(void)
hxis_rvalue_reference<T> - Implements std::is_rvalue_reference.
Definition hxutility.h:237
constexpr T hxabs(T x_)
hxabs - Returns the absolute value of x using a < comparison.
Definition hxutility.h:329
void hxswap_memcpy(T &x_, T &y_)
hxswap_memcpy - Exchanges the contents of x and y using memcpy and a stack temporary.
Definition hxutility.h:426
hxremove_cv_t< hxremove_reference_t< T > > hxremove_cvref_t
hxremove_cvref_t<T> - Returns T with const, volatile, and references removed.
Definition hxutility.h:103
constexpr bool hxis_lvalue_reference(void)
hxis_lvalue_reference<T> - Implements std::is_lvalue_reference.
Definition hxutility.h:207
constexpr bool hxis_array(void)
hxis_array<T> - Implements std::is_array.
Definition hxutility.h:148
constexpr bool hxis_floating_point(void)
hxis_floating_point<T> - Implements std::is_floating_point.
Definition hxutility.h:168
constexpr T hxclamp(T x_, T minimum_, T maximum_)
hxclamp - Returns x clamped between the minimum and maximum using < comparisons.
Definition hxutility.h:337
constexpr T hxmax(T x_, T y_)
hxmax - Returns the maximum value of x and y using a < comparison.
Definition hxutility.h:395
T && hxdeclval(void) noexcept
hxdeclval - Implements std::declval.
constexpr T hxmin(T x_, T y_)
hxmin - Returns the minimum value of x and y using a < comparison.
Definition hxutility.h:401
constexpr bool hxis_reference(void)
hxis_reference<T> - Implements std::is_reference.
Definition hxutility.h:228
constexpr hxnil_t hxnil
hxnil - An instance of hxnil_t useful as a shorthand.
Definition hxutility.h:67
constexpr bool hxbinds_directly(void)
hxbinds_directly<T, U> - Returns true when an lvalue of type U binds to T& without creating a tempora...
Definition hxutility.h:138
constexpr bool hxisspace(char ch_)
hxisspace - Implements standard isspace for a locale where all non-ASCII characters are considered gr...
Definition hxutility.h:303
constexpr hxremove_reference_t< T > && hxmove(T &&t_)
hxmove - Implements std::move.
Definition hxutility.h:407
constexpr bool hxis_integral(void)
hxis_integral<T> - Implements std::is_integral.
Definition hxutility.h:196
constexpr bool hxis_pointer(void)
hxis_pointer<T> - Implements std::is_pointer.
Definition hxutility.h:216
constexpr hxforward_like_t_< like_t_, value_t_ > hxforward_like(value_t_ &value_)
hxforward_like<T> - Returns value with the constness and value category of T.
Definition hxutility.h:387
typename hxremove_reference_< T >::type hxremove_reference_t
hxremove_reference_t<T> - Returns T with references removed.
Definition hxutility.h:99
constexpr bool hxis_void(void)
hxis_void<T> - Implements std::is_void.
Definition hxutility.h:275
constexpr bool hxis_const(void)
hxis_const<T> - Implements std::is_const.
Definition hxutility.h:157
HX_C_END_ HX_NS_BEGIN_ constexpr hxsize_t hxsize(T(&)[N_])
hxsize - Returns the size of a C array.
Definition hxutility.h:41
typename hxremove_pointer_< T >::type hxremove_pointer_t
hxremove_pointer_t<T> - Returns T with one pointer level removed.
Definition hxutility.h:90
HX_C_BEGIN_ void hxfloat_view(const float *address_, size_t size_)
hxfloat_view - Prints an array of floating point values.
int hxlog2i(uint32_t i_)
hxlog2i - Returns log2(n) as an integer which is the power of 2 of the largest bit in n.
Definition hxutility.h:312
Provides core macros, memory management and feature detection.
#define hxassertf(x_,...)
hxassertf(bool x, ...) - Logs an error and terminates execution if x is false.
Definition libhatchet.h:101
ptrdiff_t hxsize_t
hxsize_t - A signed size type, same as ssize_t or ptrdiff_t.
Definition libhatchet.h:207
hxfalse_t - Implements std::false_type.
Definition hxutility.h:112
static constexpr bool value
Definition hxutility.h:112
hxtrue_t - Implements std::true_type.
Definition hxutility.h:110
static constexpr bool value
Definition hxutility.h:110