version 0.4.1
Algorithms

Stl-like algorithms for runtime and compile time. More...

Collaboration diagram for Algorithms:

Functions

void Ikarus::utils::makeUniqueAndSort (std::ranges::random_access_range auto &r)
 Sorts and removes duplicate elements from a random access range.*. More...
 
template<typename T >
auto Ikarus::utils::appendUnique (std::ranges::random_access_range auto &r, T &&v)
 Appends a value to the range if it is not already present. More...
 
template<class C >
void Ikarus::utils::printContent (C &&c, std::ostream &os=std::cout)
 Prints the contents of a container to the specified output stream. More...
 
template<class C >
auto Ikarus::utils::transformValueRangeToPointerRange (C &cont)
 Transforms a value range to a pointer range. More...
 
template<class C >
auto Ikarus::utils::transformPointerRangeToReferenceRange (C &cont)
 Transforms a pointer range to a reference range. More...
 
template<typename Tuple , typename Predicate >
constexpr size_t Ikarus::utils::find_if (Tuple &&tuple, Predicate pred)
 Finds the index of the first element in the tuple satisfying a predicate. More...
 
template<typename Tuple , typename Predicate >
bool Ikarus::utils::none_of (Tuple &&tuple, Predicate pred)
 Checks if none of the elements in the tuple satisfy a given predicate. More...
 
template<typename Tuple , typename Predicate >
bool Ikarus::utils::any_of (Tuple &&tuple, Predicate pred)
 Checks if any of the elements in the tuple satisfy a given predicate. More...
 
template<typename Tuple , typename Predicate >
auto Ikarus::utils::filter (Tuple &&tuple, Predicate pred)
 Filters the elements of a tuple based on a given predicate. More...
 
template<typename... Types>
constexpr auto Ikarus::utils::unique (std::tuple< Types... > &&tuple)
 Creates a tuple with unique types from the given tuple. More...
 
template<typename Tuple , typename Predicate >
constexpr size_t Ikarus::utils::count_if (Tuple &&tuple, Predicate pred)
 Counts the number of elements in the tuple satisfying the given predicate. More...
 
template<template< auto... > class Type, typename Tuple >
constexpr int Ikarus::utils::findTypeSpecialization ()
 Finds the index of the first element in the tuple that is a specialization of the given template type. More...
 
template<template< auto... > class Type, typename Tuple >
auto Ikarus::utils::getSpecialization (Tuple &&tuple)
 Gets the specialization of the given template type from the tuple. More...
 
template<template< auto... > class Type, typename Tuple >
constexpr bool Ikarus::utils::hasTypeSpecialization ()
 Checks if a tuple has a specialization of a template type. More...
 
template<template< auto... > class Type, typename Tuple >
constexpr bool Ikarus::utils::countTypeSpecialization ()
 Counts the occurrences of a specialization of a template type in a tuple. More...
 
template<int N, class Tuple >
constexpr auto Ikarus::utils::makeTupleSubset (Tuple &&t)
 Creates a subset tuple with the first N elements from the given tuple. More...
 
template<class Tuple , std::size_t... I>
constexpr auto Ikarus::utils::makeTupleFromTupleIndices (Tuple &&t)
 Creates a new tuple using indices from the original tuple. More...
 

Variables

template<template< auto... > class Type, typename Tuple >
static constexpr bool Ikarus::utils::countTypeSpecialization_v = countTypeSpecialization<Type, Tuple>()
 Variable template for counting the occurrences of a specialization of a template type in a tuple. More...
 

Detailed Description

Function Documentation

◆ any_of()

template<typename Tuple , typename Predicate >
bool Ikarus::utils::any_of ( Tuple &&  tuple,
Predicate  pred 
)
Template Parameters
TupleType of the input tuple.
PredicateType of the predicate function.
Parameters
tupleInput tuple.
predPredicate function to check each element.
Returns
bool True if any of the elements satisfy the predicate, false otherwise.

◆ appendUnique()

template<typename T >
auto Ikarus::utils::appendUnique ( std::ranges::random_access_range auto &  r,
T &&  v 
)

This function appends a value to the given random access range only if the value is not already present in the range. It returns the index of the value in the range, whether it was added or already existed.

Template Parameters
TThe type of the value to be appended.
Parameters
rThe random access range to be modified.
vThe value to be appended.
Returns
The index of the value in the range.

◆ count_if()

template<typename Tuple , typename Predicate >
constexpr size_t Ikarus::utils::count_if ( Tuple &&  tuple,
Predicate  pred 
)
constexpr
Template Parameters
TupleType of the tuple.
PredicatePredicate function determining whether an element satisfies the condition.
Parameters
tupleInput tuple.
predPredicate function.
Returns
constexpr size_t Number of elements satisfying the predicate.

This function counts the number of elements in the tuple that satisfy the given predicate.

Here is the caller graph for this function:

◆ countTypeSpecialization()

template<template< auto... > class Type, typename Tuple >
constexpr bool Ikarus::utils::countTypeSpecialization ( )
constexpr
Template Parameters
TypeTemplate type to count occurrences for.
TupleType of the tuple.
Returns
The count of occurrences of the specialization.

This function counts the occurrences of a specialization of a template type in a tuple.

◆ filter()

template<typename Tuple , typename Predicate >
auto Ikarus::utils::filter ( Tuple &&  tuple,
Predicate  pred 
)
Template Parameters
TupleType of the input tuple.
PredicateType of the predicate function.
Parameters
tupleInput tuple.
predPredicate function to filter the elements.
Returns
auto Tuple containing elements that satisfy the predicate.

