This header provides general algorithms to make your life easier.
More...
|
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...
|
|
This header provides general algorithms to make your life easier.
◆ 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
-
T | The type of the value to be checked. |
In | The type of the range of predicates. |
- Parameters
-
value | The value to be checked. |
range | The 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.
104 std::vector<std::ranges::iterator_t<In const>> result;
106 for (
auto it{std::ranges::begin(range)}; it != std::ranges::end(range);
109 result.emplace_back(it);
◆ 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
-
T | type of the elements to be extracted. |
T2 | value_type of the output iterator |
In | type of the input iterators |
Out | type of the output iterator |
- Parameters
-
begin | Start of the range of elements to be extracted |
end | End of the range of elements to be extracted |
out | Output iterator to store the extracted elements |
- Examples
- algorithm/hello_world.cpp, and algorithm/hello_world_ranges.cpp.
39 if constexpr (std::is_same_v<T, typename std::iter_value_t<In>>)
40 std::copy(begin, end, out);
44 typename std::iter_reference_t<In>
const value{*begin++};
45 flatten<T>(std::cbegin(value), std::cend(value), out);
◆ 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
-
T | type of the elements to be extracted. |
In | Type of the input range. |
Out | Type of the output iterator. |
- Parameters
-
range | Input range of elements to be extracted. |
out | Output iterator to store the extracted elements. |
72 if constexpr (std::is_same_v<T, typename std::iter_value_t<In>>)
73 std::ranges::copy(range, out);
75 std::ranges::for_each(
77 [&out](
auto const &value)
78 { flatten<T>(std::cbegin(value), std::cend(value), out); });