sparrow 0.9.0
Loading...
Searching...
No Matches
sparrow::mpl Namespace Reference

Namespaces

namespace  impl
 
namespace  predicate
 

Classes

struct  add_const_lvalue_reference
 Adds const and lvalue reference to a type. More...
 
struct  constify
 Conditionally adds const to a type. More...
 
struct  constify< T &, is_const >
 Specialization for reference types. More...
 
struct  ct_type_predicate_to_callable
 
struct  dependent_false
 Workaround to replace static_assert(false) in template code. More...
 
struct  excludes_copy_and_move_ctor
 Helper to exclude copy and move constructors from variadic templates. More...
 
struct  excludes_copy_and_move_ctor< CLS >
 Specialization for no arguments. More...
 
struct  excludes_copy_and_move_ctor< CLS, T >
 Specialization for single argument. More...
 
struct  is_type_instance_of
 Type trait to check if a type is an instantiation of a template. More...
 
struct  is_type_instance_of< L< T... >, U >
 Specialization for matching template instantiations. More...
 
struct  typelist
 A sequence of types used for metaprogramming operations. More...
 

Concepts

concept  any_typelist
 Concept that matches any typelist instantiation.
 
concept  type_wrapper
 Concept for template types that can wrap a single type.
 
concept  ct_type_predicate
 Concept for compile-time type predicates.
 
concept  callable_type_predicate
 Concept for callable type predicates.
 
concept  constant_iterator
 Concept for constant iterators.
 
concept  constant_range
 Concept for constant ranges.
 
concept  bool_convertible_range
 Concept for ranges whose elements are convertible to bool.
 
concept  boolean_like
 Concept for boolean-like types.
 
concept  convertible_ranges
 Concept for convertible range types.
 
concept  unique_ptr
 Concept for unique_ptr instances.
 
concept  unique_ptr_or_derived
 Concept for unique_ptr or derived types.
 
concept  shared_ptr
 Concept for shared_ptr instances.
 
concept  shared_ptr_or_derived
 Concept for shared_ptr or derived types.
 
concept  smart_ptr
 Concept for any smart pointer type.
 
concept  smart_ptr_and_derived
 Concept for smart pointers and derived types.
 
concept  testable
 Concept for testable types in boolean contexts.
 
concept  T_matches_qualifier_if_Y_is
 Concept for matching qualifier requirements.
 
concept  iterator_of_type
 Concept for iterators of a specific value type.
 
concept  char_like
 Concept for character-like types.
 
concept  std_array
 Concept for std::array types.
 
concept  weakly_equality_comparable_with
 

Typedefs

template<class TypeList, class... Us>
using append_t = decltype(append(TypeList{}, Us{}...))
 Type alias for appending types or typelists to a given typelist.
 
template<class From, template< class... > class To>
using rename = typename impl::rename_impl<From, To>::type
 Changes the template type of a type list.
 
template<template< class > class F, class... L>
using transform = typename impl::transform_impl<F, L...>::type
 Applies a metafunction to each element of typelists.
 
template<class L1, class L2>
using merge_set = typename impl::merge_set_impl<L1, L2>::type
 Generates the union of two typelists, removing duplicates.
 
template<class L>
using unique = typename impl::unique_impl<L>::type
 Removes all duplicated types in the given typelist Example: unique<typelist<int, float, double, float, int> gives typelist<int, float, double>
 
template<class T>
using add_const_lvalue_reference_t = typename add_const_lvalue_reference<T>::type
 Convenience alias for add_const_lvalue_reference.
 
template<class T, bool is_const>
using constify_t = typename constify<T, is_const>::type
 Convenience alias for constify.
 
template<class T>
using iter_const_reference_t = std::common_reference_t<const std::iter_value_t<T>&&, std::iter_reference_t<T>>
 Computes the const reference type of an iterator.
 

Functions

template<class... Ts, class... Us>
requires (!is_type_instance_of_v<Us, typelist> && ...)
consteval auto append (typelist< Ts... >, Us...)
 Appends individual types to a typelist.
 
template<class... Ts, class... Us>
consteval auto append (typelist< Ts... >, typelist< Us... >)
 Appends two typelists together.
 
template<class... T>
constexpr std::size_t size (typelist< T... >={})
 Gets the count of types contained in a typelist.
 
template<class T, template< class > class P>
requires ct_type_predicate<P, T>
consteval bool evaluate (P< T >)
 Evaluates a compile-time template predicate.
 
