xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::tools Namespace Reference

Tools and utilities. More...

Namespaces

namespace  byteSwap
 
namespace  deprecated
 

Classes

class  Defer
 A class that executes a callable at destruct time. More...
 
class  DeferThrowing
 A class that executes a callable at destruct time, catching exceptions if necessary. More...
 
class  DisableCopy
 A class that can be neither copied nor moved. More...
 
class  Hash
 A hash object with extended functionality. More...
 
struct  IsArithmetic
 Determines if a type is an arithmetic type, but not a bool or a special character type. More...
 
struct  IsBool
 Determines if a type is a Boolean type. More...
 
struct  IsCharType
 Determines if a type is a special character type. More...
 
struct  IsIeeeFloatingPoint
 Determines if a type is an IEEE floating point. More...
 
struct  IsIntegral
 Determines if a type is an integral type, but not a bool or a special character type. More...
 
struct  IsNothrowStringViewable
 Determines if a type can be converted to a string view without throwing exceptions. More...
 
struct  IsNothrowStringViewConstructible
 Determines if a type can be constructed from a string view without throwing exceptions. More...
 
struct  IsSame
 Determines if two types are the same, without taking into account qualifiers or references. More...
 
struct  IsStringType
 Determines if a type is a specialization of std::basic_string. More...
 
struct  IsStringViewable
 Determines if a type can be converted to a string view. More...
 
struct  IsStringViewConstructible
 Determines if a type can be constructed from a string view. More...
 
struct  IsStringViewType
 Determines if a type is a specialization of std::basic_string_view. More...
 
struct  NotCopyMove
 Checks whether a parameter pack doesn't consist of a single element with a specific type. More...
 
struct  ParameterPack
 A marker for a pack of parameters. More...
 
class  Unique
 A class that can be moved but not copied. More...
 
class  UnownedPointer
 A non-owning pointer that is interface compatible with std::unique_ptr. More...
 
class  UnownedPointer< Element[], Deleter >
 Template specialization of UnownedPointer for array types. More...
 

Concepts

concept  Integral
 Determines if a type is an integral type, but not a bool or a special character type.
 
concept  SignedIntegral
 Determines if a type is a signed integral type, but not a bool or a special character type.
 
concept  UnsignedIntegral
 Determines if a type is an integral type, but not a bool or a special character type.
 
concept  Arithmetic
 Determines if a type is an arithmetic type, but not a bool or a special character type.
 
concept  IeeeFloatingPoint
 A concept describing an IEEE floating point.
 
concept  Bool
 Determines if a type is a Boolean type.
 
concept  CharType
 Determines if a type is a special character type.
 
concept  StringType
 Determines if a type is a specialization of std::basic_string.
 
concept  StringViewType
 Determines if a type is a specialization of std::basic_string_view.
 
concept  StringViewable
 Determines if a type can be converted to a string view.
 
concept  StringViewConstructible
 Determines if a type can be constructed from a string view.
 
concept  SameAs
 Determines if two types are the same, without taking into account qualifiers or references.
 
concept  OneOf
 Determines if a type is one of a list of allowed types.
 
concept  Singleton
 A concept used for singleton classes.
 
concept  NullablePointer
 A concept for pointers that can be nulled.
 
concept  Allocator
 A concept for pointers that can be nulled.
 
concept  StdHashable
 This concept checks whether a class has a proper specialization for std::hash.
 

Typedefs

template<typename Key , typename Value , typename Allocator = std::allocator<std::pair<const Key, Value>>>
using unordered_map = std::unordered_map< Key, Value, Hash, std::equal_to<>, Allocator >
 Type alias for a hash table that uses xentara::utils::tools::hash as hash and generic std::equal_to<> as key compare.
 
template<typename Key , typename Allocator = std::allocator<Key>>
using unordered_set = std::unordered_set< Key, Hash, std::equal_to<>, Allocator >
 Type alias for a hash table based set that uses xentara::utils::tools::hash as hash and generic std::equal_to<> as key compare.
 
