From cab01e8ba3d34344f7a7780843ea79e2a89f99b1 Mon Sep 17 00:00:00 2001
From: Neil Groves
- Three types of objects are currently supported by the library:
-
- Please also see Range concepts for more details.
-
-
-
-
-
-
-
-
-
-
- Boost.Range
- Synopsis and Reference
-
-
-
-
-
- Overview
-
-
- Even though the behavior of the primary templates are exactly such that
- standard containers will be supported by default, the requirements are much
- lower than the standard container requirements. For example, the utility class
- std::pair<iterator,iterator>
- iterator_range
implements the minimal
- interface required to make the class a Forward
- Range
- .
-
- Synopsis
-
-namespace boost
-{
- //
- // Single Pass Range metafunctions
- //
-
- template< class T >
- struct range_iterator;
-
- template< class T >
- struct range_value;
-
- template< class T >
- struct range_reference;
-
- template< class T >
- struct range_pointer;
-
- template< class T >
- struct range_category;
-
- //
- // Forward Range metafunctions
- //
-
- template< class T >
- struct range_difference;
-
- //
- // Bidirectional Range metafunctions
- //
-
- template< class T >
- struct range_reverse_iterator;
-
- //
- // Single Pass Range functions
- //
-
- template< class T >
- typename range_iterator<T>::type
- begin( T& r );
-
- template< class T >
- typename range_iterator<const T>::type
- begin( const T& r );
-
- template< class T >
- typename range_iterator<T>::type
- end( T& r );
-
- template< class T >
- typename range_iterator<const T>::type
- end( const T& r );
-
- template< class T >
- bool
- empty( const T& r );
-
- //
- // Forward Range functions
- //
-
- template< class T >
- typename range_difference<T>::type
- distance( const T& r );
-
- //
- // Bidirectional Range functions
- //
-
- template< class T >
- typename range_reverse_iterator<T>::type
- rbegin( T& r );
-
- template< class T >
- typename range_reverse_iterator<const T>::type
- rbegin( const T& r );
-
- template< class T >
- typename range_reverse_iterator<T>::type
- rend( T& r );
-
- template< class T >
- typename range_reverse_iterator<const T>::type
- rend( const T& r );
-
- //
- // Random Access Range functions
- //
-
- template< class T >
- typename range_difference<T>::type
- size( const T& r );
-
- //
- // Special const Range functions
- //
-
- template< class T >
- typename range_iterator<const T>::type
- const_begin( const T& r );
-
- template< class T >
- typename range_iterator<const T>::type
- const_end( const T& r );
-
- template< class T >
- typename range_reverse_iterator<const T>::type
- const_rbegin( const T& r );
-
- template< class T >
- typename range_reverse_iterator<const T>::type
- const_rend( const T& r );
-
- //
- // String utilities
- //
-
- template< class T >
- iterator_range<...see below...>
- as_literal( T& r );
-
- template< class T >
- iterator_range<...see below...>
- as_literal( const T& r );
-
- template< class T >
- iterator_range< typename range_iterator<T>::type >
- as_array( T& r );
-
- template< class T >
- iterator_range< typename range_iterator<const T>::type >
- as_array( const T& r );
-
-} // namespace 'boost'
-
-
-
-
- Semantics
- notation
-
-
-
-
-
- Type
-
- Object
-
- Describes
-
- X
- x
- any type
-
-
-
- T
- t
- denotes behavior of the primary templates
-
- P
- p
- denotes
- std::pair<iterator,iterator>
-
- A[sz]
- a
- denotes an array of type A
of size sz
-
-
- Char*
- s
- denotes either
- char*
or wchar_t*
- Please notice in tables below that when four lines appear in a cell, the first - line will describe the primary template, the second line pairs of iterators, - the third line arrays and the last line null-terminated strings. -
--
-
- The special const_
-named functions are useful when you
- want to document clearly that your code is read-only.
-
- as_literal()
can be used internally in string
- algorithm librararies such that arrays of characters are
- handled correctly.
-
- as_array()
can be used with string algorithm libraries to make it clear that arrays of characters are handled like an array and not like a string.
-
Notice that the above functions should always be called with
- qualification (boost::
) to prevent unintended
- Argument Dependent Lookup (ADL).
-
- This procedure assumes that you have control over the types that should be made - conformant to a Range concept. If not, see method 2. -
- -
- The primary templates in this library are implemented such that standard
- containers will work automatically and so will boost::array
.
- Below is given an overview of which member functions and member types a class
- must specify to be useable as a certain Range concept.
-
-
- Member function | -- Related concept | -
---|---|
begin() |
- Single Pass Range | -
end()
- |
- Single Pass Range | -
- Notice that rbegin()
and rend()
member functions are
- not needed even though the container can support bidirectional iteration.
-
- The required member types are: -
--
- Member type | -- Related concept | -
---|---|
iterator |
- Single Pass Range | -
const_iterator |
- Single Pass Range | -
- Again one should notice that member types reverse_iterator
and const_reverse_iterator
- are not needed.
-
- This procedure assumes that you cannot (or do not wish to) change the types that should be made - conformant to a Range concept. If this is not true, see method 1. -
- -
- The primary templates in this library are implemented such that
- certain functions are found via argument-dependent-lookup (ADL).
- Below is given an overview of which free-standing functions a class
- must specify to be useable as a certain Range concept.
- Let x
be a variable (const
or mutable)
- of the class in question.
-
-
- Function | -- Related concept | -
---|---|
range_begin(x) |
- Single Pass Range | -
range_end(x)
- |
- Single Pass Range | -
range_begin()
and range_end()
must be
- overloaded for both const
and mutable reference arguments.
-
- You must also specialize two metafunctions for your type X
:
-
-
- Metafunction | -- Related concept | -
---|---|
boost::range_mutable_iterator |
- Single Pass Range | -
boost::range_const_iterator |
- Single Pass Range | -
- A complete example is given here: -
--- --#include <boost/range.hpp> -#include <iterator> // for std::iterator_traits, std::distance() - -namespace Foo -{ - // - // Our sample UDT. A 'Pair' - // will work as a range when the stored - // elements are iterators. - // - template< class T > - struct Pair - { - T first, last; - }; - -} // namespace 'Foo' - -namespace boost -{ - // - // Specialize metafunctions. We must include the range.hpp header. - // We must open the 'boost' namespace. - // - - template< class T > - struct range_mutable_iterator< Foo::Pair<T> > - { - typedef T type; - }; - - template< class T > - struct range_const_iterator< Foo::Pair<T> > - { - // - // Remark: this is defined similar to 'range_mutable_iterator' - // because the 'Pair' type does not distinguish - // between an iterator and a const_iterator. - // - typedef T type; - }; - -} // namespace 'boost' - -namespace Foo -{ - // - // The required functions. These should be defined in - // the same namespace as 'Pair', in this case - // in namespace 'Foo'. - // - - template< class T > - inline T range_begin( Pair<T>& x ) - { - return x.first; - } - - template< class T > - inline T range_begin( const Pair<T>& x ) - { - return x.first; - } - - template< class T > - inline T range_end( Pair<T>& x ) - { - return x.last; - } - - template< class T > - inline T range_end( const Pair<T>& x ) - { - return x.last; - } - -} // namespace 'Foo' - -#include <vector> - -int main() -{ - typedef std::vector<int>::iterator iter; - std::vector<int> vec; - Foo::Pair<iter> pair = { vec.begin(), vec.end() }; - const Foo::Pair<iter>& cpair = pair; - // - // Notice that we call 'begin' etc with qualification. - // - iter i = boost::begin( pair ); - iter e = boost::end( pair ); - i = boost::begin( cpair ); - e = boost::end( cpair ); - boost::range_difference< Foo::Pair<iter> >::type s = boost::size( pair ); - s = boost::size( cpair ); - boost::range_reverse_iterator< const Foo::Pair<iter> >::type - ri = boost::rbegin( cpair ), - re = boost::rend( cpair ); -} --
- © Copyright Thorsten Ottosen 2008. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt) -
-![]() |
- Boost.Range |
-
counting_range
- The intention of the counting_range
function is to construct
- a new range with iterators that are wrapped in a
- counting_iterator
(from Boost.Iterator)
-
namespace boost -{ - template< class Incrementable > inline - range< counting_iterator<Incrementable> > - counting_range(Incrementable first, Incrementable last); - - template< class SinglePassRange > inline - range< counting_iterator<typename range_iterator<SinglePassRange>::type > - counting_range(const Range& rng); - - template< class SinglePassRange > inline - range< counting_iterator<typename range_iterator<SinglePassRange>::type > - counting_range(Range& rng); - -} // namespace 'boost' -- -
- © Copyright Neil Groves 2009. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy - at www.boost.org/LICENSE_1_0.txt) -
- -![]() |
- Boost.Range |
-
- Some examples are given in the accompanying test files: -
-string.cpp
-
- shows how to implement a container version of std::find()
that
- works with char[],wchar_t[],char*,wchar_t*.
- algorithm_example.cpp
-
-
- shows the replace example from the introduction.
- - © Copyright Thorsten Ottosen 2008. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt) -
- -![]() |
- Boost.Range |
-
-
range_iterator<C>::type
- and range_const_iterator<C>::type
for std::pair<iterator, iterator>
.
-
-
- In general it is not possible nor desirable to find a corresponding const_iterator
.
- When it is possible to come up with one, the client might choose to construct a std::pair<const_iterator,const_iterator>
- object.
-
- Note that an iterator_range
- is somewhat more convenient than a pair
and that a sub_range
does
- propagate const-ness.
- The library has been kept small because its current interface will - serve most - purposes. If and when a genuine need arises for more functionality, it can be - implemented. -
-- One should always start with a generic algorithm that takes two iterators (or - more) as input. Then use Boost.Range to build handier versions on top of the - iterator based algorithm. Please notice that once the range version of the - algorithm is done, it makes sense not to expose the iterator version in - the public interface. -
-- Even though we speak of incrementable iterators, it would not make - much sense for ranges; for example, we cannot determine the size and - emptiness of a range since we cannot even compare - its iterators. -
-- Note also that incrementable iterators are derived from output - iterators and so there exist no output range. -
-- © Copyright Thorsten Ottosen 2008. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy - at www.boost.org/LICENSE_1_0.txt) -
- -![]() |
- Boost.Range |
-
-
Header | -Includes | -Related concept | -
---|---|---|
<boost/range.hpp> |
- everything | -- | -
<boost/range/metafunctions.hpp> |
- every metafunction | -- | -
<boost/range/functions.hpp> |
- every function | -- | -
<boost/range/value_type.hpp> |
- range_value | -Single Pass Range | -
<boost/range/iterator.hpp> |
- range_iterator | -Single Pass Range | -
<boost/range/mutable_iterator.hpp> |
- range_mutable_iterator | -Single Pass Range | -
<boost/range/const_iterator.hpp> |
- range_const_iterator | -Single Pass Range | -
<boost/range/difference_type.hpp> |
- range_difference | -Forward Range | -
<boost/range/pointer.hpp> |
- range_pointer | -- | -
<boost/range/category.hpp> |
- range_category | -- | -
<boost/range/reverse_iterator.hpp> |
- range_reverse_iterator | -Bidirectional Range | -
<boost/range/begin.hpp> |
- - begin and - const_begin - | -Single Pass Range | -
<boost/range/end.hpp> |
- - end and - const_end - | -Single Pass Range | -
<boost/range/empty.hpp> |
- empty | -Single Pass Range | -
<boost/range/distance.hpp> |
- distance | -Forward Range | -
<boost/range/size.hpp> |
- size | -Random Access Range - | -
<boost/range/rbegin.hpp> |
- - rbegin and - const_rbegin - | -Bidirectional Range | -
<boost/range/rend.hpp> |
- - rend and - const_rend - | -Bidirectional Range | -
<boost/range/as_array.hpp> |
- - as_array - | -- | -
<boost/range/as_literal.hpp> |
- - as_literal - | -- | -
<boost/range/iterator_range.hpp> |
- iterator_range | -- | -
<boost/range/sub_range.hpp> |
- sub_range | -- | -
<boost/range/concepts.hpp> |
- concept checks | -- | -
- © Copyright Thorsten Ottosen 2008. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy - at www.boost.org/LICENSE_1_0.txt) -
- -![]() |
- Boost.Range |
-
- The library was under way for a long time. Dietmar Kühl originally intended
- to submit an array_traits
class template which had most of
- the functionality present now, but only for arrays and standard containers.
- I believe this was back in 2001 or 2002.
-
- Meanwhile work on algorithms for containers in various contexts showed the - need for handling pairs of iterators, and string libraries needed special - treatment of character arrays. In the end it made sense to formalize the - minimal requirements of these similar concepts. And the results are the - Range concepts found in this library.
- -
- The term Range was adopted because of paragraph 24.1/7
from the
-C++ standard:
- Most of the library's algorithmic templates that operate on data - structures have interfaces that use ranges. A range is a pair of - iterators that designate the beginning and end of the computation. A - range [i, i) is an empty range; in general, a range [i, j) refers to - the elements in the data structure starting with the one pointed to - by i and up to but not including the one pointed to by j. Range [i, - j) is valid if and only if j is reachable from i. The result of the - application of functions in the library to invalid ranges is - undefined. -- -
- Special thanks goes to -
- The concept checks and their documentation was provided by Daniel Walker. - -
- © Copyright Thorsten Ottosen 2008. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy - at www.boost.org/LICENSE_1_0.txt) -
- -![]() |
-Home | -Libraries | -People | -FAQ | -More | -
- In its most simple form a Range Algorithm - (or range-based algorithm) is simply an iterator-based algorithm where - the two iterator arguments have been replaced by - one range argument. For example, we may write -
-- -
-#include <boost/range/algorithm.hpp> -#include <vector> - -std::vector<int> vec = ...; -boost::sort(vec); --
-
-- instead of -
-- -
-std::sort(vec.begin(), vec.end()); --
-
-- However, the return type of range algorithms is almost always different - from that of existing iterator-based algorithms. -
-
- One group of algorithms, like boost::sort()
, will simply return the same range so
- that we can continue to pass the range around and/or further modify it.
- Because of this we may write
-
boost:unique(boost::sort(vec)); --
- to first sort the range and then run unique()
on the sorted range.
-
- Algorithms like boost::unique()
- fall into another group of algorithms that return (potentially) narrowed
- views of the original range. By default boost::unique(rng)
returns the range [boost::begin(rng), found)
- where found
denotes the
- iterator returned by std::unique(boost::begin(rng), boost::end(rng))
-
- Therefore exactly the unique values can be copied by writing -
-boost::copy(boost::unique(boost::sort(vec)), - std::ostream_iterator<int>(std::cout)); --
-
-
- Algorithms like boost::unique
usually return the same range:
- [boost::begin(rng), found)
. However, this behaviour may be changed
- by supplying the algorithms with a template argument:
-
- - Expression - - |
-
- - Return - - |
-
---|---|
-
- |
-
-
- returns a single iterator like |
-
-
- |
-
-
- returns the range |
-
-
- |
-
-
- returns the range |
-
-
- |
-
-
- returns the range |
-
-
- |
-
-
- returns the range |
-
-
- |
-
- - returns the entire original range. - - |
-
- This functionality has the following advantages: -
-- For example, consider how easy we may erase the duplicates in a sorted - container: -
-- -
-std::vector<int> vec = ...; -boost::erase(vec, boost::unique<boost::return_found_end>(boost::sort(vec))); --
-
-
- Notice the use of boost::return_found_end
.
- What if we wanted to erase all the duplicates except one of them? In old-fashined
- STL-programming we might write
-
- -
-// assume 'vec' is already sorted -std::vector<int>::iterator i = std::unique(vec.begin(), vec.end()); - -// remember this check or you get into problems -if (i != vec.end()) - ++i; - -vec.erase(i, vec.end()); --
-
-- The same task may be accomplished simply with -
-boost::erase(vec, boost::unique<boost::return_next_end>(vec)); --
- and there is no need to worry about generating an invalid range. Furthermore,
- if the container is complex, calling vec.begin()
several times will be more expensive
- than using a range algorithm.
-
- | - |
![]() |
-Home | -Libraries | -People | -FAQ | -More | -
- | - |
![]() |
-Home | -Libraries | -People | -FAQ | -More | -
- -
-template<class SinglePassRange, class OutputIterator> -OutputIterator copy(const SinglePassRange& source_rng, OutputIterator out_it); --
-
-
- copy
copies all elements
- from source_rng
to the
- range [out_it, out_it
- + distance(source_rng))
. The return value is out_it +
- distance(source_rng)
-
- Defined in the header file boost/range/algorithm/copy.hpp
-
SinglePassRange
is
- a model of the SinglePassRangeConcept
.
- OutputIterator
is a
- model of the OutputIteratorConcept
.
- value_type
of
- SinglePassRange
is
- convertible to a type in OutputIterator
's
- set of value types.
- out_it
is not an iterator
- within the source_rng
.
- [out_it, out_it
- + distance(source_rng))
is a valid range.
-
- Linear. Exactly distance(source_rng)
assignments are performed.
-
- | - |
![]() |
-Home | -Libraries | -People | -FAQ | -More | -
- -
-template<class BidirectionalRange, class BidirectionalOutputIterator> - BidirectionalOutputIterator - copy_backward(const BidirectionalRange& source_rng, - BidirectionalOutputIterator out_it); --
-
-
- copy_backward
copies
- all elements from source_rng
- to the range [out_it
- - distance(source_rng), out_it)
.
-
- The values are copied in reverse order. The return value is out_it -
- distance(source_rng)
.
-
- Note well that unlike all other standard algorithms out_it
- denotes the end of the output sequence.
-
- Defined in the header file boost/range/algorithm/copy_backward.hpp
-
BidirectionalRange
- is a model of the SinglePassRangeConcept
.
- OutputIterator
is a
- model of the OutputIteratorConcept
.
- value_type
of
- SinglePassRange
is
- convertible to a type in OutputIterator
's
- set of value types.
- out_it
is not an iterator
- within the source_rng
.
- [out_it, out_it
- + distance(source_rng))
is a valid range.
-
- Linear. Exactly distance(source_rng)
assignments are performed.
-
- | - |
![]() |
-Home | -Libraries | -People | -FAQ | -More | -
- | - |
![]() |
-Home | -Libraries | -People | -FAQ | -More | -
- | - |
![]() |
- Boost.Range |
-
- 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 we are used to work with is standard library - containers. However, one - often finds it desirable to extend that code to work with 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. -
- -
- This library therefore provides the means to adapt standard-like
- containers, 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 -
Below is given a small example (the complete example can be found here):
-- - By using the free-standing functions and metafunctions, the code automatically - works for all the types supported by this library; now and in the future. -Notice that we have to - provide two version of- - // - // example: extracting bounds in a generic algorithm - // - template< class ForwardReadableRange, class T > - inline typename boost::range_iterator< ForwardReadableRange >::type - find( ForwardReadableRange& c, const T& value ) - { - return std::find( boost::begin( c ), boost::end( c ), value ); - } - - template< class ForwardReadableRange, class T > - inline typename boost::range_iterator< const ForwardReadableRange >::type - find( const ForwardReadableRange& c, const T& value ) - { - return std::find( boost::begin( c ), boost::end( c ), value ); - } - - // - // replace first value and return its index - // - template< class ForwardReadableWriteableRange, class T > - inline typename boost::range_difference< ForwardReadableWriteableRange >::type - my_generic_replace( ForwardReadableWriteableRange& c, const T& value, const T& replacement ) - { - typename boost::range_iterator< ForwardReadableWriteableRange >::type found = find( c, value ); - - if( found != boost::end( c ) ) - *found = replacement; - return std::distance( boost::begin( c ), found ); - } - - // - // usage - // - const int N = 5; - std::vector<int> my_vector; - int values[] = { 1,2,3,4,5,6,7,8,9 }; - - my_vector.assign( values, boost::end( values ) ); - typedef std::vector<int>::iterator iterator; - std::pair<iterator,iterator> my_view( boost::begin( my_vector ), - boost::begin( my_vector ) + N ); - char str_val[] = "a string"; - char* str = str_val; - - std::cout << my_generic_replace( my_vector, 4, 2 ); - std::cout << my_generic_replace( my_view, 4, 2 ); - std::cout << my_generic_replace( str, 'a', 'b' ); - - // prints '3', '5' and '0' --
find()
since we cannot forward a non-const
- rvalue with reference arguments (see this article about The
- Forwarding Problem ).
-
-
-
-
- - © Copyright Thorsten Ottosen 2008. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy - at www.boost.org/LICENSE_1_0.txt) -
- -![]() |
- Boost.Range |
-
istream_range
- The intention of the istream_range
function is to construct
- a new range with a pair of std::istream_iterator
s that wrap a
- specified std::basic_istream
instance.
-
-namespace boost -{ - template< class - Type, class - Elem, class Traits > inline - range< std::istream_iterator<Type, Elem, Traits> > - istream_range(std::basic_istream<Elem, Traits>& in); -}- -
- © Copyright Neil Groves 2009. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy - at www.boost.org/LICENSE_1_0.txt) -
- -Author: | -Shunsuke Sogame |
---|---|
Contact: | -mb2act@yahoo.co.jp |
Date: | -26th of May 2006 |
Copyright: | -Shunsuke Sogame 2005-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt). |
Boost.Range MFC/ATL Extension provides Boost.Range support for MFC/ATL collection and string types.
--CTypedPtrArray<CPtrArray, CList<CString> *> myArray; -... -BOOST_FOREACH (CList<CString> *theList, myArray) -{ - BOOST_FOREACH (CString& str, *theList) - { - boost::to_upper(str); - std::sort(boost::begin(str), boost::end(str)); - ... - } -} -- -
If the <boost/range/mfc.hpp> is included before or after Boost.Range headers, -the MFC collections and strings become models of Range. -The table below lists the Traversal Category and range_reference of MFC ranges.
-Range | -Traversal Category | -range_reference<Range>::type | -
---|---|---|
CArray<T,A> | -Random Access | -T& | -
CList<T,A> | -Bidirectional | -T& | -
CMap<K,AK,M,AM> | -Forward | -Range::CPair& | -
CTypedPtrArray<B,T*> | -Random Access | -T* const | -
CTypedPtrList<B,T*> | -Bidirectional | -T* const | -
CTypedPtrMap<B,T*,V*> | -Forward | -std::pair<T*,V*> const | -
CByteArray | -Random Access | -BYTE& | -
CDWordArray | -Random Access | -DWORD& | -
CObArray | -Random Access | -CObject* & | -
CPtrArray | -Random Access | -void* & | -
CStringArray | -Random Access | -CString& | -
CUIntArray | -Random Access | -UINT& | -
CWordArray | -Random Access | -WORD& | -
CObList | -Bidirectional | -CObject* & | -
CPtrList | -Bidirectional | -void* & | -
CStringList | -Bidirectional | -CString& | -
CMapPtrToWord | -Forward | -std::pair<void*,WORD> const | -
CMapPtrToPtr | -Forward | -std::pair<void*,void*> const | -
CMapStringToOb | -Forward | -std::pair<String,CObject*> const | -
CMapStringToString | -Forward | -Range::CPair& | -
CMapWordToOb | -Forward | -std::pair<WORD,CObject*> const | -
CMapWordToPtr | -Forward | -std::pair<WORD,void*> const | -
Other Boost.Range metafunctions are defined by the following. -Let Range be any type listed above and ReF be the same as range_reference<Range>::type. -range_value<Range>::type is the same as remove_reference<remove_const<Ref>::type>::type, -range_difference<Range>::type is the same as std::ptrdiff_t, and -range_pointer<Range>::type is the same as add_pointer<remove_reference<Ref>::type>::type. -As for const Range, see const Ranges.
-If the <boost/range/atl.hpp> is included before or after Boost.Range headers, -the ATL collections and strings become models of Range. -The table below lists the Traversal Category and range_reference of ATL ranges.
-Range | -Traversal Category | -range_reference<Range>::type | -
---|---|---|
CAtlArray<E,ET> | -Random Access | -E& | -
CAutoPtrArray<E> | -Random Access | -E& | -
CInterfaceArray<I,pi> | -Random Access | -CComQIPtr<I,pi>& | -
CAtlList<E,ET> | -Bidirectional | -E& | -
CAutoPtrList<E> | -Bidirectional | -E& | -
CHeapPtrList<E,A> | -Bidirectional | -E& | -
CInterfaceList<I,pi> | -Bidirectional | -CComQIPtr<I,pi>& | -
CAtlMap<K,V,KT,VT> | -Forward | -Range::CPair& | -
CRBTree<K,V,KT,VT> | -Bidirectional | -Range::CPair& | -
CRBMap<K,V,KT,VT> | -Bidirectional | -Range::CPair& | -
CRBMultiMap<K,V,KT,VT> | -Bidirectional | -Range::CPair& | -
CSimpleStringT<B,b> | -Random Access | -B& | -
CStringT<B,ST> | -Random Access | -B& | -
CFixedStringT<S,n> | -Random Access | -range_reference<S>::type | -
CStringT<B,ST> | -Random Access | -B& | -
CComBSTR | -Random Access | -OLECHAR& | -
CSimpleArray<T,TE> | -Random Access | -T& | -
Other Boost.Range metafunctions are defined by the following. -Let Range be any type listed above and ReF be the same as range_reference<Range>::type. -range_value<Range>::type is the same as remove_reference<Ref>::type, -range_difference<Range>::type is the same as std::ptrdiff_t, and -range_pointer<Range>::type is the same as add_pointer<remove_reference<Ref>::type>::type. -As for const Range, see const Ranges.
-range_reference<const Range>::type is defined by the following algorithm. -Let Range be any type listed above and ReF be the same as range_reference<Range>::type.
--if (Range is CObArray || Range is CObList) - return CObject const * & -else if (Range is CPtrArray || Range is CPtrList) - return void const * & -else if (there is a type X such that X& is the same as ReF) - return X const & -else if (there is a type X such that X* const is the same as ReF) - return X const * const -else - return ReF --
Other Boost.Range metafunctions are defined by the following. -range_value<const Range>::type is the same as range_value<Range>::type, -range_difference<const Range>::type is the same as std::ptrdiff_t, and -range_pointer<const Range>::type is the same as add_pointer<remove_reference<range_reference<const Range>::type>::type>::type.
-![]() |
- Boost.Range |
-
- A huge effort has been made to port the library to as many compilers as possible. -
- -- Full support for built-in arrays require that the compiler supports class - template partial specialization. For non-conforming compilers there might be a - chance that it works anyway thanks to workarounds in the type traits library. -
-Visual C++ 6/7.0 has a limited support for arrays: as long as the arrays - are of built-in type it should work. -
-
- Notice also that some compilers cannot do function template ordering properly.
- In that case one must rely on range_iterator
- and a single function definition instead of overloaded versions for const and
- non-const arguments.
-
- So if one cares about old compilers, one should not pass rvalues to the
- functions.
-
- For maximum portability you should follow these guidelines: - -
begin()
, end()
and
- iterator_range
Range constructors and assignment operators,
- const_begin()
- and const_end()
- whenever your code by intention is read-only; this will also solve
- most rvalue problems,
- boost
.
- - © Copyright Thorsten Ottosen 2008. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy - at www.boost.org/LICENSE_1_0.txt) -
> - -![]() |
- Boost.Range |
-
- A Range is a concept similar to the STL Container concept. A
- Range provides iterators for accessing a half-open range
-[first,one_past_last)
of elements and provides
- information about the number of elements in the Range. However, a Range has
- much fewer requirements than a Container.
-
- The motivation for the Range concept is - that there are many useful Container-like types that do not meet the full - requirements of Container, and many algorithms that can be written with this - reduced set of requirements. In particular, a Range does not necessarily - -
- The operations that can be performed on a Range is dependent on the - traversal -category of the underlying iterator type. Therefore - the range concepts are named to reflect which traversal category their - iterators support. See also terminology and style - guidelines. for more information about naming of ranges.
- -The concepts described below specifies associated types as -metafunctions and all -functions as free-standing functions to allow for a layer of indirection.
- - - -X |
- A type that is a model of Single Pass Range. | -
a |
- Object of type X . |
-
- A range X where boost::range_iterator<X>::type
is a model of
-Single Pass Iterator
-
-
Iterator type | -boost::range_iterator<X>::type |
- The type of iterator used to iterate through a Range's elements. - The iterator's value type is expected to be the Range's value type. A - conversion from the iterator type to the const iterator type must exist. - |
Const iterator type | -boost::range_iterator<const X>::type |
- A type of iterator that may be used to examine, but not to - modify, a Range's elements. | -
- -
Name | -Expression | -Return type | -
---|---|---|
Beginning of range | -boost::begin(a) |
- boost::range_iterator<X>::type if
-a is mutable, boost::range_iterator<const X>::type
-otherwise |
End of range | -boost::end(a) |
- boost::range_iterator<X>::type if
-a is mutable, boost::range_iterator<const X>::type
-otherwise |
-
Expression | -Semantics | -Postcondition | -
---|---|---|
boost::begin(a) |
- Returns an iterator pointing to the first element in the Range. | -boost::begin(a) is either dereferenceable or past-the-end.
- It is past-the-end if and only if boost::distance(a) == 0 . |
-
boost::end(a) |
- Returns an iterator pointing one past the last element in the - Range. | -boost::end(a) is past-the-end. |
-
boost::end(a)
is at most amortized linear time, boost::begin(a)
is
- amortized constant time. For most practical
- purposes, one can expect both to be amortized constant time.
-
- Valid range | -For any Range a , [boost::begin(a),boost::end(a)) is
- a valid range, that is, boost::end(a) is reachable from boost::begin(a)
- in a finite number of increments. |
-
Completeness | -An algorithm that iterates through the range [boost::begin(a),boost::end(a))
- will pass through every element of a . |
-
Extending the library for UDTs
-Implementation of - metafunctions
- - -- Container -
- - -X |
- A type that is a model of Forward Range. | -
a |
- Object of type X . |
-
- A range X
where boost::range_iterator<X>::type
is a model
-of Forward Traversal Iterator
-
X |
- A type that is a model of Bidirectional Range. | -
a |
- Object of type X . |
-
boost::range_iterator<X>::type
iterator must meet all of the requirements
-of Bidirectional Traversal Iterator.
-
-
- A range X
where boost::range_iterator<X>::type
is a model
-of Random Access Traversal Iterator
-
<boost/range/concepts.hpp>
. These classes may be
- used in conjunction with the Boost Concept
- Check library to insure that the type of a template parameter
- is compatible with a range concept. If not, a meaningful compile
- time error is generated. Checks are provided for the range
- concepts related to iterator traversal categories. For example,
- the following line checks that the type T
models the
- ForwardRange concept.
-
- - function_requires<ForwardRangeConcept<T> >(); -- - An additional concept check is required for the value access - property of the range based on the range's iterator type. For - example to check for a ForwardReadableRange, the following code is - required. - -
- function_requires<ForwardRangeConcept<T> >(); - function_requires< - ReadableIteratorConcept< - typename range_iterator<T>::type - > - >(); -- - The following range concept checking classes are provided. -
SinglePassRangeConcept
checks for Single Pass Range
- ForwardRangeConcept
checks for Forward Range
- BidirectionalRangeConcept
checks for Bidirectional Range
- RandomAccessRangeConcept
checks for Random Access Range
- Range Terminology and style guidelines
- - - -- © Copyright Thorsten Ottosen 2008. -
- -- Distributed under the Boost Software License, Version 1.0. (See - accompanying file LICENSE_1_0.txt or copy - at www.boost.org/LICENSE_1_0.txt) -
-