0.2.0
Loading...
Searching...
No Matches
CartesianProduct.hpp File Reference

Algorithm iterating all combinations of a list. More...

Go to the source code of this file.

Classes

struct  NAV::CartesianProduct::increment_iterator< I >
 Helper struct to increment an iterator. More...
 
struct  NAV::CartesianProduct::increment_iterator< 0 >
 Helper struct to increment an iterator. More...
 

Functions

template<typename Tuple , typename Predicate >
bool NAV::CartesianProduct::tuple_algos::any_of (Tuple &&tuple, Predicate pred)
 Any_of algorithm for tuples.
 
template<typename Function , typename... Ts, size_t... Is>
void NAV::CartesianProduct::callFunction (Function function, std::tuple< Ts... > const &tuple, std::index_sequence< Is... >)
 Calls the function on the tuple.
 
template<typename Function , typename... Ranges>
void NAV::cartesian_product (Function function, Ranges const &... ranges)
 Calls a function on all combinations over ranges.
 
template<typename SubList , size_t N, typename Function >
void NAV::cartesian_product (Function function, std::array< SubList, N > list)
 Calls a function on all combinations over ranges defined in an array, e.g. std::array<std::vector>
 
template<typename SubList , size_t N, typename Function >
void NAV::cartesian_product_idx (Function function, std::array< SubList, N > list)
 Calls a function on all combinations over ranges defined in an array, e.g. std::array<std::vector>. Instead of providing the list entry to the function, provides the index of it in the sub list.
 
template<typename... Ts>
auto NAV::CartesianProduct::dereference (std::tuple< Ts... > const &tuple)
 Dereference a tuple.
 
template<typename Tuple , typename Predicate >
size_t NAV::CartesianProduct::tuple_algos::find_if (Tuple &&tuple, Predicate pred)
 Find_if for tuples.
 
template<class F , class Tuple >
constexpr decltype(auto) NAV::CartesianProduct::tuple_algos::for_each (Tuple &&t, F &&f)
 For-each algorithm for tuples.
 
template<class Tuple , class F , std::size_t... I>
NAV::CartesianProduct::tuple_algos::for_each_impl (Tuple &&t, F &&f, std::index_sequence< I... >)
 For-each implementation for tuples.
 
template<typename... Iterators>
void NAV::CartesianProduct::next_combination (std::tuple< Iterators... > &iterators, std::tuple< Iterators... > const &beginIterators, std::tuple< Iterators... > const &endIterators)
 Gets the next combination of the tuples of iterators.
 
template<typename... Ts, typename Function >
auto NAV::CartesianProduct::tuple_algos::transform (std::tuple< Ts... > const &inputs, Function function)
 Transform algorithm for tuples.
 
template<class Tuple , class F , std::size_t... Is>
auto NAV::CartesianProduct::tuple_algos::transform_impl (Tuple &&t, F &&f, std::index_sequence< Is... >) -> decltype(std::make_tuple(std::forward< F >(f)(std::get< Is >(std::forward< Tuple >(t)))...))
 Transform implementation for tuples.
 

Detailed Description

Algorithm iterating all combinations of a list.

Author
T. Topp (topp@.nosp@m.ins..nosp@m.uni-s.nosp@m.tutt.nosp@m.gart..nosp@m.de)
Date
2022-11-04
Note
Original code by Jonathan Boccara from https://www.fluentcpp.com/2022/03/18/how-to-generate-all-the-combinations-from-several-collections/

Function Documentation

◆ any_of()

template<typename Tuple , typename Predicate >
bool NAV::CartesianProduct::tuple_algos::any_of ( Tuple && tuple,
Predicate pred )

Any_of algorithm for tuples.

Parameters
[in]tupleThe tuple to search
[in]predPredicate to check for
Returns
True if any of the tuple entries fulfills the predicate

◆ callFunction()