template<typename Key , typename Value , typename Allocator = std::allocator<std::pair<const Key, Value>>>
using unordered_multimap = std::unordered_multimap< Key, Value, Hash, std::equal_to<>, Allocator >
 Type alias for a multi-hash table that uses xentara::utils::tools::hash as hash and generic std::equal_to<> as key compare.
 
template<typename Key , typename Allocator = std::allocator<Key>>
using unordered_multiset = std::unordered_multiset< Key, Hash, std::equal_to<>, Allocator >
 Type alias for a hash table based multi-set that uses xentara::utils::tools::hash as hash and generic std::equal_to<> as key compare.
 
template<typename Key , typename Value , typename Allocator = std::allocator<std::pair<const Key, Value>>>
using map = std::map< Key, Value, std::less<>, Allocator >
 Type alias for a hash table that uses xentara::utils::tools::hash as hash and generic std::less<> as key compare.
 
template<typename Key , typename Allocator = std::allocator<Key>>
using set = std::set< Key, std::less<>, Allocator >
 Type alias for a hash table based set that uses xentara::utils::tools::hash as hash and generic std::less<> as key compare.
 
template<typename Key , typename Value , typename Allocator = std::allocator<std::pair<const Key, Value>>>
using multimap = std::multimap< Key, Value, std::less<>, Allocator >
 Type alias for a multi-hash table that uses xentara::utils::tools::hash as hash and generic std::less<> as key compare.
 
template<typename Key , typename Allocator = std::allocator<Key>>
using multiset = std::multiset< Key, std::less<>, Allocator >
 Type alias for a hash table based multi-set that uses xentara::utils::tools::hash as hash and generic std::less<> as key compare.
 
template<std::size_t kSize>
using IntegerWithSize = __sized_integer_type__< kSize >
 A template that can be used to find an integer type with a certain size.
 
template<std::size_t kSize>
using UnsignedIntegerWithSize = __sized_unsigned_integer_type__< kSize >
 A template that can be used to find an unsigned integer type with a certain size.
 
template<std::size_t kSize>
using ExtendedIntegerWithSize = __sized_extended_integer_type__< kSize >
 A template that can be used to find a possibly extended integer type with a certain size.
 
template<std::size_t kSize>
using ExtendedUnsignedIntegerWithSize = __sized_extended_unsigned_integer_type__< kSize >
 A template that can be used to find a possibly extended unsigned integer type with a certain size.
 
template<typename Type >
using StringViewableCharType = __string_viewable_char_type__< Type >
 A template that can be used to find the character type of the string view that a type can be converted to.
 
template<typename Type >
using StringViewableViewType = std::basic_string_view< StringViewableCharType< Type > >
 A template that can be used to find the string view type that a type can be converted to.
 
template<typename Type >
using StringViewConstructibleCharType = __string_view_constructible_char_type__< Type >
 A template that can be used to find the character type of the string view that a type can be constructed from.
 
template<typename Type >
using StringViewConstructibleViewType = std::basic_string_view< StringViewConstructibleCharType< Type > >
 A template that can be used to find the string view type that a type can be constructed from.
 

Functions

template<typename To , typename From >
requires (sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> && std::is_trivially_copyable_v<To>)
constexpr auto bit_cast (const From &from) noexcept -> To
 Replacement for std::bit_cast on systems where it is missing.
 
template<typename Type , typename... PackTypes>
constexpr auto countOfType () noexcept -> std::size_t
 Returns the number of times a type appears in a parameter pack.
 
template<typename Type , typename... PackTypes>
constexpr auto get (PackTypes &&... pack) noexcept -> decltype(auto)
 Gets the first member of a certain type from a parameter pack.
 
template<typename Type , auto kFallback, typename... PackTypes>
constexpr auto getOr (PackTypes &&... pack) noexcept -> decltype(auto)
 Gets the first value of a certain type from a parameter pack.
 
template<typename Type , typename... PackTypes>
constexpr auto indexOfType () noexcept -> std::size_t
 Returns the index of a type within a parameter pack.
 
auto unreachable () -> void
 This is a dummy function that lets the compiler that this part of the code cannot be reached.
 
