cxxomfort
rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
|
cxxomfort Supplementals for <algorithm> More...
Namespaces | |
cxxomfort | |
Namespace of the cxxomfort library. | |
cxxomfort::library | |
Supplements to backports and other utilities. | |
Functions | |
template<typename Container > | |
void | erase (Container &C, typename Container::value_type const &u) |
Invokes erase-remove idiom on a container to remove element u as per remove() . More... | |
template<typename Container , typename Pred > | |
void | erase_if (Container &C, Pred if_) |
Invokes erase-remove idiom on a container to remove elements conditionally given predicate if_ as per remove_if() . More... | |
template<typename T , typename Compare > | |
CXXO_CONSTEXPR bool | is_clamped (T const &value, T const &lo, T const &hi, Compare less) CXXO_NOEXCEPTNOTHROW |
Checks if a value is clamped. More... | |
template<typename T > | |
CXXO_CONSTEXPR bool | is_clamped (T const &value, T const &lo, T const &hi) CXXO_NOEXCEPTNOTHROW |
template<class T , class Compare > | |
CXXO_CONSTEXPR T const & | clamp_halfopen (T const &val, T const &lo, T const &hi, Compare less) CXXO_NOEXCEPT |
Clamps a value within a half-open range. More... | |
template<class T > | |
CXXO_CONSTEXPR T const & | clamp_halfopen (T const &val, T const &lo, T const &hi) CXXO_NOEXCEPT |
template<typename T , typename Compare > | |
CXXO_CONSTEXPR bool | is_clamped_halfopen (T const &value, T const &lo, T const &hi, Compare less) CXXO_NOEXCEPTNOTHROW |
Checks if a value is clamped in a half-open interval as per clamp_halfopen() More... | |
template<typename T > | |
CXXO_CONSTEXPR bool | is_clamped_halfopen (T const &value, T const &lo, T const &hi) CXXO_NOEXCEPTNOTHROW |
template<typename OutI , typename InpI , typename Pred > | |
OutI | copy_if_not (InpI ini, InpI fin, OutI dest, Pred p) |
Copy like copy_if with inverted predicate (for symmetry with find_if_not ). More... | |
template<typename Iter1 , typename Integer , typename Iter2 > | |
Iter2 | copy_leftmost_n (Iter1 ini1, Iter1, Integer n, Iter2 ini2) |
Like copy_n in that it copies leftmost ("starting") n elements from the sequence. More... | |
template<typename It1 , typename Integer , typename It2 > | |
It2 | copy_rightmost_n (It1 ini1, It1 fin1, Integer n, It2 ini2) |
Like copy_n except it copies the rightmost n elements from the sequence. More... | |
template<typename It , typename Pred , typename T > | |
It | find (It ini, It fin, Pred if_, T const &v) |
Finds an element x in a sequence such that if_(x,v) holds. More... | |
template<typename It , typename T > | |
It | find_not (It ini, It fin, T const &t) |
Finds the first element in the sequence not equal to t . More... | |
template<typename It , typename Pred > | |
It | find_if_not (It ini, It fin, Pred if_) |
Finds the first element in the sequence not fitting predicate if_ . More... | |
template<typename Iter , typename Less > | |
Iter | find_inversion (Iter ini, Iter fin, Less lt) |
Finds a pair of elements that are out of place (ie.: the second one is "less" than the first). More... | |
template<typename Iter > | |
Iter | find_inversion (Iter ini, Iter fin) |
template<typename Iter , typename Less > | |
Iter | fix_inversion (Iter ini, Iter fin, Less m) |
Fixes a pair of misplaced elements where the second one is "less" than the first. More... | |
template<typename Iter , typename Pred > | |
Iter | find_last_if (Iter ini, Iter fin, Pred if_) |
Finds the latest item in a sequence that fits predicate if_ . More... | |
template<class InputIterator , class UnaryPredicate > | |
std::iterator_traits< InputIterator >::difference_type | count_while (InputIterator first, InputIterator last, UnaryPredicate pred) |
template<typename FIter , typename TF > | |
FIter | transform_inplace (FIter ini, FIter fin, TF tf) |
Transform elements in the range in-place via the transformation tf . More... | |
template<typename FIter , typename TF , typename P > | |
FIter | transform_inplace_if (FIter ini, FIter fin, TF tf, P p) |
Transform elements in the range conditionally. More... | |
template<typename IIterator , typename OIterator , typename TF , typename Integer > | |
OIterator | transform_n (IIterator ini, Integer n, OIterator dest, TF tf) |
Transform elements up to n times. More... | |
template<typename Iterator , typename ValueMapIterator , typename Reductor > | |
Iterator | count_frequencies_map (Iterator ini, Iterator fin, ValueMapIterator vi, Reductor const rint) |
Constructs a map of frequencies each element appears in the sequence. More... | |
cxxomfort Supplementals for <algorithm>
CXXO_CONSTEXPR bool cxxomfort::library::algorithm::is_clamped | ( | T const & | value, |
T const & | lo, | ||
T const & | hi, | ||
Compare | less | ||
) |
Checks if a value is clamped.
less | A relational predicate with semantics similar to those of std::less or operator<() |
true
if value is within the constraints. This is an implementation of p1440 "is_clamped": a complement to clamp()
in the same way is_sorted()
is a complement to sort()
.
Given general invocations of clamp()
, the following assertion should hold:
hi < lo
.is_clamped()
here is marked noexcept
; I consider there is no good scenario where relational comparison operators, or anything that mimics them, would be throwing, and clamp()
is to abort rather than throw upon precondition violation. Referenced by cxxomfort::library::algorithm::is_clamped().
CXXO_CONSTEXPR bool cxxomfort::library::algorithm::is_clamped | ( | T const & | value, |
T const & | lo, | ||
T const & | hi | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
CXXO_CONSTEXPR T const& cxxomfort::library::algorithm::clamp_halfopen | ( | T const & | val, |
T const & | lo, | ||
T const & | hi, | ||
Compare | less | ||
) |
Clamps a value within a half-open range.
less | A relational predicate with semantics similar to those of std::less or operator<() |
[lo , hi )
. clamp_halfopen(V,a,b)
is similar to clamp(V,a,b)
except that b is excluded as a potential resulting value.
hi < lo
. Referenced by cxxomfort::library::algorithm::clamp_halfopen(), and cxxomfort::library::algorithm::is_clamped_halfopen().
CXXO_CONSTEXPR T const& cxxomfort::library::algorithm::clamp_halfopen | ( | T const & | val, |
T const & | lo, | ||
T const & | hi | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
CXXO_CONSTEXPR bool cxxomfort::library::algorithm::is_clamped_halfopen | ( | T const & | value, |
T const & | lo, | ||
T const & | hi, | ||
Compare | less | ||
) |
Checks if a value is clamped in a half-open interval as per clamp_halfopen()
This is a supplement to p1440 "is_clamped" in that it checks if the value is clamped in a half-open interval.
Given the general concept of calls to clamp()
, the following assertion should hold:
hi < lo
.is_clamped_halfopen()
here is marked noexcept
; I consider there is no good scenario where relational comparison operators, or anything that mimics them, would be throwing. Referenced by cxxomfort::library::algorithm::is_clamped_halfopen().
CXXO_CONSTEXPR bool cxxomfort::library::algorithm::is_clamped_halfopen | ( | T const & | value, |
T const & | lo, | ||
T const & | hi | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Copy like copy_if
with inverted predicate (for symmetry with find_if_not
).
This is provided for symmetry with: std::find_if_not()
, std::copy_if()
.
Referenced by cxxomfort::library::algorithm::copy_if_not().
Iter2 cxxomfort::library::algorithm::copy_leftmost_n | ( | Iter1 | ini1, |
Iter1 | , | ||
Integer | n, | ||
Iter2 | ini2 | ||
) |
Like copy_n
in that it copies leftmost ("starting") n elements from the sequence.
This function copies the first n elements from the sequence starting at ini1. While it is basically equivalent to copy_n()
, it is provided for symmetry and completeness with copy_rightmost_n()
.
Referenced by cxxomfort::library::algorithm::copy_leftmost_n().
It2 cxxomfort::library::algorithm::copy_rightmost_n | ( | It1 | ini1, |
It1 | fin1, | ||
Integer | n, | ||
It2 | ini2 | ||
) |
Like copy_n
except it copies the rightmost n elements from the sequence.
It cxxomfort::library::algorithm::find | ( | It | ini, |
It | fin, | ||
Pred | if_, | ||
T const & | v | ||
) |
Finds an element x in a sequence such that if_(x,v)
holds.
fin
. This is taken from proposal wlg217.
See also: std::find_if
.
It cxxomfort::library::algorithm::find_not | ( | It | ini, |
It | fin, | ||
T const & | t | ||
) |
Finds the first element in the sequence not equal to t .
find()
This is provided for homology with: std::find
, std::find_if_not
.
Referenced by cxxomfort::library::algorithm::find_not().
It cxxomfort::library::algorithm::find_if_not | ( | It | ini, |
It | fin, | ||
Pred | if_ | ||
) |
Finds the first element in the sequence not fitting predicate if_ .
find_if()
|
inline |
Finds a pair of elements that are out of place (ie.: the second one is "less" than the first).
For example, for the following example find_inversion
will return an iterator pointing to the element 6:
See also: fix_inversion()
.
Referenced by cxxomfort::library::algorithm::find_inversion(), and cxxomfort::library::algorithm::fix_inversion().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Fixes a pair of misplaced elements where the second one is "less" than the first.
See also: find_inversion()
.
Referenced by cxxomfort::library::algorithm::fix_inversion().
Iter cxxomfort::library::algorithm::find_last_if | ( | Iter | ini, |
Iter | fin, | ||
Pred | if_ | ||
) |
Finds the latest item in a sequence that fits predicate if_
.
ini,fin | Delimiters to the sequence to be examined. |
if_ | A predicate (a function from ini...fin's alue type to bool ). |
std::iterator_traits<InputIterator>::difference_type cxxomfort::library::algorithm::count_while | ( | InputIterator | first, |
InputIterator | last, | ||
UnaryPredicate | pred | ||
) |
count_while proposal https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-proposals/bXrQrkBw59c
Referenced by cxxomfort::library::algorithm::count_while().
FIter cxxomfort::library::algorithm::transform_inplace | ( | FIter | ini, |
FIter | fin, | ||
TF | tf | ||
) |
Transform elements in the range in-place via the transformation tf .
ini,fin | Iterators marking a writable sequence. |
tf | A transformation of the form TF(value_type) → value_type . |
Referenced by cxxomfort::library::algorithm::transform_inplace().
FIter cxxomfort::library::algorithm::transform_inplace_if | ( | FIter | ini, |
FIter | fin, | ||
TF | tf, | ||
P | p | ||
) |
Transform elements in the range conditionally.
ini,fin | Iterators marking a writable sequence. |
tf | A transformation of the form TF(*FIter) -> *FIter . |
p | a predicate to decide if the elements need transformation. |
This is provided for homology with: std::copy_if
Referenced by cxxomfort::library::algorithm::transform_inplace_if().
|
inline |
Transform elements up to n times.
tf | A transformation of the form TF(*FIter) -> *FIter . |
This is provided for homology with: std::copy_n
.
Referenced by cxxomfort::library::algorithm::transform_n().
Iterator cxxomfort::library::algorithm::count_frequencies_map | ( | Iterator | ini, |
Iterator | fin, | ||
ValueMapIterator | vi, | ||
Reductor const | rint | ||
) |
Constructs a map of frequencies each element appears in the sequence.
Given a sequence S=[ini,fin), and a map vi of elements of type X with an associated mapping function rint such that:
Then it iterates over S and increments the value at vi+f(x)
.
Referenced by cxxomfort::library::algorithm::count_frequencies_map().
void cxxomfort::library::algorithm::lfv2::erase | ( | Container & | C, |
typename Container::value_type const & | u | ||
) |
Invokes erase-remove idiom on a container to remove element u as per remove()
.
C | a container object (lvalue). |
u | the value to pass to C.remove() . |
exception | Whatever the expression C.erase(...) throws. |
Referenced by cxxomfort::library::algorithm::lfv2::erase().
void cxxomfort::library::algorithm::lfv2::erase_if | ( | Container & | C, |
Pred | if_ | ||
) |
Invokes erase-remove idiom on a container to remove elements conditionally given predicate if_ as per remove_if()
.
C | a container object (lvalue). |
if_ | A predicate to pass to C.remove_if() . |
exception | Whatever the expression C.erase(...) throws. |
Referenced by cxxomfort::library::algorithm::lfv2::erase_if().