Ase::Aux namespace

Auxillary algorithms brodly useful.

Functions

template <typename Value>
static auto compare_greater(const Value& v1, const Value& v2) →  int
Comparison function useful to sort greater items first.
template <typename Value>
static auto compare_lesser(const Value& v1, const Value& v2) →  int
Comparison function useful to sort lesser items first.
template <typename RandIter, class Cmp, typename Arg>
auto binary_lookup(RandIter begin, RandIter end, Cmp cmp_elements, const Arg& arg) →  RandIter
template <typename RandIter, class Cmp, typename Arg>
auto binary_lookup_insertion_pos(RandIter begin, RandIter end, Cmp cmp_elements, const Arg& arg) →  std::pair<RandIter, bool>
template <typename RandIter, class Cmp, typename Arg>
auto binary_lookup_sibling(RandIter begin, RandIter end, Cmp cmp_elements, const Arg& arg) →  RandIter
template <class Container, class Iteratable>
auto container_copy(const Iteratable& source) →  Container
Create a Container with copies of the elements of source.
template <typename C>
auto contains(const C& container, const std::function<bool(typename C::value_type const&value)>& pred) →  bool
Returns true if container element for which pred() is true.
template <class C>
auto erase_all(C& container, const std::function<bool(typename C::value_type const&value)>& pred) →  size_t
Erase all elements for which pred() is true in vector or list.
template <class C>
auto erase_first(C& container, const std::function<bool(typename C::value_type const&value)>& pred) →  size_t
Erase first element for which pred() is true in vector or list.
template <class T, class Compare>
auto insert_sorted(std::vector<T>& vec, const T& value, Compare compare) →  std::vector<T>::iterator
Insert value into sorted vec using binary_lookup_insertion_pos() with compare.

Function documentation

template <typename RandIter, class Cmp, typename Arg>
RandIter Ase::Aux::binary_lookup(RandIter begin, RandIter end, Cmp cmp_elements, const Arg& arg)

Perform binary lookup and yield exact match or end. The arguments [ begin, end [ denote the range used for the lookup, arg is passed along with the current element to the cmp_elements function.

template <typename RandIter, class Cmp, typename Arg>
std::pair<RandIter, bool> Ase::Aux::binary_lookup_insertion_pos(RandIter begin, RandIter end, Cmp cmp_elements, const Arg& arg)

Perform a binary lookup to find the insertion position for a new element. Return (end,false) for end-begin==0, or return (position,true) for exact match, otherwise return (position,false) where position indicates the location for the key to be inserted (and may equal end).

template <typename RandIter, class Cmp, typename Arg>
RandIter Ase::Aux::binary_lookup_sibling(RandIter begin, RandIter end, Cmp cmp_elements, const Arg& arg)

Perform a binary lookup to yield exact or nearest match. return end for end-begin==0, otherwise return the exact match element, or, if there's no such element, return the element last visited, which is pretty close to an exact match (will be one off into either direction).