exptl
General C++20 library that complements the C++ Standard Library
Functions
algorithm

This header provides general algorithms to make your life easier. More...

Functions

template<typename T , typename T2 = T, std::input_iterator In, std::output_iterator< T2 > Out>
requires std::assignable_from<T2 &, T>
void exptl::flatten (In begin, In const end, Out out)
 Extracts elements from nested containers. More...
 
template<typename T , typename T2 = T, std::ranges::input_range In, std::output_iterator< T2 > Out>
requires std::assignable_from<T2 &, T>
void exptl::flatten (In range, Out out)
 Extracts elements from nested containers. More...
 
template<typename T , std::ranges::forward_range In>
requires std::predicate<std::ranges::range_value_t<In const>, T const &> std::vector<std::ranges::borrowed_iterator_t<In const>>
constexpr exptl::classify (T const value, In &&range)
 Checks a value against a range of predicates and returns a vector of iterators to the satisfied predicates. More...
 

Detailed Description

This header provides general algorithms to make your life easier.

Function Documentation

◆ classify()

template<typename T , std::ranges::forward_range In>
requires std::predicate<std::ranges::range_value_t<In const>, T const &> std::vector<std::ranges::borrowed_iterator_t<In const>>
constexpr exptl::classify ( T const  value,
In &&  range 
)
constexpr

Checks a value against a range of predicates and returns a vector of iterators to the satisfied predicates.

Template Parameters
TThe type of the value to be checked.
InThe type of the range of predicates.
Parameters
valueThe value to be checked.
rangeThe range of predicates to apply.
Returns
Vector of iterators to the satisfied predicates. Iterators are std::ranges::dangling if range does not model std::ranges::borrowed_range.
Examples
algorithm/classify_dangling.cpp, and algorithm/classify_fizzbuzz.cpp.
103{
104 std::vector<std::ranges::iterator_t<In const>> result;
105
106 for (auto it{std::ranges::begin(range)}; it != std::ranges::end(range);
107 ++it)
108 if ((*it)(value))
109 result.emplace_back(it);
110
111 return result;
112}

◆ flatten() [1/2]

template<typename T , typename T2 = T, std::input_iterator In, std::output_iterator< T2 > Out>
requires std::assignable_from<T2 &, T>
void exptl::flatten ( In  begin,
In const  end,
Out  out 
)

Extracts elements from nested containers.

Template Parameters
Ttype of the elements to be extracted.
T2value_type of the output iterator
Intype of the input iterators
Outtype of the output iterator
Parameters
beginStart of the range of elements to be extracted
endEnd of the range of elements to be extracted
outOutput iterator to store the extracted elements
Examples
algorithm/hello_world.cpp, and algorithm/hello_world_ranges.cpp.
38{
39 if constexpr (std::is_same_v<T, typename std::iter_value_t<In>>)
40 std::copy(begin, end, out);
41 else
42 while (begin != end)
43 {
44 typename std::iter_reference_t<In> const value{*begin++};
45 flatten<T>(std::cbegin(value), std::cend(value), out);
46 }
47}

◆ flatten() [2/2]

template<typename T , typename T2 = T, std::ranges::input_range In, std::output_iterator< T2 > Out>
requires std::assignable_from<T2 &, T>
void exptl::flatten ( In  range,
Out  out 
)

Extracts elements from nested containers.

Template Parameters
Ttype of the elements to be extracted.
InType of the input range.
OutType of the output iterator.
Parameters
rangeInput range of elements to be extracted.
outOutput iterator to store the extracted elements.
71{
72 if constexpr (std::is_same_v<T, typename std::iter_value_t<In>>)
73 std::ranges::copy(range, out);
74 else
75 std::ranges::for_each(
76 range,
77 [&out](auto const &value)
78 { flatten<T>(std::cbegin(value), std::cend(value), out); });
79}