template<typename Visitor , typename... Values>
constexpr auto visit (Visitor &&visitor, Values &&... values) -> void
 Executes a callable visitor for a series of values.
 
template<typename Visitor , typename Tuple >
requires requires { std::tuple_size<std::remove_reference_t<Tuple>>::value; }
constexpr auto visitTuple (Visitor &&visitor, Tuple &&tuple) -> void
 Executes a callable visitor for all the members of a tuple.
 

Variables

constexpr bool kHasConstexprBitCast
 Constant describing whether bit_cast is constexpr.
 
template<typename >
constexpr bool kAlwaysFalse
 A value of false.
 
template<typename... Parameters>
constexpr ParameterPack< Parameters... > kParameterPack
 A marker for a pack of parameters.
 
template<typename Type , typename... ParameterPack>
constexpr bool kNotCopyMove
 Checks whether a parameter pack contains a single element with a specific type.
 

Detailed Description

Tools and utilities.

This namespace contains various tools and utilities, mainly for template meta programming.

Typedef Documentation

◆ ExtendedIntegerWithSize

template<std::size_t kSize>
using xentara::utils::tools::ExtendedIntegerWithSize = typedef __sized_extended_integer_type__<kSize>

A template that can be used to find a possibly extended integer type with a certain size.

This type alias is equivalent to IntegerWithSize, except that it may return extended integer types like *__int128*.

If there is no integer or extended integer type with the specified size, this type is not defined.

◆ ExtendedUnsignedIntegerWithSize

template<std::size_t kSize>
using xentara::utils::tools::ExtendedUnsignedIntegerWithSize = typedef __sized_extended_unsigned_integer_type__<kSize>

A template that can be used to find a possibly extended unsigned integer type with a certain size.

This type alias is equivalent to UnsignedIntegerWithSize, except that it may return extended integer types like unsigned __int128.

If there is no unsigned integer or extended unsigned integer type with the specified size, this type is not defined.

◆ IntegerWithSize

template<std::size_t kSize>
using xentara::utils::tools::IntegerWithSize = typedef __sized_integer_type__<kSize>

A template that can be used to find an integer type with a certain size.

If there is no integer type with the specified size, this type is not defined.

◆ map

template<typename Key , typename Value , typename Allocator = std::allocator<std::pair<const Key, Value>>>
using xentara::utils::tools::map = typedef std::map<Key, Value, std::less<>, Allocator>

Type alias for a hash table that uses xentara::utils::tools::hash as hash and generic std::less<> as key compare.

◆ multimap

template<typename Key , typename Value , typename Allocator = std::allocator<std::pair<const Key, Value>>>
using xentara::utils::tools::multimap = typedef std::multimap<Key, Value, std::less<>, Allocator>

Type alias for a multi-hash table that uses xentara::utils::tools::hash as hash and generic std::less<> as key compare.

◆ multiset

template<typename Key , typename Allocator = std::allocator<Key>>
using xentara::utils::tools::multiset = typedef std::multiset<Key, std::less<>, Allocator>

Type alias for a hash table based multi-set that uses xentara::utils::tools::hash as hash and generic std::less<> as key compare.

◆ set

template<typename Key , typename Allocator = std::allocator<Key>>
using xentara::utils::tools::set = typedef std::set<Key, std::less<>, Allocator>

Type alias for a hash table based set that uses xentara::utils::tools::hash as hash and generic std::less<> as key compare.

◆ StringViewableCharType

template<typename Type >
using xentara::utils::tools::StringViewableCharType = typedef __string_viewable_char_type__<Type>

A template that can be used to find the character type of the string view that a type can be converted to.

If the given type cannot be converted to a string view, or if it can be converted to multiple types of string view, this type is not defined.

◆ StringViewableViewType

A template that can be used to find the string view type that a type can be converted to.

If the given type cannot be converted to a string view, or if it can be converted to multiple types of string view, this type is not defined.

◆ StringViewConstructibleCharType

