xentara-utils v1.0
Xentara utilities library
xentara::utils::tools Namespace Reference

Tools and utilities. More...

Namespaces

namespace  byteSwap
 

Classes

class  Defer
 A class that executes a callable at destruct time. More...
 
class  DisableCopy
 A class that can be neither copied nor moved. More...
 
class  Hash
 A hash object with extended functionality. More...
 
struct  IeeeFloatingPointTraits
 Information about an IEEE floating point type. 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  IsSame
 Determines if two types are the same, without taking into account qualifiers or references. 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...
 

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  Bool
 Determines if a type is a Boolean type.
 
concept  CharType
 Determines if a type is a special character type.
 
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.
 
concept  IeeeFloatingPoint
 A concept describing an IEEE floating point.
 

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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
template<std::size_t kSize>
using IntegerWithSize = typename detail::SizedTypeFinder< kSize, std::int8_t, std::int16_t, std::int32_t, std::int64_t, std::intmax_t >::Type
 A template that can be used to find an integer type with a certain size. More...
 
template<std::size_t kSize>
using UnsignedIntegerWithSize = typename detail::SizedTypeFinder< kSize, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, std::uintmax_t >::Type
 A template that can be used to find an unsigned integer type with a certain size. More...
 
template<std::size_t kSize>
using ExtendedIntegerWithSize = typename detail::SizedTypeFinder< kSize, std::int8_t, std::int16_t, std::int32_t, std::int64_t, std::intmax_t >::Type
 A template that can be used to find a possibly extended integer type with a certain size. More...
 
template<std::size_t kSize>
using ExtendedUnsignedIntegerWithSize = typename detail::SizedTypeFinder< kSize, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, std::uintmax_t >::Type
 A template that can be used to find a possibly extended unsigned integer type with a certain size. More...
 

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. More...
 
template<std::integral Target, std::integral Source>
auto clamp (Source source)
 Converts an integer to a new type using clamping. More...
 
template<typename Type , typename... PackTypes>
constexpr auto countOfType () noexcept -> std::size_t
 Returns the number of times a type appears in a parameter pack. More...
 
template<typename Type , typename... PackTypes>
constexpr auto get (PackTypes &&... pack) noexcept -> Type
 Gets the first value of a certain type from a parameter pack. More...
 
template<typename Type , auto kFallback, typename... PackTypes>
constexpr auto getOr (PackTypes &&... pack) noexcept -> Type
 Gets the first value of a certain type from a parameter pack. More...
 
template<typename Type , typename... PackTypes>
constexpr auto indexOfType () noexcept -> std::size_t
 Returns the index of a type within a parameter pack. More...
 
template<typename Rep , typename Period >
auto toTimeSpec (const std::chrono::duration< Rep, Period > &duration) -> eh::Failable< std::timespec >
 Converts a duration to an std::timespec value. More...
 
template<typename Clock , typename Duration >
auto toTimeSpec (const std::chrono::time_point< Clock, Duration > &timePoint) -> eh::Failable< std::timespec >
 Converts a time point to an std::timespec value. More...
 
template<typename Visitor , typename... Values>
constexpr auto visit (Visitor &&visitor, Values &&... values) -> void
 Executes a callable visitor for a series of values. More...
 
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. More...
 

Variables

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

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 typename detail::SizedTypeFinder<kSize, std::int8_t, std::int16_t, std::int32_t, std::int64_t, std::intmax_t >::Type

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 typename detail::SizedTypeFinder<kSize, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, std::uintmax_t >::Type

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 typename detail::SizedTypeFinder<kSize, std::int8_t, std::int16_t, std::int32_t, std::int64_t, std::intmax_t>::Type

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.

◆ 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 typename detail::SizedTypeFinder<kSize, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, std::uintmax_t>::Type

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.

◆ clamp()

template<std::integral Target, std::integral Source>
auto xentara::utils::tools::clamp ( Source  source)

Converts an integer to a new type using clamping.

Converts an integer to a new type. If the value lies outside the range of the new type, the closest possible value is returned.

Parameters
sourceThe source integer
Returns
The closest possible target integer

◆ 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) -> Type
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.

Template Parameters
TypeThe desired type.
...PackTypesThe types in the parameter pack. Must contain at least one instance of Type.
Parameters
...packThe parameter pack
Returns
The value

◆ getOr()

template<typename Type , auto kFallback, typename... PackTypes>
constexpr auto xentara::utils::tools::getOr ( PackTypes &&...  pack) -> Type
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 -> Type
Gets the first value of a certain type from a parameter pack.
Definition: get.hpp:124
Template Parameters
TypeThe desired type.
kFallbackThe value to return if the pack does not contain any suitable types. Must be implicitly convertible to Type.
...PackTypesThe types in the parameter pack
Parameters
...packThe parameter pack
Returns
The value, or kFallback if none was found.

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

◆ toTimeSpec() [1/2]

template<typename Rep , typename Period >
auto xentara::utils::tools::toTimeSpec ( const std::chrono::duration< Rep, Period > &  duration) -> eh::Failable<std::timespec>

Converts a duration to an std::timespec value.

◆ toTimeSpec() [2/2]

template<typename Clock , typename Duration >
auto xentara::utils::tools::toTimeSpec ( const std::chrono::time_point< Clock, Duration > &  timePoint) -> eh::Failable<std::timespec>

Converts a time point to an std::timespec value.

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

◆ kIsBool

template<typename Type >
constexpr bool xentara::utils::tools::kIsBool
constexpr

Determines if a type is a Boolean type.

This value is true if the type is possibly CV-qualified bool.

◆ kIsCharType

template<typename Type >
constexpr bool xentara::utils::tools::kIsCharType
constexpr

Determines if a type is a special character type.

This value is true if the type is possibly CV-qualified char, char8_t, char16_t, char32_t, or wchar_t.

◆ 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