template<class T, callable_type_predicate< T > P>
consteval bool evaluate (P predicate)
 Evaluates a callable type predicate.
 
template<template< class > class P>
consteval auto as_predicate ()
 
template<class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (callable_type_predicate<Predicate, T> && ...)
consteval bool any_of (L< T... >, Predicate predicate={})
 Checks if at least one type in the typelist satisfies the predicate.
 
template<template< class > class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (ct_type_predicate<Predicate, T> && ...)
consteval bool any_of (L< T... > list)
 Checks if at least one type satisfies the compile-time predicate.
 
template<class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (callable_type_predicate<Predicate, T> && ...)
consteval bool all_of (L< T... >, Predicate predicate)
 Checks if all types in the typelist satisfy the predicate.
 
template<template< class > class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (ct_type_predicate<Predicate, T> && ...)
consteval bool all_of (L< T... > list)
 Checks if all types satisfy the compile-time predicate.
 
template<class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (callable_type_predicate<Predicate, T> && ...)
consteval std::size_t find_if (L< T... >, Predicate predicate)
 Finds the index of the first type satisfying the predicate.
 
template<template< class > class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (ct_type_predicate<Predicate, T> && ...)
consteval std::size_t find_if (L< T... > list)
 Finds the index of the first type satisfying the compile-time predicate.
 
template<class TypeToFind, any_typelist L>
consteval std::size_t find (L list)
 Finds the index of a specific type in the typelist.
 
template<any_typelist L, class V>
consteval bool contains ()
 Checks if a typelist contains a specific type.
 
void unreachable ()
 Invokes undefined behavior for optimization purposes.
 

Variables

template<class T, template< class... > class U>
constexpr bool is_type_instance_of_v = is_type_instance_of<T, U>::value
 Variable template for convenient access to is_type_instance_of.
 
template<class CLS, class... ARGS>
constexpr bool excludes_copy_and_move_ctor_v = excludes_copy_and_move_ctor<CLS, ARGS...>::value
 Convenience variable template for excludes_copy_and_move_ctor.
 

Typedef Documentation

◆ add_const_lvalue_reference_t

template<class T>
using sparrow::mpl::add_const_lvalue_reference_t = typename add_const_lvalue_reference<T>::type

Convenience alias for add_const_lvalue_reference.

Template Parameters
TType to get const lvalue reference of
Postcondition
Results in const T& for most types
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 766 of file mp_utils.hpp.

◆ append_t

template<class TypeList, class... Us>
using sparrow::mpl::append_t = decltype(append(TypeList{}, Us{}...))

Type alias for appending types or typelists to a given typelist.

This template alias provides a convenient way to append one or more types or typelists to an existing typelist using the append function.

Template Parameters
TypeListThe typelist to which types will be appended
UsTypes or typelists to be appended
Precondition
TypeList must be an instance of typelist
Postcondition
Results in the typelist after appending operations
using result = append_t<typelist<int>, float, typelist<double>>;
//result is typelist<int, float, double>
decltype(append(TypeList{}, Us{}...)) append_t
Type alias for appending types or typelists to a given typelist.
Definition mp_utils.hpp:198
A sequence of types used for metaprogramming operations.
Definition mp_utils.hpp:123

Definition at line 198 of file mp_utils.hpp.

◆ constify_t

template<class T, bool is_const>
using sparrow::mpl::constify_t = typename constify<T, is_const>::type

Convenience alias for constify.

This is required since std::add_const_t<T&> is T& (not const T&).

Template Parameters
TType to conditionally const-qualify
is_constWhether to add const qualification
Postcondition
Results in const-qualified type if is_const is true
Handles reference types correctly

Definition at line 807 of file mp_utils.hpp.

◆ iter_const_reference_t

template<class T>
using sparrow::mpl::iter_const_reference_t = std::common_reference_t<const std::iter_value_t<T>&&, std::iter_reference_t<T>>

Computes the const reference type of an iterator.

This utility determines the appropriate const reference type for an iterator, ensuring proper const-correctness for iterator operations.

Template Parameters
TIterator type
Postcondition
Results in the const reference type for iterator T

Definition at line 820 of file mp_utils.hpp.

◆ merge_set

template<class L1, class L2>
using sparrow::mpl::merge_set = typename impl::merge_set_impl<L1, L2>::type

Generates the union of two typelists, removing duplicates.

This utility merges two typelists and ensures that each type appears only once in the result, maintaining the order from the first list and adding new types from the second list.

