3rdParty/boost/1.78.0/libs/range/doc/html/range/introduction.html
| | Home | Libraries | People | FAQ | More |
Generic algorithms have so far been specified in terms of two or more iterators. Two iterators would together form a range of values that the algorithm could work on. This leads to a very general interface, but also to a somewhat clumsy use of the algorithms with redundant specification of container names. Therefore we would like to raise the abstraction level for algorithms so they specify their interface in terms of Ranges as much as possible.
The most common form of ranges used throughout the C++ community are standard library containers. When writing algorithms however, one often finds it desirable for the algorithm to accept other types that offer enough functionality to satisfy the needs of the generic code if a suitable layer of indirection is applied. For example, raw arrays are often suitable for use with generic code that works with containers, provided a suitable adapter is used. Likewise, null terminated strings can be treated as containers of characters, if suitably adapted.
This library therefore provides the means to adapt standard-like containers, null terminated strings, std::pairs of iterators, and raw arrays (and more), such that the same generic code can work with them all. The basic idea is to add another layer of indirection using metafunctions and free-standing functions so syntactic and/or semantic differences can be removed.
The main advantages are
usingnamespaceboost;usingnamespaceboost::adaptors;for\_each(my\_map|map\_values,fn);
usingnamespaceboost;usingnamespaceboost::adaptors;for\_each(my\_map|map\_keys,fn);
target](introduction.html#range.introduction.example push_the_even_values_from_a_map_in_reverse_order_into_the_container code phrase_role identifier target phrase___code)usingnamespaceboost;usingnamespaceboost::adaptors;// Assume that is\_even is a predicate that has been implemented elsewhere...push\_back(target,my\_map|map\_values|filtered(is\_even())|reversed);
| | Copyright © 2003-2010 Thorsten Ottosen, Neil Groves
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|