template<typename Type >
using xentara::utils::tools::StringViewConstructibleCharType = typedef __string_view_constructible_char_type__<Type>

A template that can be used to find the character type of the string view that a type can be constructed from.

If the given type cannot be constructed from a string view, or if it can be constructed from multiple types of string view, this type is not defined.

◆ StringViewConstructibleViewType

A template that can be used to find the string view type that a type can be constructed from.

If the given type cannot be constructed from a string view, or if it can be constructed from multiple types of string view, this type is not defined.

◆ unordered_map

template<typename Key , typename Value , typename Allocator = std::allocator<std::pair<const Key, Value>>>
using xentara::utils::tools::unordered_map = typedef std::unordered_map<Key, Value, Hash, std::equal_to<>, Allocator>

Type alias for a hash table that uses xentara::utils::tools::hash as hash and generic std::equal_to<> as key compare.

◆ unordered_multimap

template<typename Key , typename Value , typename Allocator = std::allocator<std::pair<const Key, Value>>>
using xentara::utils::tools::unordered_multimap = typedef std::unordered_multimap<Key, Value, Hash, std::equal_to<>, Allocator>

Type alias for a multi-hash table that uses xentara::utils::tools::hash as hash and generic std::equal_to<> as key compare.

◆ unordered_multiset

template<typename Key , typename Allocator = std::allocator<Key>>
using xentara::utils::tools::unordered_multiset = typedef std::unordered_multiset<Key, Hash, std::equal_to<>, Allocator>

Type alias for a hash table based multi-set that uses xentara::utils::tools::hash as hash and generic std::equal_to<> as key compare.

◆ unordered_set

template<typename Key , typename Allocator = std::allocator<Key>>
using xentara::utils::tools::unordered_set = typedef std::unordered_set<Key, Hash, std::equal_to<>, Allocator>

Type alias for a hash table based set that uses xentara::utils::tools::hash as hash and generic std::equal_to<> as key compare.

◆ UnsignedIntegerWithSize

template<std::size_t kSize>
using xentara::utils::tools::UnsignedIntegerWithSize = typedef __sized_unsigned_integer_type__<kSize>

A template that can be used to find an unsigned integer type with a certain size.

If there is no unsigned integer type with the specified size, this type is not defined.

Function Documentation

◆ bit_cast()

template<typename To , typename From >
requires (sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> && std::is_trivially_copyable_v<To>)
constexpr auto xentara::utils::tools::bit_cast ( const From &  from) -> To
constexprnoexcept

Replacement for std::bit_cast on systems where it is missing.

This is an implementation of std::bit_cast for platforms on which is is missing. On platforms that supply an std::bit_cast, this is simply a using-directive for std::bit_cast.

Attention
When using GCC prior to version 11, it is not possible to implement a constexpr version of std::bit_cast. When using GCC prior to version 11, this function is not constexpr. Use the constant kHasConstexprBitCast to determine whether this function is constexpr ot not.

◆ countOfType()

template<typename Type , typename... PackTypes>
constexpr auto xentara::utils::tools::countOfType ( ) -> std::size_t
constexprnoexcept

Returns the number of times a type appears in a parameter pack.

This function counts how many times a parameter appears in a parameter pack. The type is considered matching if std::remove_cvref_t<PackType> is the same as the given type.

Template Parameters
TypeThe type to search for
...PackTypesThe types in the parameter pack
Returns
The number of matching occurrences.

◆ get()

template<typename Type , typename... PackTypes>
constexpr auto xentara::utils::tools::get ( PackTypes &&...  pack) -> decltype(auto)
constexprnoexcept

Gets the first member of a certain type from a parameter pack.

This function extracts the first parameter whose type matches that in a parameter pack. The type is considered matching if std::remove_cvref_t<PackType> is the same as the given type.

Template Parameters
TypeThe desired type.
...PackTypesThe types in the parameter pack. Must contain at least one instance of Type.
Parameters
...packThe parameter pack
Returns
A reference to the corresponding member of the parameter pack. The exact return type is the same as the return type of std::forward<PackType>(member) for the matching member.

◆ getOr()