This function applies the given predicate to each element of the tuple. It constructs a new tuple containing only those elements for which the predicate returns true. The resulting tuple is returned.

◆ find_if()

template<typename Tuple , typename Predicate >
constexpr size_t Ikarus::utils::find_if ( Tuple &&  tuple,
Predicate  pred 
)
constexpr
Template Parameters
TupleType of the input tuple.
PredicateType of the predicate function.
Parameters
tupleInput tuple.
predPredicate function to check each element.
Returns
Index of the first element satisfying the predicate. If no element satisfies the predicate, it returns the size of the tuple.

This function takes a tuple and a predicate function and finds the index of the first element in the tuple that satisfies the given predicate. It uses Dune::Hybrid::forEach to iterate through the tuple.

Here is the caller graph for this function:

◆ findTypeSpecialization()

template<template< auto... > class Type, typename Tuple >
constexpr int Ikarus::utils::findTypeSpecialization ( )
constexpr
Template Parameters
TypeTemplate type to search for.
TupleType of the tuple.
Returns
Index of the first specialization in the tuple

This function finds the index of the first element in the tuple that is a specialization of the given template type. It returns the size of the tuple if the template type is not found

◆ getSpecialization()

template<template< auto... > class Type, typename Tuple >
auto Ikarus::utils::getSpecialization ( Tuple &&  tuple)
Template Parameters
TypeTemplate type to search for.
TupleType of the tuple.
Parameters
tupleThe tuple containing elements.
Returns
The specialization element

This function retrieves the specialization of a template type from the tuple.

◆ hasTypeSpecialization()

template<template< auto... > class Type, typename Tuple >
constexpr bool Ikarus::utils::hasTypeSpecialization ( )
constexpr
Template Parameters
TypeTemplate type to check for.
TupleType of the tuple.
Returns
true if the tuple has the specialization; otherwise, false.

This function checks if a tuple has a specialization of a template type. It uses find_if to search for the type and returns true if the index is less than the tuple size; otherwise, false.

◆ makeTupleFromTupleIndices()

template<class Tuple , std::size_t... I>
constexpr auto Ikarus::utils::makeTupleFromTupleIndices ( Tuple &&  t)
constexpr
Template Parameters
TupleType of the original tuple.
IIndices to include in the new tuple.
Parameters
tThe original tuple.
Returns
A new tuple containing elements from the original tuple based on the specified indices.

This function creates a new tuple using indices from the original tuple. It uses makeTupleFromTupleIndicesImpl from the Impl namespace to implement the tuple creation.

◆ makeTupleSubset()

template<int N, class Tuple >
constexpr auto Ikarus::utils::makeTupleSubset ( Tuple &&  t)
constexpr
Template Parameters
NNumber of elements in the subset.
TupleType of the original tuple.
Parameters
tThe original tuple.
Returns
A new tuple containing the first N elements of the original tuple.

This function creates a subset tuple with the first N elements from the given tuple.

◆ makeUniqueAndSort()

void Ikarus::utils::makeUniqueAndSort ( std::ranges::random_access_range auto &  r)

This function sorts the elements of the given random access range and removes duplicate elements, leaving only unique elements in the range.

Parameters
rThe random access range to be modified.

◆ none_of()

template<typename Tuple , typename Predicate >
bool Ikarus::utils::none_of ( Tuple &&  tuple,
Predicate  pred 
)
Template Parameters
TupleType of the input tuple.
PredicateType of the predicate function.
Parameters
tupleInput tuple.
predPredicate function to check each element.
Returns
bool True if none of the elements satisfy the predicate, false otherwise.
Here is the caller graph for this function:

◆ printContent()

template<class C >
void Ikarus::utils::printContent ( C &&  c,
std::ostream &  os = std::cout 
)

This function prints the contents of the given container to the specified output stream.

Template Parameters
CThe type of the container to be printed.
Parameters
cThe container whose contents will be printed.
osThe output stream where the contents will be printed. Default is std::cout.

◆ transformPointerRangeToReferenceRange()

template<class C >
auto Ikarus::utils::transformPointerRangeToReferenceRange ( C &  cont)

This function transforms a range of pointers to a range of references.

Template Parameters
CThe type of the container containing pointers.
Parameters
contThe container whose pointers will be transformed to references.
Returns
A subrange containing references to the pointed objects.

◆ transformValueRangeToPointerRange()

template<class C >
auto Ikarus::utils::transformValueRangeToPointerRange ( C &  cont)
Template Parameters
CThe type of the container containing values.
Parameters
contThe container whose values will be transformed to pointers.
Returns
A subrange containing pointers to the values.

◆ unique()

template<typename... Types>
constexpr auto Ikarus::utils::unique ( std::tuple< Types... > &&  tuple)
constexpr
Template Parameters
TypesVariadic template parameters representing types.
Parameters
tupleInput tuple.
Returns
auto Tuple with unique types.

This function takes a tuple and returns a new tuple containing only unique types from the input tuple.

Here is the caller graph for this function:

Variable Documentation

◆ countTypeSpecialization_v

template<template< auto... > class Type, typename Tuple >
constexpr bool Ikarus::utils::countTypeSpecialization_v = countTypeSpecialization<Type, Tuple>()
staticconstexpr
Template Parameters
TypeTemplate type to count occurrences for.
TupleType of the tuple.

This variable template provides a compile-time constant for the count of occurrences of a specialization of a template type in a tuple.