QueriesΒΆ

const auto find

Find the first element in a range that for which a predicate is true, or the empty range if the predicate is not true for any element.

find (predicate, range) is roughly defined as if (empty (range) || predicate (first (range))) return range; else return find (predicate, drop (range));

The complete parameter list is find (range, [direction,] predicate, [actor_non_empty, [actor_empty]]).

The additional first parameter is the direction. The actors are functions that are called with the range starting with the first element for which the predicate is true. If no actor is given, the range is returned. If one actor is given, it is called on the range and its return value called. If two actors are given, the first one is called if the range is non-empty and the second if the range is empty. The function then implements if (empty (range, direction)) return actor_empty (range); else if (predicate (first (range, direction))) return actor_non_empty (range); else return find (drop (range, direction), direction, predicate, actor_non_empty, actor_empty);

The recursion is implemented as an iteration if the range is homogeneous, to prevent stack overflows.

The first evaluation of the predicate to return true is the last to be evaluated.

The first evaluation of the predicate to return a true compile-time constant is the last to be instantiated.

Parameters
  • range -

    The range to find an element in.

  • direction -

    (optional) The direction to traverse the range in.

  • predicate -

    The function that is called with every element until it returns true.

  • actor_non_empty -

    (optional) The function that is called with the remaining range that starts with the first element that predicate returns true for. By default, the range itself is returned.

  • actor_empty -

    (optional) The function that is called with the empty range if predicate is not true for any element. By default, actor_non_empty is used.

const auto all_of

Return whether all elements of the range evaluate to true.

Written tersely, all_of (r) returns fold (r, &&, true).

If the result is known at compile time, a compile time constant is returned.

Short-circuiting is important. If any element is known at compile time to be false, then the following elements are not instantiated. If any element is found at run time to false, then the following elements are not evaluated.

const auto any_of

Return whether any elements of the range evaluate to true.

Written tersely, any_of (r) returns fold (||, false, r).

If the result is known at compile time, a compile time constant is returned.

Short-circuiting is important. If any element is known at compile time to be true, then the following elements are not instantiated. If any element is found at run time to true, then the following elements are not evaluated.

const auto equal

Compare two ranges for equality.

Return
true iff the two arguments have equal length and all elements compare equal.
Parameters
  • range1 -

    The first range to compare.

  • range2 -

    The second range to compare.

  • direction -

    (optional) Direction that should be used to traverse the ranges. If not given, the default direction of the first range is used.

  • predicate -

    (optional) Predicate to use to compare individual elements. If not given, then operator== is used.

const auto less_lexicographical

Compare two ranges lexicographically.

Return
true iff the left-hand side is ordered before the right-hand side in lexicographical ordering.
Parameters
  • range1 -

    The first range to compare.

  • range2 -

    The second range to compare.

  • direction -

    (optional) Direction that should be used to traverse the ranges. If not given, the default direction of the first range is used.

  • less -

    (optional) Predicate used for comparing individual elements. If not given, then operator== is used.

Previous topic

Utility

Next topic

Compile-time queries

This Page