Template Parameters
L1First typelist
L2Second typelist
Postcondition
Returns typelist containing all types from L1 and L2 without duplicates
Order preserves L1 types first, then new types from L2
//Result: typelist<int, float, double>
typename impl::merge_set_impl< L1, L2 >::type merge_set
Generates the union of two typelists, removing duplicates.
Definition mp_utils.hpp:722

Definition at line 722 of file mp_utils.hpp.

◆ rename

template<class From, template< class... > class To>
using sparrow::mpl::rename = typename impl::rename_impl<From, To>::type

Changes the template type of a type list.

This utility extracts the template arguments from one template instantiation and applies them to a different template.

Template Parameters
FromSource template instantiation
ToTarget template to apply arguments to
Postcondition
Results in To<Args...> where Args are extracted from From
using result = rename<typelist<int, float>, std::variant>;
//result is std::variant<int, float>
typename impl::rename_impl< From, To >::type rename
Changes the template type of a type list.
Definition mp_utils.hpp:268

Definition at line 268 of file mp_utils.hpp.

◆ transform

template<template< class > class F, class... L>
using sparrow::mpl::transform = typename impl::transform_impl<F, L...>::type

Applies a metafunction to each element of typelists.

This template applies the metafunction F to each tuple of elements in the provided typelists and returns the corresponding result list.

Template Parameters
FMetafunction to apply
LTypelist(s) to transform
Precondition
L must be typelist-like types
Postcondition
Returns typelist with F applied to each element
//Single list transformation
//Result: typelist<int*, float*>
//Binary transformation
//Result: typelist<std::is_same<int, int>, std::is_same<float, int>>
typename impl::transform_impl< F, L... >::type transform
Applies a metafunction to each element of typelists.
Definition mp_utils.hpp:682

Definition at line 682 of file mp_utils.hpp.

◆ unique

template<class L>
using sparrow::mpl::unique = typename impl::unique_impl<L>::type

Removes all duplicated types in the given typelist Example: unique<typelist<int, float, double, float, int> gives typelist<int, float, double>

Definition at line 740 of file mp_utils.hpp.

Function Documentation

◆ all_of() [1/2]

template<template< class > class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (ct_type_predicate<Predicate, T> && ...)
bool sparrow::mpl::all_of ( L< T... > list)
nodiscardconsteval

Checks if all types satisfy the compile-time predicate.

Template Parameters
PredicateTemplate predicate to apply
LTypelist template
TTypes in the typelist
Parameters
listTypelist instance
Returns
true if all types satisfy the predicate
Precondition
L<T...> must be a typelist
Predicate must be a compile-time predicate for each type T
Postcondition
Returns true if all Predicate<T>::value are true
Returns true for empty lists

Definition at line 513 of file mp_utils.hpp.

Here is the call graph for this function:

◆ all_of() [2/2]

template<class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (callable_type_predicate<Predicate, T> && ...)
bool sparrow::mpl::all_of ( L< T... > ,
Predicate predicate )
nodiscardconsteval

Checks if all types in the typelist satisfy the predicate.

Template Parameters
PredicateCallable predicate type
LTypelist template
TTypes in the typelist
Parameters
predicatePredicate to apply
Returns
true if all types satisfy the predicate
Precondition
L<T...> must be a typelist
Predicate must be callable for each type T
Postcondition
Returns true if all evaluate<T>(predicate) are true
Returns true for empty lists

Definition at line 492 of file mp_utils.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ any_of() [1/2]

template<template< class > class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (ct_type_predicate<Predicate, T> && ...)
bool sparrow::mpl::any_of ( L< T... > list)
nodiscardconsteval

Checks if at least one type satisfies the compile-time predicate.

Template Parameters
PredicateTemplate predicate to apply
LTypelist template
TTypes in the typelist
Parameters
listTypelist instance
Returns
true if at least one type satisfies the predicate
Precondition
L<T...> must be a typelist
Predicate must be a compile-time predicate for each type T
Postcondition
Returns true if any Predicate<T>::value is true
Returns false for empty lists

Definition at line 471 of file mp_utils.hpp.

Here is the call graph for this function:

◆ any_of() [2/2]

template<class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (callable_type_predicate<Predicate, T> && ...)
bool sparrow::mpl::any_of ( L< T... > ,
Predicate predicate = {} )
nodiscardconsteval

Checks if at least one type in the typelist satisfies the predicate.

