User:Cooky/ranges

The ranges library is an extension and generalization of the algorithms and iterator libraries that makes them more powerful by making them composable and less error-prone.

The library creates and manipulates range views, lightweight objects that indirectly represent iterable sequences (ranges). Ranges are an abstraction on top of
 * [begin, end) iterator pairs, e.g. ranges made by implicit conversion from containers. All algorithms that take iterator pairs now have overloads that accept ranges (e.g )
 * [start, size) counted sequences, e.g. range returned by
 * [start, predicate) conditionally-terminated sequences, e.g. range returned by
 * [start..) unbounded sequences, e.g. range returned by

The ranges library includes range algorithms, which are applied to ranges eagerly, and range adaptors, which are applied to views lazily. Adaptors can be composed into pipelines, so that their actions take place as the view is iterated.

The namespace alias is provided as a shorthand for.

Range adaptor closure objects
Range adaptor closure objects are objects whose type is the same as one of the following objects (ignoring cv-qualification):
 * unary range adaptor objects,


 * the results of binding trailing arguments by range adaptor objects, and
 * the results of chaining two range adaptor closure objects by.

Range adaptor closure objects take one  as its only argument. They are callable via the pipe operator: if is a range adaptor closure object and  is a , these two expressions are equivalent (both well-formed or ill-formed):

This call forwards the bound arguments (if any) to the associated range adaptor object. The bound arguments (if any) are identically treated as lvalue or rvalue and cv-qualified to.

Two range adaptor closure objects can be chained by to produce another range adaptor closure object: if  and  are range adaptor closure objects, then  is also a range adaptor closure object if it is valid.

The bound arguments of is determined as follows:
 * there is a subobject in the result object of the same type (cv-qualification discarded) for every subobject in both operands that is a bound argument,
 * such a bound argument is direct-non-list-initialized with the source subobject in its containing operand, where the source is identically treated as lvalue or rvalue and cv-qualified to the operand,
 * the result is valid if and only if the initialization of all bound arguments are valid.

The effect and validity of the of the result is determined as follows: given a  , these two expressions are equivalent (both well-formed or ill-formed):

Notes: is unsupported for volatile-qualified or const-volatile-qualified version of range adaptor object closure types.

Range adaptor objects
Range adaptor objects are customization point objects that accept as their first arguments and return a. Some range adaptor objects are unary, i.e. they take one as their only argument. Other range adaptor objects take a and other trailing arguments.

If a range adaptor object takes more than one argument, it also supports partial application: let expression has following properties:
 * be such a range adaptor object, and
 * be arguments (generally suitable for trailing arguments),
 * it is valid if and only if for every argument in  such that  is,  is ,
 * when the call is valid, its result object stores a subobject of type direct-non-list-initialized with, for every argument  in  (in other words, range adaptor objects bind arguments by value), and
 * the result object is a range adaptor closure object.

Like other customization point objects, let calls to are all equivalent.
 * be an object of the cv-unqualified version of the type of any range adaptor objects,
 * be any group of arguments that satisfies the constraints of the of the type of ,
 * , and
 * , and
 * , and

The result object of each of these expressions is either a object or a range adaptor closure object.

Notes: is unsupported for volatile-qualified or const-volatile-qualified version of range adaptor object types. Arrays and functions are converted to pointers while binding.

Helper items
Following exposition-only items are used for several types and functions, but they are not parts of the interface of the standard library.