template<typename Type , auto kFallback, typename... PackTypes>
constexpr auto xentara::utils::tools::getOr ( PackTypes &&...  pack) -> decltype(auto)
constexprnoexcept

Gets the first value of a certain type from a parameter pack.

This function extracts the first value whose type matches that in a parameter pack. The type is considered matching if std::remove_cvref_t<PackType> is the same as the given type.

This function returns a fallback value if none of the pack does not contain any suitable types. The fallback value is contained in the template parameter kFallback. kFallback must be a value that can be implicitly converted to Type.

Not all C++ types can be used as template parameters. To provide a fallback value of a type that is not suitable for use as a template parameter, you can use the following workaround:

struct FallbackHelper
{
constexpr operator Type() const noexcept
{
return ...;
}
};
return tools::getOr<Type, FallbackHelper{}>(...);
constexpr auto getOr(PackTypes &&... pack) noexcept -> decltype(auto)
Gets the first value of a certain type from a parameter pack.
Definition get.hpp:127
Template Parameters
TypeThe desired type.
kFallbackThe value to return if the pack does not contain any suitable types.
...PackTypesThe types in the parameter pack
Parameters
...packThe parameter pack
Returns
A reference to the corresponding member of the parameter pack, or the value kFallback if none was found. If a suitable member is found, the exact return type is the same as the return type of std::forward<PackType>(member) for the matching member. If a suitable member is not found, the return type is decltype(kFallback).

◆ indexOfType()

template<typename Type , typename... PackTypes>
constexpr auto xentara::utils::tools::indexOfType ( ) -> std::size_t
constexprnoexcept

Returns the index of a type within a parameter pack.

This function gets the index of a type within a parameter pack. The type is considered matching if std::remove_cvref_t<PackType> is the same as the given type.

Template Parameters
TypeThe type to search for
...PackTypesThe types in the parameter pack
Returns
The index of the type.

◆ unreachable()

auto xentara::utils::tools::unreachable ( ) -> void

This is a dummy function that lets the compiler that this part of the code cannot be reached.

◆ visit()

template<typename Visitor , typename... Values>
constexpr auto xentara::utils::tools::visit ( Visitor &&  visitor,
Values &&...  values 
) -> void
constexpr

Executes a callable visitor for a series of values.

Parameters
visitorThe visitor
...valuesThe values

◆ visitTuple()

template<typename Visitor , typename Tuple >
requires requires { std::tuple_size<std::remove_reference_t<Tuple>>::value; }
constexpr auto xentara::utils::tools::visitTuple ( Visitor &&  visitor,
Tuple &&  tuple 
) -> void
constexpr

Executes a callable visitor for all the members of a tuple.

Parameters
visitorThe visitor
tupleThe tuple

Variable Documentation

◆ kAlwaysFalse

template<typename >
constexpr bool xentara::utils::tools::kAlwaysFalse
constexpr

A value of false.

This constant can be used to trigger static asserts unconditionally in template instantiations where the assert needs to be always false, but dependend on a parameter.

◆ kHasConstexprBitCast

constexpr bool xentara::utils::tools::kHasConstexprBitCast
constexpr

Constant describing whether bit_cast is constexpr.

◆ kNotCopyMove

template<typename Type , typename... ParameterPack>
constexpr bool xentara::utils::tools::kNotCopyMove
constexpr

Checks whether a parameter pack contains a single element with a specific type.

This value checks whether a parameter pack doesn't consist of exactly one parameter that is a possibly CV-qualified version of a certain type, or a possibly CV-qualified reference to that type. This can be used to prevent templated constructors from qualifying as copy and/or move constructors.

Template Parameters
TypeThe type to check for
ParameterPackThe parameter pack

◆ kParameterPack

template<typename... Parameters>
constexpr ParameterPack<Parameters...> xentara::utils::tools::kParameterPack
constexpr

A marker for a pack of parameters.

This is an empty object that can be used in meta programming to represent a parameter pack. It is used in a similar way to std::in_place_type: it can be passed to a function to select an overload that uses a certain pack of parameter templates