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

Namespaces

namespace  impl
 
namespace  predicate
 

Classes

struct  add_const_lvalue_reference
 
struct  constify
 
struct  constify< T &, is_const >
 
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
 
struct  excludes_copy_and_move_ctor< CLS >
 
struct  excludes_copy_and_move_ctor< CLS, T >
 
struct  is_type_instance_of
 
struct  is_type_instance_of< L< T... >, U >
 
struct  typelist
 A sequence of types, used for meta-programming operations. More...
 

Concepts

concept  any_typelist
 Matches any type which is an instance of typelist.
 
concept  type_wrapper
 Matches template types which can be used as type-wrappers for evaluation in type-predicates.
 
concept  ct_type_predicate
 Matches template types that can be evaluated at compile-time similarly to std::true/false_type This makes possible to use predicates provided by the standard.
 
concept  callable_type_predicate
 Matches types whose instance can be called with an object representing a type to evaluate it.
 
concept  constant_iterator
 Represents a constant iterator.
 
concept  constant_range
 The constant_range concept is a refinement of range for which ranges::begin returns a constant iterator.
 
concept  bool_convertible_range
 Matches range types whose elements are convertible to bool.
 
concept  boolean_like
 Matches types that can be convertible to and assignable from bool.
 
concept  convertible_ranges
 Matches range types From whose elements are convertible to elements of range type To.
 
concept  unique_ptr
 
concept  unique_ptr_or_derived
 
concept  shared_ptr
 
concept  shared_ptr_or_derived
 
concept  smart_ptr
 
concept  smart_ptr_and_derived
 
concept  testable
 
concept  T_matches_qualifier_if_Y_is
 
concept  iterator_of_type
 Concept to check if an iterator is of a specific type.
 
concept  char_like
 
concept  std_array
 
concept  fixed_size_span
 

Typedefs

template<class TypeList, class... Us>
using append_t = decltype(append(TypeList{}, Us{}...))
 Appends one or more types or typelist to a given TypeList.
 
template<class From, template< class... > class To>
using rename = typename impl::rename_impl<From, To>::type
 Changes the type of the list to the given type/ Example: static_assert(std::same_as<rename<typelist<int, float>, std::variant>, std::variant<int, float>>)
 
template<template< class > class F, class... L>
using transform = typename impl::transform_impl<F, L...>::type
 Applies the metafunction F to each tuple of elements in the typelists and returns the corresponding list Example: transform<std::add_pointer_t, typelist<int, float> gives typelist<int*, float*> transform<std::is_same, typelist<int, float>, typelist<int, int>> gives typelist<std::is_same<int, int>, std::is_same<float, int>>
 
template<class T>
using add_const_lvalue_reference_t = typename add_const_lvalue_reference<T>::type
 
template<class T, bool is_const>
using constify_t = typename constify<T, is_const>::type
 
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 T.
 

Functions

template<class... Ts, class... Us>
requires (!is_type_instance_of_v<Us, typelist> && ...)
consteval auto append (typelist< Ts... >, Us...)
 Appends the given 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... >={})
 
template<class T, template< class > class P>
requires ct_type_predicate<P, T>
consteval bool evaluate (P< T >)
 Evaluates the provided compile-time template class predicate P given a type T, if P is of a similar shape to std::true/false_type.
 
template<class T, callable_type_predicate< T > P>
consteval bool evaluate (P predicate)
 Evaluates the provided compile-time template class predicate P given a type T, if P's instance is callable given a value type wrapper of T.
 
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 that at least one type in the provided list of is making the provide predicate return true.
 
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 that at least one type in the provided list of is making the provide predicate return true.
 
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 that every type in the provided list of is making the provide predicate return true.
 
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 that every type in the provided list of is making the provide predicate return true.
 
template<class V, any_typelist L>
consteval bool contains (L list)
 
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)
 
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)
 
template<class TypeToFind, any_typelist L>
consteval std::size_t find (L list)
 
void unreachable ()
 Invokes undefined behavior.
 
template<typename T>
constexpr bool is_reference_wrapper (const T &)
 Checks if the given type is a reference wrapper.
 

Variables

template<class T, template< class... > class U>
constexpr bool is_type_instance_of_v = is_type_instance_of<T, U>::value
 true if T is a concrete type template instanciation of U which is a type template.
 
template<class CLS, class... ARGS>
constexpr bool excludes_copy_and_move_ctor_v = excludes_copy_and_move_ctor<CLS, ARGS...>::value
 
template<typename T>
constexpr bool is_reference_wrapper_v = false
 
template<typename U>
constexpr bool is_reference_wrapper_v< std::reference_wrapper< U > > = true
 

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

Definition at line 373 of file mp_utils.hpp.

◆ append_t

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

Appends one or more types or typelist to a given TypeList.

This template alias takes a TypeList and one or more types or typelist as template arguments. It appends the types to the given TypeList and returns the resulting TypeList.

Template Parameters
TypeListThe TypeList to which the types will be appended.
UsThe types or typelists to be appended to the TypeList.
Returns
The resulting TypeList after appending the types.