Template Parameters
PredicateCallable predicate type
LTypelist template
TTypes in the typelist
Parameters
listTypelist instance
predicatePredicate to apply (defaults to default-constructed)
Returns
true if at least one type satisfies the predicate
Precondition
L<T...> must be a typelist
Predicate must be callable for each type T
Postcondition
Returns true if any evaluate<T>(predicate) is true
Returns false for empty lists
auto is_integral = [](auto) { return std::is_integral_v<typename decltype(type)::type>; };
static_assert(any_of(typelist<int, float>{}, is_integral));
consteval bool any_of(L< T... >, Predicate predicate={})
Checks if at least one type in the typelist satisfies the predicate.
Definition mp_utils.hpp:450

Definition at line 450 of file mp_utils.hpp.

Here is the caller graph for this function:

◆ append() [1/2]

template<class... Ts, class... Us>
auto sparrow::mpl::append ( typelist< Ts... > ,
typelist< Us... >  )
consteval

Appends two typelists together.

This function takes two typelists as input and returns a new typelist that contains all the types from both input typelists in order.

Template Parameters
TsTypes in the first typelist
UsTypes in the second typelist
Parameters
list1The first typelist
list2The second typelist
Returns
New typelist containing all types from both lists
Postcondition
Returns typelist<Ts..., Us...>
auto result = append(typelist<int, float>{}, typelist<double, char>{});
//result is typelist<int, float, double, char>
consteval auto append(typelist< Ts... >, Us...)
Appends individual types to a typelist.
Definition mp_utils.hpp:149

Definition at line 174 of file mp_utils.hpp.

◆ append() [2/2]

template<class... Ts, class... Us>
requires (!is_type_instance_of_v<Us, typelist> && ...)
auto sparrow::mpl::append ( typelist< Ts... > ,
Us...  )
consteval

Appends individual types to a typelist.

This function takes a typelist and additional types as arguments, and returns a new typelist containing all the types from the original typelist followed by the additional types.

Template Parameters
TsTypes in the original typelist
UsAdditional types to be appended (must not be typelists)
Parameters
listThe original typelist
typesThe additional types to append
Returns
New typelist containing all types
Precondition
Us types must not be typelist instances
Postcondition
Returns typelist<Ts..., Us...>
auto result = append(typelist<int, float>{}, double{}, char{});
//result is typelist<int, float, double, char>

Definition at line 149 of file mp_utils.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ as_predicate()

template<template< class > class P>
auto sparrow::mpl::as_predicate ( )
consteval
Returns
A callable type-predicate object which will return P<T>::value when called with T in a type-wrapper.

Definition at line 420 of file mp_utils.hpp.

Here is the caller graph for this function:

◆ contains()

template<any_typelist L, class V>
bool sparrow::mpl::contains ( )
nodiscardconsteval

Checks if a typelist contains a specific type.

Template Parameters
LTypelist type to search in
VType to search for
Returns
true if V is found in L, false otherwise
Precondition
L must be a typelist
Postcondition
Returns true if V appears in L
Implementation avoids instantiating L for forward-declared types
static_assert(contains<typelist<int, float>, int()>);
static_assert(!contains<typelist<int, float>, double()>);
consteval bool contains()
Checks if a typelist contains a specific type.
Definition mp_utils.hpp:633

Definition at line 633 of file mp_utils.hpp.

◆ evaluate() [1/2]

template<class T, callable_type_predicate< T > P>
bool sparrow::mpl::evaluate ( P predicate)
nodiscardconsteval

Evaluates a callable type predicate.

Template Parameters
TType to evaluate
PCallable predicate type
Parameters
predicatePredicate instance
Returns
Boolean result of calling predicate with type wrapper
Precondition
P must satisfy callable_type_predicate concept for T
Postcondition
Returns result of calling predicate with appropriate type wrapper

Definition at line 371 of file mp_utils.hpp.

◆ evaluate() [2/2]

template<class T, template< class > class P>
requires ct_type_predicate<P, T>
bool sparrow::mpl::evaluate ( P< T > )
consteval

Evaluates a compile-time template predicate.

Template Parameters
TType to evaluate
PTemplate predicate to apply
Returns
Boolean result of P<T>::value
Precondition
P must satisfy ct_type_predicate concept for T
Postcondition
Returns P<T>::value

Definition at line 354 of file mp_utils.hpp.

Here is the caller graph for this function:

◆ find()

