cxxomfort  rel.20210622
Simple backports for C++ - http://ryan.gulix.cl/fossil.cgi/cxxomfort/
<algorithm>

Backports related to Standard header <algorithm>

// or as part of:

Interfaces

Backports defined in this section:

Pending:

Non-backport features:

algorithms

This header offers a number of constexpr -capable implementations for some algorithms that can be made constexpr with only C++11 requirement. Because the names can not be reused when the algorithms are already provided by C++ (since they'd take the same argumentts in the same order), they are instead provided in two ways:

These algorithms are:

Note
These algorithms can only work constexpr with native arrays, and with constexpr types whose iterators are pointer types (eg.: basic_string with default allocator).

Demonstration:

Copies and prints elements from a list via copy_if() and for_each_n() .

struct {
template <typename Numeric>
bool operator() (Numeric n) const {
return n % 2 == 0;
}
} even= {};
struct {
template <typename T>
SS& operator() (T const& t) const {
return os<< t;
}
std::ostream& os;
} print (std::cout);
list<int> s1;
generate( begin(s1), end(s1), rand);
vector<int> s2;
copy_if( begin(s1), end(s1), back_inserter(s2), even);
for_each_n( begin(s1), end(s1), print);

Examples

For other examples see the following entries in cxxomfort-examples :

See Also

See also
cxxomfort/algorithm.hpp (header reference)
header/algorithm @ cppreference (cppreference)
<numeric> (std numeric algorithms) , Cxxomfort <algorithm> Supplements (supplemental)
Member cxxomfort::cxxostd::copy_if (InpI ini, InpI fin, OutI dest, Predicate f)
Copy elements from one place to another
Member cxxomfort::cxxostd::copy_n (InpI ini, Integral n, OutI dest)
"Algorithms" "copy_n"
Member cxxomfort::cxxostd::count (It ini, It fin, T const &tv)
Member cxxomfort::cxxostd::count_if (It ini, It fin, Pred p)
Member cxxomfort::cxxostd::equal (RangeIt1 ini1, RangeIt1 fin1, RangeIt2 ini2, RangeIt2 fin2, Compare eq)
""
Member cxxomfort::cxxostd::fill_n (It ini, Numeric n, T const &tv)
Member cxxomfort::cxxostd::find_if (It ini, It fin, Pred f)
Member cxxomfort::cxxostd::find_if_not (It ini, It fin, Pred f)
"Algorithms" find_if_not
Member cxxomfort::cxxostd::for_each_n (II first, Size n, UnaryFunction f)

Member cxxomfort::cxxostd::is_sorted (Iterator ini, Iterator fin, Compare less)
"Algorithms" is_sorted
Member cxxomfort::cxxostd::minmax (T const &a, T const &b, Comparator Less)
Find the minimum and maximum elements in a sequence
Member cxxomfort::cxxostd::minmax_element (FIterator ini, FIterator fin, Comparator less)
Member cxxomfort::cxxostd::mismatch (InputIt1 ini1, InputIt1 fin1, InputIt2 ini2, InputIt2 fin2, BinaryPredicate p)
""
Member cxxomfort::cxxostd::next_permutation (BidirIt ini, BidirIt fin, Compare Less)
Member cxxomfort::cxxostd::partition_copy (InpI ini, InpI const fin, OutI1 Dtrue, OutI2 Dfalse, Predicate f)
Conditionally copy data to either of two destinations. partition_copy
Member cxxomfort::cxxostd::prev_permutation (BidirIt ini, BidirIt fin, Compare less)
Member cxxomfort::cxxostd::shuffle (RAIterator ini, RAIterator fin, URNG &g)

"Algorithms" shuffle

Member cxxomfort::move (IIt ini, IIt fin, OIt dest)
Member cxxomfort::move_backward (IIt ini, IIt fin, OIt dest)