template<typename Function , typename... Ts, size_t... Is>
void NAV::CartesianProduct::callFunction ( Function function,
std::tuple< Ts... > const & tuple,
std::index_sequence< Is... >  )

Calls the function on the tuple.

Parameters
[in]functionFunction to call
[in]tupleTuple to pass as argument

◆ cartesian_product() [1/2]

template<typename Function , typename... Ranges>
void NAV::cartesian_product ( Function function,
Ranges const &... ranges )

Calls a function on all combinations over ranges.

Parameters
[in]functionFunction to call. Needs one parameter for each range given. Type of the parameter must be equal to the range type.
[in]rangesRanges to call the function on

◆ cartesian_product() [2/2]

template<typename SubList , size_t N, typename Function >
void NAV::cartesian_product ( Function function,
std::array< SubList, N > list )

Calls a function on all combinations over ranges defined in an array, e.g. std::array<std::vector>

Parameters
[in]functionFunction to call. Needs one parameter for each element in the array. Type of the parameter must be equal to the range type.
[in]listList of ranges to call the function on

◆ cartesian_product_idx()

template<typename SubList , size_t N, typename Function >
void NAV::cartesian_product_idx ( Function function,
std::array< SubList, N > list )

Calls a function on all combinations over ranges defined in an array, e.g. std::array<std::vector>. Instead of providing the list entry to the function, provides the index of it in the sub list.

Parameters
[in]functionFunction to call. Needs one 'size_t' parameter for each element in the array
[in]listList of ranges to call the function on

◆ dereference()

template<typename... Ts>
auto NAV::CartesianProduct::dereference ( std::tuple< Ts... > const & tuple)

Dereference a tuple.

Parameters
[in]tupleTuple to dereference
Returns
Dereferenced tuple values

◆ find_if()

template<typename Tuple , typename Predicate >
size_t NAV::CartesianProduct::tuple_algos::find_if ( Tuple && tuple,
Predicate pred )

Find_if for tuples.

Parameters
[in]tupleThe tuple to search
[in]predPredicate to use for finding
Returns
Index of the found entry

◆ for_each()

template<class F , class Tuple >
constexpr decltype(auto) NAV::CartesianProduct::tuple_algos::for_each ( Tuple && t,
F && f )
constexpr

For-each algorithm for tuples.

Parameters
[in]tThe tuple
[in]fFunction to call
Returns
Function return value

◆ for_each_impl()

template<class Tuple , class F , std::size_t... I>
F NAV::CartesianProduct::tuple_algos::for_each_impl ( Tuple && t,
F && f,
std::index_sequence< I... >  )

For-each implementation for tuples.

Parameters
[in]tThe tuple
[in]fFunction to call

◆ next_combination()

template<typename... Iterators>
void NAV::CartesianProduct::next_combination ( std::tuple< Iterators... > & iterators,
std::tuple< Iterators... > const & beginIterators,
std::tuple< Iterators... > const & endIterators )

Gets the next combination of the tuples of iterators.

Parameters
[in]iteratorsThe iterator to get the next combination for
[in]beginIteratorsBeginning of the Iterators
[in]endIteratorsEnd of the Iterators

◆ transform()

template<typename... Ts, typename Function >
auto NAV::CartesianProduct::tuple_algos::transform ( std::tuple< Ts... > const & inputs,
Function function )

Transform algorithm for tuples.

Parameters
[in]inputsInput tuple
[in]functionFunction to call
Returns
The transformed tuple

◆ transform_impl()

template<class Tuple , class F , std::size_t... Is>
auto NAV::CartesianProduct::tuple_algos::transform_impl ( Tuple && t,
F && f,
std::index_sequence< Is... >  ) -> decltype(std::make_tuple(std::forward<F>(f)(std::get<Is>(std::forward<Tuple>(t)))...))

Transform implementation for tuples.

Parameters
[in]tTuple
[in]fFunction to call
Returns
The transformed tuple