Definition at line 103 of file mp_utils.hpp.

◆ constify_t

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

Definition at line 390 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 T.

Template Parameters
TThe const reference type of T.

Definition at line 396 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 type of the list to the given type/ Example: static_assert(std::same_as<rename<typelist<int, float>, std::variant>, std::variant<int, float>>)

Definition at line 135 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 the metafunction F to each tuple of elements in the typelists and returns the corresponding list Example: transform<std::add_pointer_t, typelist<int, float> gives typelist<int*, float*> transform<std::is_same, typelist<int, float>, typelist<int, int>> gives typelist<std::is_same<int, int>, std::is_same<float, int>>

Definition at line 362 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 that every type in the provided list of is making the provide predicate return true.

Returns
true if for every type T in the type list L, Predicate<T>::value == true or if the list is empty; false otherwise.

Definition at line 278 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 that every type in the provided list of is making the provide predicate return true.

Returns
true if for every type T in the type list L, Predicate{}(typelist<T>) == true or if the list is empty; false otherwise.

Definition at line 264 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 that at least one type in the provided list of is making the provide predicate return true.

Returns
'true' if for at least one type T in the type list L, Predicate<T>::value == true. false otherwise or if the list is empty.

Definition at line 254 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 that at least one type in the provided list of is making the provide predicate return true.

Returns
'true' if for at least one type T in the type list L,, Predicate{}(typelist<T>) == true. false otherwise or if the list is empty.

Definition at line 244 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.

Template Parameters
Ts...The types in the first typelist.
Us...The types in the second typelist.
Parameters
list1The first typelist.
list2The second typelist.
Returns
A new typelist that contains all the types from both input typelists.

Definition at line 87 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 the given types to a typelist.

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

Template Parameters
Ts...The types in the original typelist.
Us...The additional types to be appended.
Parameters
typelist<Ts...>The original typelist.
Us...The additional types.
Returns
A new typelist containing all the types from the original typelist followed by the additional types.

Definition at line 71 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 231 of file mp_utils.hpp.

Here is the caller graph for this function:

◆ contains()

template<class V, any_typelist L>
bool sparrow::mpl::contains ( L list)
nodiscardconsteval
Returns
true if the provided type list contains V

Definition at line 285 of file mp_utils.hpp.

Here is the call graph for this function:

◆ evaluate() [1/2]

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

Evaluates the provided compile-time template class predicate P given a type T, if P's instance is callable given a value type wrapper of T.

Definition at line 182 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 the provided compile-time template class predicate P given a type T, if P is of a similar shape to std::true/false_type.

Definition at line 174 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
Returns
The index position in the type TypeToFind in the provided type list L, or the size of the list if the matching type was not found.

Definition at line 329 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
Returns
The index position in the first type in the provided type list L that matches the provided predicate, or the size of the list if the matching type was not found.

Definition at line 321 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
Returns
The index position in the first type in the provided type list L that matches the provided predicate, or the size of the list if the matching type was not found.

Definition at line 295 of file mp_utils.hpp.

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

◆ is_reference_wrapper()

template<typename T>
bool sparrow::mpl::is_reference_wrapper ( const T & )
nodiscardconstexpr

Checks if the given type is a reference wrapper.

Template Parameters
TThe type to check.
Parameters
Theinstance of the type to check.
Returns
true if the type is a reference wrapper, false otherwise.

Definition at line 66 of file reference_wrapper_utils.hpp.

◆ size()

template<class... T>
std::size_t sparrow::mpl::size ( typelist< T... > = {})
constexpr
Returns
The count of types contained in a given typelist.

Definition at line 107 of file mp_utils.hpp.

◆ unreachable()

void sparrow::mpl::unreachable ( )
inline

Invokes undefined behavior.

An implementation may use this to optimize impossible code branches away (typically, in optimized builds) or to trap them to prevent further execution (typically, in debug builds).

Note
Documentation and implementation come from https://en.cppreference.com/w/cpp/utility/unreachable

Definition at line 425 of file mp_utils.hpp.

Here is the caller graph for this function:

Variable Documentation

◆ excludes_copy_and_move_ctor_v

template<class CLS, class... ARGS>
bool sparrow::mpl::excludes_copy_and_move_ctor_v = excludes_copy_and_move_ctor<CLS, ARGS...>::value
constexpr

Definition at line 507 of file mp_utils.hpp.

◆ is_reference_wrapper_v

template<typename T>
bool sparrow::mpl::is_reference_wrapper_v = false
constexpr

Definition at line 55 of file reference_wrapper_utils.hpp.

◆ is_reference_wrapper_v< std::reference_wrapper< U > >

template<typename U>
bool sparrow::mpl::is_reference_wrapper_v< std::reference_wrapper< U > > = true
constexpr

Definition at line 58 of file reference_wrapper_utils.hpp.

◆ 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

true if T is a concrete type template instanciation of U which is a type template.

Example: is_type_instance_of_v< std::vector<int>, std::vector > == true

Definition at line 50 of file mp_utils.hpp.