template<class TypeToFind, any_typelist L>
std::size_t sparrow::mpl::find ( L list)
nodiscardconsteval

Finds the index of a specific type in the typelist.

Template Parameters
TypeToFindType to search for
LTypelist type
Parameters
listTypelist instance
Returns
Index of TypeToFind, or size() if not found
Precondition
L must be a typelist
Postcondition
Returns index in range [0, size(L)]
Returns size(L) if TypeToFind is not in the list

Definition at line 590 of file mp_utils.hpp.

Here is the call graph for this function:

◆ find_if() [1/2]

template<template< class > class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (ct_type_predicate<Predicate, T> && ...)
std::size_t sparrow::mpl::find_if ( L< T... > list)
nodiscardconsteval

Finds the index of the first type satisfying the compile-time predicate.

Template Parameters
PredicateTemplate predicate to apply
LTypelist template
TTypes in the typelist
Parameters
listTypelist instance
Returns
Index of first matching type, or size() if not found
Precondition
L<T...> must be a typelist
Predicate must be a compile-time predicate for each type T
Postcondition
Returns index in range [0, sizeof...(T)]
Returns sizeof...(T) if no type matches

Definition at line 572 of file mp_utils.hpp.

Here is the call graph for this function:

◆ find_if() [2/2]

template<class Predicate, template< class... > class L, class... T>
requires any_typelist<L<T...>> and (callable_type_predicate<Predicate, T> && ...)
std::size_t sparrow::mpl::find_if ( L< T... > ,
Predicate predicate )
nodiscardconsteval

Finds the index of the first type satisfying the predicate.

Template Parameters
PredicateCallable predicate type
LTypelist template
TTypes in the typelist
Parameters
listTypelist instance
predicatePredicate to apply
Returns
Index of first matching type, or size() if not found
Precondition
L<T...> must be a typelist
Predicate must be callable for each type T
Postcondition
Returns index in range [0, sizeof...(T)]
Returns sizeof...(T) if no type matches

Definition at line 535 of file mp_utils.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

template<class... T>
std::size_t sparrow::mpl::size ( typelist< T... > = {})
constexpr

Gets the count of types contained in a typelist.

Template Parameters
TTypes in the typelist
Parameters
listTypelist instance (defaulted for convenience)
Returns
Number of types in the typelist
Postcondition
Returns sizeof...(T)
Result is available at compile time
constexpr auto count = size(typelist<int, float, double>{});
static_assert(count == 3);
constexpr std::size_t size(typelist< T... >={})
Gets the count of types contained in a typelist.
Definition mp_utils.hpp:216

Definition at line 216 of file mp_utils.hpp.

◆ unreachable()

void sparrow::mpl::unreachable ( )
inline

Invokes undefined behavior for optimization purposes.

This function can be used to mark code paths that should never be reached, allowing compilers to optimize away impossible branches or trap execution in debug builds.

Precondition
This function should never actually be called
Postcondition
Undefined behavior occurs if called
Note
Implementation uses compiler-specific extensions when available
Documentation based on https://en.cppreference.com/w/cpp/utility/unreachable
switch (value) {
case 1: return "one";
case 2: return "two";
default: unreachable(); // value is guaranteed to be 1 or 2
}
void unreachable()
Invokes undefined behavior for optimization purposes.
Definition mp_utils.hpp:882

Definition at line 882 of file mp_utils.hpp.

Here is the caller graph for this function:

Variable Documentation

◆ excludes_copy_and_move_ctor_v

◆ is_type_instance_of_v

template<class T, template< class... > class U>
bool sparrow::mpl::is_type_instance_of_v = is_type_instance_of<T, U>::value
constexpr

Variable template for convenient access to is_type_instance_of.

Checks if T is a concrete instantiation of template U.

Template Parameters
TThe concrete type to check
UThe template to check against
Postcondition
Returns true if T is an instantiation of U, false otherwise
static_assert(is_type_instance_of_v<std::vector<int>, std::vector>);
constexpr bool is_type_instance_of_v
Variable template for convenient access to is_type_instance_of.
Definition mp_utils.hpp:102
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/layout/fixed_width_binary_layout/fixed_width_binary_array.hpp, /home/runner/work/sparrow/sparrow/include/sparrow/layout/primitive_layout/primitive_array_impl.hpp, and /home/runner/work/sparrow/sparrow/include/sparrow/utils/decimal.hpp.

Definition at line 102 of file mp_utils.hpp.