From 0b0dfc0e06cb98efb2b8726fca80479b7ba9a68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Sch=C3=B6pflin?= Date: Thu, 4 Oct 2007 11:51:51 +0000 Subject: [PATCH 01/57] Added missing boost namespace reference to as_literal. [SVN r39683] --- test/string.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/string.cpp b/test/string.cpp index 9d4b252..9a2e5a8 100755 --- a/test/string.cpp +++ b/test/string.cpp @@ -33,28 +33,28 @@ template< class T > inline BOOST_DEDUCED_TYPENAME boost::range_iterator::type str_begin( T& r ) { - return boost::begin( as_literal(r) ); + return boost::begin( boost::as_literal(r) ); } template< class T > inline BOOST_DEDUCED_TYPENAME boost::range_iterator::type str_end( T& r ) { - return boost::end( as_literal(r) ); + return boost::end( boost::as_literal(r) ); } template< class T > inline BOOST_DEDUCED_TYPENAME boost::range_size::type str_size( const T& r ) { - return boost::size( as_literal(r) ); + return boost::size( boost::as_literal(r) ); } template< class T > inline bool str_empty( T& r ) { - return boost::empty( as_literal(r) ); + return boost::empty( boost::as_literal(r) ); } template< typename Container, typename T > From a862a573dfc2a15705f21af431253db4a2dd28b5 Mon Sep 17 00:00:00 2001 From: Nicola Musatti Date: Sun, 14 Oct 2007 17:53:15 +0000 Subject: [PATCH 02/57] Applied patch from Ticket #1320 [SVN r40020] --- include/boost/range/as_literal.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/include/boost/range/as_literal.hpp b/include/boost/range/as_literal.hpp index 0d6b946..72f0eb5 100755 --- a/include/boost/range/as_literal.hpp +++ b/include/boost/range/as_literal.hpp @@ -21,6 +21,9 @@ #include #include + +#include + #include #include @@ -104,15 +107,23 @@ namespace boost template< class Char, std::size_t sz > inline iterator_range as_literal( Char (&arr)[sz] ) { +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x590)) && __BORLANDC__ >= 0x590 + return boost::make_iterator_range( arr, arr + sz - 1 ); +#else return boost::make_iterator_range( arr, arr + sz - 1 ); +#endif } template< class Char, std::size_t sz > - inline iterator_range as_literal( const Char (&arr)[sz] ) + inline iterator_range as_literal( const Char (&arr)[sz] ) { +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x590)) && __BORLANDC__ >= 0x590 + return boost::make_iterator_range( arr, arr + sz - 1 ); +#else return boost::make_iterator_range( arr, arr + sz - 1 ); - } +#endif + } } #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING From c8ffe55ae507e6558d9dfef2bd69ca1b2bac2093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 18:36:03 +0000 Subject: [PATCH 03/57] added test for char array with nested null in response to Ticket #471 [SVN r40367] --- test/array.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/array.cpp b/test/array.cpp index db7054d..a83151c 100755 --- a/test/array.cpp +++ b/test/array.cpp @@ -62,6 +62,8 @@ void check_array() BOOST_CHECK_EQUAL( end( ca ), ca + size( ca ) ); BOOST_CHECK_EQUAL( empty( ca ),false ); + const char A[] = "\0A"; + BOOST_CHECK_EQUAL( boost::size(A), 3u ); } using boost::unit_test::test_suite; From 24466ae189cb2f2dcdad10e0d62ac8df52fbc2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 18:59:11 +0000 Subject: [PATCH 04/57] applied patch from Ticket #1302 (new Patches) to handle char arrays correctly [SVN r40370] --- test/iterator_range.cpp | 15 ++++++++------- test/sub_range.cpp | 17 +++++++++-------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/test/iterator_range.cpp b/test/iterator_range.cpp index 9f8d7b6..7854a92 100755 --- a/test/iterator_range.cpp +++ b/test/iterator_range.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -79,12 +80,12 @@ void check_iterator_range() BOOST_CHECK( rr.equal( r ) ); rr = make_iterator_range( str.begin(), str.begin() + 5 ); - BOOST_CHECK( rr == "hello" ); - BOOST_CHECK( rr != "hell" ); - BOOST_CHECK( rr < "hello dude" ); - BOOST_CHECK( "hello" == rr ); - BOOST_CHECK( "hell" != rr ); - BOOST_CHECK( ! ("hello dude" < rr ) ); + BOOST_CHECK( rr == as_literal("hello") ); + BOOST_CHECK( rr != as_literal("hell") ); + BOOST_CHECK( rr < as_literal("hello dude") ); + BOOST_CHECK( as_literal("hello") == rr ); + BOOST_CHECK( as_literal("hell") != rr ); + BOOST_CHECK( ! (as_literal("hello dude") < rr ) ); irange rrr = rr; BOOST_CHECK( rrr == rr ); BOOST_CHECK( !( rrr != rr ) ); @@ -96,7 +97,7 @@ void check_iterator_range() BOOST_CHECK_EQUAL( cr[1], 'e' ); rrr = make_iterator_range( str, 1, -1 ); - BOOST_CHECK( rrr == "ello worl" ); + BOOST_CHECK( rrr == as_literal("ello worl") ); rrr = make_iterator_range( rrr, -1, 1 ); BOOST_CHECK( rrr == str ); diff --git a/test/sub_range.cpp b/test/sub_range.cpp index ccc2a89..3694105 100755 --- a/test/sub_range.cpp +++ b/test/sub_range.cpp @@ -17,6 +17,7 @@ #endif #include +#include #include #include #include @@ -110,12 +111,12 @@ void check_sub_range() BOOST_CHECK( rr.equal( r ) ); rr = make_iterator_range( str.begin(), str.begin() + 5 ); - BOOST_CHECK( rr == "hello" ); - BOOST_CHECK( rr != "hell" ); - BOOST_CHECK( rr < "hello dude" ); - BOOST_CHECK( "hello" == rr ); - BOOST_CHECK( "hell" != rr ); - BOOST_CHECK( ! ("hello dude" < rr ) ); + BOOST_CHECK( rr == as_literal("hello") ); + BOOST_CHECK( rr != as_literal("hell") ); + BOOST_CHECK( rr < as_literal("hello dude") ); + BOOST_CHECK( as_literal("hello") == rr ); + BOOST_CHECK( as_literal("hell") != rr ); + BOOST_CHECK( ! (as_literal("hello dude") < rr ) ); irange rrr = rr; BOOST_CHECK( rrr == rr ); @@ -128,13 +129,13 @@ void check_sub_range() BOOST_CHECK_EQUAL( cr[1], 'e' ); rrr = make_iterator_range( str, 1, -1 ); - BOOST_CHECK( rrr == "ello worl" ); + BOOST_CHECK( rrr == as_literal("ello worl") ); rrr = make_iterator_range( rrr, -1, 1 ); BOOST_CHECK( rrr == str ); rrr.front() = 'H'; rrr.back() = 'D'; rrr[1] = 'E'; - BOOST_CHECK( rrr == "HEllo worlD" ); + BOOST_CHECK( rrr == as_literal("HEllo worlD") ); } #include From 33a8016af3627afcb166c8389b24e182f4e80ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 19:06:39 +0000 Subject: [PATCH 05/57] change names of ADL functions back to 1.34 names ... the old names have been in use for too long so let's not break code that depends on them [SVN r40371] --- test/extension_mechanism.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/extension_mechanism.cpp b/test/extension_mechanism.cpp index 2fd7929..828b5cd 100755 --- a/test/extension_mechanism.cpp +++ b/test/extension_mechanism.cpp @@ -57,24 +57,24 @@ namespace Foo // to be defined because X defines the proper set of // nested types. // - inline X::iterator range_begin( X& x ) + inline X::iterator boost_range_begin( X& x ) { return x.vec.begin(); } - inline X::const_iterator range_begin( const X& x ) + inline X::const_iterator boost_range_begin( const X& x ) { return x.vec.begin(); } - inline X::iterator range_end( X& x ) + inline X::iterator boost_range_end( X& x ) { return x.vec.end(); } - inline X::const_iterator range_end( const X& x ) + inline X::const_iterator boost_range_end( const X& x ) { return x.vec.end(); } From 028bff0c22a7b67c3d0fbc4e1e8afeaa310649b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 19:07:38 +0000 Subject: [PATCH 06/57] changed ADL functions back the names of 1.34 ... these names have been in use for too long ... let's not break code that depends on them [SVN r40372] --- include/boost/range/begin.hpp | 14 +++++++------- include/boost/range/end.hpp | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/boost/range/begin.hpp b/include/boost/range/begin.hpp index e8251c9..2f2cb3b 100755 --- a/include/boost/range/begin.hpp +++ b/include/boost/range/begin.hpp @@ -39,7 +39,7 @@ namespace range_detail template< typename C > inline BOOST_DEDUCED_TYPENAME range_iterator::type - range_begin( C& c ) + boost_range_begin( C& c ) { return c.begin(); } @@ -49,13 +49,13 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename Iterator > - inline Iterator range_begin( const std::pair& p ) + inline Iterator boost_range_begin( const std::pair& p ) { return p.first; } template< typename Iterator > - inline Iterator range_begin( std::pair& p ) + inline Iterator boost_range_begin( std::pair& p ) { return p.first; } @@ -68,13 +68,13 @@ namespace range_detail // May this be discarded? Or is it needed for bad compilers? // template< typename T, std::size_t sz > - inline const T* range_begin( const T (&array)[sz] ) + inline const T* boost_range_begin( const T (&array)[sz] ) { return array; } template< typename T, std::size_t sz > - inline T* range_begin( T (&array)[sz] ) + inline T* boost_range_begin( T (&array)[sz] ) { return array; } @@ -95,7 +95,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator::type begin( T& r ) /**/ using namespace range_detail; #endif - return range_begin( r ); + return boost_range_begin( r ); } template< class T > @@ -106,7 +106,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator::type begin( const T& r ) /**/ using namespace range_detail; #endif - return range_begin( r ); + return boost_range_begin( r ); } } // namespace boost diff --git a/include/boost/range/end.hpp b/include/boost/range/end.hpp index be2f495..59bae67 100755 --- a/include/boost/range/end.hpp +++ b/include/boost/range/end.hpp @@ -40,7 +40,7 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename C > inline BOOST_DEDUCED_TYPENAME range_iterator::type - range_end( C& c ) + boost_range_end( C& c ) { return c.end(); } @@ -50,13 +50,13 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename Iterator > - inline Iterator range_end( const std::pair& p ) + inline Iterator boost_range_end( const std::pair& p ) { return p.second; } template< typename Iterator > - inline Iterator range_end( std::pair& p ) + inline Iterator boost_range_end( std::pair& p ) { return p.second; } @@ -66,13 +66,13 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename T, std::size_t sz > - inline const T* range_end( const T (&array)[sz] ) + inline const T* boost_range_end( const T (&array)[sz] ) { return range_detail::array_end( array ); } template< typename T, std::size_t sz > - inline T* range_end( T (&array)[sz] ) + inline T* boost_range_end( T (&array)[sz] ) { return range_detail::array_end( array ); } @@ -91,7 +91,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator::type end( T& r ) /**/ using namespace range_detail; #endif - return range_end( r ); + return boost_range_end( r ); } template< class T > @@ -102,7 +102,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator::type end( const T& r ) /**/ using namespace range_detail; #endif - return range_end( r ); + return boost_range_end( r ); } } // namespace 'boost' From cf9ad808a6c91597b4027fcb3bba488df3301617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 19:12:19 +0000 Subject: [PATCH 07/57] new fancy quickbook documentaion [SVN r40373] --- doc/Jamfile.v2 | 18 + doc/boost_range.qbk | 1234 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1252 insertions(+) create mode 100644 doc/Jamfile.v2 create mode 100644 doc/boost_range.qbk diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 new file mode 100644 index 0000000..4f7b44b --- /dev/null +++ b/doc/Jamfile.v2 @@ -0,0 +1,18 @@ + +use-project boost : $(BOOST_ROOT) ; + + +#import boostbook : boostbook ; +import quickbook ; + +xml boost_range : boost_range.qbk ; + +boostbook standalone + : + boost_range + : + generate.section.toc.level=4 + chunk.first.sections=7 + toc.section.depth=10 + ; + diff --git a/doc/boost_range.qbk b/doc/boost_range.qbk new file mode 100644 index 0000000..80b5c8c --- /dev/null +++ b/doc/boost_range.qbk @@ -0,0 +1,1234 @@ +[article Boost.Range Documentation + [quickbook 1.3] + [id boost.range] + [copyright 2003-2007 Thorsten Ottosen] + [license + 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]) + ] +] + +[/ Converted to Quickbook format by Darren Garvey, 2007] + +[def __ranges__ [link boost.range.concepts Ranges]] +[def __range_concepts__ [link boost.range.concepts Range concepts]] +[def __forward_range__ [link boost.range.concepts.forward_range Forward Range]] +[def __single_pass_range__ [link boost.range.concepts.single_pass_range Single Pass Range]] +[def __bidirectional_range__ [link boost.range.concepts.bidirectional_range Bidirectional Range]] +[def __random_access_range__ [link boost.range.concepts.random_access_range Random Access Range]] + +[def __iterator_range__ [link boost.range.utilities.iterator_range `iterator_range`]] +[def __sub_range__ [link boost.range.utilities.sub_range `sub_range`]] +[def __minimal_interface__ [link boost.range.reference.extending minimal interface]] +[def __range_result_iterator__ [link boost.range.reference.semantics.metafunctions `range_result_iterator`]] +[def __implementation_of_metafunctions__ [link boost.range.reference.semantics.metafunctions implementation of metafunctions]] +[def __implementation_of_functions__ [link boost.range.reference.semantics.functions implementation of functions]] + +[def __single_pass_iterator__ [@../../libs/iterator/doc/new-iter-concepts.html#singls-pass-iterators-lib-single-pass-iterators Single Pass Iterator]] +[def __forward_traversal_iterator__ [@../../libs/iterator/doc/new-iter-concepts.html#forward-traversal-iterators-lib-forward-traversal-iterators Forward Traversal Iterator]] +[def __bidirectional_traversal_iterator__ [@../../libs/iterator/doc/new-iter-concepts.html#bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators Bidirectional Traversal Iterator]] +[def __random_access_traversal_iterator__ [@../../libs/iterator/doc/new-iter-concepts.html#random-access-traversal-iterators-lib-random-access-traversal-iterators Random Access Traversal Iterator]] +[def __new_style_iterators__ [@../../libs/iterator/doc/new-iter-concepts.html new style iterators]] +[def __iterator_concepts__ [@../../libs/iterator/doc/iterator_concepts.html Iterator concepts]] + +[def __container__ [@http://www.sgi.com/Technology/STL/Container.html Container]] +[def __metafunctions__ [@../../libs/mpl/doc/refmanual/metafunction.html metafunctions]] +[def __concept_check__ [@../../libs/concept_check/index.html Boost Concept Check library]] +[def __boost_array__ [@../../libs/array/index.html boost::array]] +[def __the_forwarding_problem__ [@http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm The Forwarding Problem]] + + +Boost.Range is a collection of concepts and utilities that are particularly useful for specifying and implementing generic algorithms. + + +[section Introduction] + +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. 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 + +* simpler implementation and specification of generic range algorithms +* more flexible, compact and maintainable client code +* correct handling of null-terminated strings + +[:[*Warning: support for null-terminated strings is deprecated and will disappear in the next Boost release (1.34).]] + +* safe use of built-in arrays (for legacy code; why else would you use built-in arrays?) + +Below are given a small example (the complete example can be found [@http://www.boost.org/libs/range/test/algorithm_example.cpp here] ): + +`` + // + // 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_const_iterator< 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_size< 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 my_vector; + int values[] = { 1,2,3,4,5,6,7,8,9 }; + + my_vector.assign( values, boost::end( values ) ); + typedef std::vector::iterator iterator; + std::pair 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' +`` + +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 `find()` since we cannot forward a non-const rvalue with reference arguments (see this article about __the_forwarding_problem__ ). + +[endsect] + + + +[section:concepts Range Concepts] + +[section Overview] + +A Range is a ['concept] similar to the STL [@http://www.sgi.com/Technology/STL/Container.html 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 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 + +* own the elements that can be accessed through it, +* have copy semantics, + +Because of the second requirement, a Range object must be passed by (const or non-const) reference in generic code. + +The operations that can be performed on a Range is dependent on the [@../../iterator/doc/new-iter-concepts.html#iterator-traversal-concepts-lib-iterator-traversal traversal category] of the underlying iterator type. Therefore the range concepts are named to reflect which traversal category its iterators support. See also terminology and style guidelines. for more information about naming of ranges. + +The concepts described below specifies associated types as [@../../libs/mpl/doc/refmanual/metafunction.html metafunctions] and all functions as free-standing functions to allow for a layer of indirection. + +[endsect] + + +[section Single Pass Range] + +[h4 Notation] + +`X` A type that is a model of __single_pass_range__. +`a` Object of type X. + +[h4 Description] + +A range `X` where `boost::range_iterator::type` is a model of __single_pass_iterator__. + +[h4 Associated types] + +[table + [] + [[Value type ] [`boost::range_value::type` ] [The type of the object stored in a Range.]] + [[Iterator type ] [`boost::range_iterator::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_const_iterator::type`] [A type of iterator that may be used to examine, but not to modify, a Range's elements.]] +] + +[h4 Valid expressions] + +The following expressions must be valid. + +[table + [[Name ] [Expression ] [Return type ]] + [[Beginning of range] [`boost::begin(a)`] [`boost::range_iterator::type` if `a` is mutable,[br] `boost::range_const_iterator::type` otherwise]] + [[End of range ] [`boost::end(a)` ] [`boost::range_iterator::type` if `a` is mutable,[br] `boost::range_const_iterator::type` otherwise]] + [[Is range empty? ] [boost::empty(a) ] [Convertible to bool]] +] + +[h4 Expression semantics] + +[table + [[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::size(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::empty(a)`] [Equivalent to `boost::begin(a) == boost::end(a)`. (But possibly faster.)] [- ]] +] + +[h4 Complexity guarantees] + +All three functions are at most amortized linear time. For most practical purposes, one can expect `boost::begin(a)`, `boost::end(a)` and `boost::empty(a)` to be amortized constant time. + +[h4 Invariants] + +[table + [] + [[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`.]] +] + +[h4 See also] + +__container__ + +__implementation_of_metafunctions__ + +__implementation_of_functions__ + +[endsect] + + +[section Forward Range] + +[h4 Notation] + +`X` A type that is a model of __forward_range__. +`a` Object of type X. + +[h4 Description] + +A range `X` where `boost::range_iterator::type` is a model of __forward_traversal_iterator__. + +[h4 Refinement of] + +__single_pass_range__ + +[h4 Associated types] + +[table + [] + [[Distance type] [`boost::range_difference::type`] [A signed integral type used to represent the distance between two of the Range's iterators. This type must be the same as the iterator's distance type.]] + [[Size type ] [`boost::range_size::type` ] [An unsigned integral type that can represent any nonnegative value of the Range's distance type.]] +] + +[h4 Valid expressions] + +[table + [[Name ] [Expression ] [Return type ]] + [[Size of range] [`boost::size(a)`] [`boost::range_size::type`]] +] + +[h4 Expression semantics] + +[table + [[Expression ] [Semantics] [Postcondition]] + [[`boost::size(a)`] [Returns the size of the Range, that is, its number of elements. Note `boost::size(a) == 0u` is equivalent to `boost::empty(a)`.] [`boost::size(a) >= 0`]] +] + +[h4 Complexity guarantees] + +`boost::size(a)` is at most amortized linear time. + +[h4 Invariants] + +[table + [] + [[Range size] [`boost::size(a)` is equal to the distance from `boost::begin(a)` to `boost::end(a)`.]] +] + +[h4 See also] + +__implementation_of_metafunctions__ + +__implementation_of_functions__ + +[endsect] + + +[section Bidirectional Range] + +[h4 Notation] + +`X` A type that is a model of __bidirectional_range__. +`a` Object of type X. + +[h4 Description] + +This concept provides access to iterators that traverse in both directions (forward and reverse). The `boost::range_iterator::type` iterator must meet all of the requirements of __bidirectional_traversal_iterator__. + +[h4 Refinement of] + +__forward_range__ + +[h4 Associated types] + +[table + [] + [[Reverse Iterator type ] [`boost::range_reverse_iterator::type` ] [The type of iterator used to iterate through a Range's elements in reverse order. The iterator's value type is expected to be the Range's value type. A conversion from the reverse iterator type to the const reverse iterator type must exist.]] + + [[Const reverse iterator type] [`boost::range_const_reverse_iterator::type`] [A type of reverse iterator that may be used to examine, but not to modify, a Range's elements.]] +] + +[h4 Valid expressions] + +[table + [[Name ] [Expression ] [Return type] [Semantics]] + [[Beginning of range] [`boost::rbegin(a)`] [`boost::range_reverse_iterator::type` if `a` is mutable[br] `boost::range_const_reverse_iterator::type` otherwise.] [Equivalent to `boost::range_reverse_iterator::type(boost::end(a))`.]] + + [[End of range ] [`boost::rend(a)` ] [`boost::range_reverse_iterator::type` if `a` is mutable,[br] `boost::range_const_reverse_iterator::type` otherwise.] [Equivalent to `boost::range_reverse_iterator::type(boost::begin(a))`.]] +] + +[h4 Complexity guarantees] + +`boost::rbegin(a)` has the same complexity as `boost::end(a)` and `boost::rend(a)` has the same complexity as `boost::begin(a)` from __forward_range__. + +[h4 Invariants] + +[table + [] + [[Valid reverse range] [For any Bidirectional Range a, `[boost::rbegin(a),boost::rend(a))` is a valid range, that is, `boost::rend(a)` is reachable from `boost::rbegin(a)` in a finite number of increments.]] + + [[Completeness ] [`An algorithm that iterates through the range `[boost::rbegin(a),boost::rend(a))` will pass through every element of `a`.]] +] + +[h4 See also] + +__implementation_of_metafunctions__ + +__implementation_of_functions__ + +[endsect] + + +[section Random Access Range] + +[h4 Description] + +A range `X` where `boost::range_iterator::type` is a model of __random_access_traversal_iterator__. + +[h4 Refinement of] + +__bidirectional_range__ + +[endsect] + + +[section Concept Checking] + +Each of the range concepts has a corresponding concept checking class in the file [@../../boost/range/concepts.hpp `boost/range/concepts.hpp`]. These classes may be used in conjunction with the __concept_check__ 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 __forward_range__ concept. + +`` +function_requires >(); +`` + +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 >(); + function_requires< + ReadableIteratorConcept< + typename range_iterator::type + > + >(); +`` + +The following range concept checking classes are provided. + +* Class SinglePassRangeConcept checks for __single_pass_range__ +* Class ForwardRangeConcept checks for __forward_range__ +* Class BidirectionalRangeConcept checks for __bidirectional_range__ +* Class RandomAccessRangeConcept checks for __random_access_range__ + +[h4 See also] + +[link boost.range.style_guide Range Terminology and style guidelines] + +__iterator_concepts__ + +__concept_check__ + +[endsect] + +[endsect] + + + +[section Reference] + +[section Overview] + +Four types of objects are currently supported by the library: + +* standard-like containers +* `std::pair` +* null terminated strings (this includes `char[]`,`wchar_t[]`, `char*`, and `wchar_t*`) + +[:[*Warning: ['support for null-terminated strings is deprecated and will disappear in the next Boost release (1.34).]]] + +* built-in arrays + +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 __iterator_range__ implements the __minimal_interface__ required to make the class a __forward_range__. + +Please also see __range_concepts__ for more details. + +[endsect] + + +[section Synopsis] + +`` +namespace boost +{ + // + // Single Pass Range metafunctions + // + + template< class T > + struct range_value; + + template< class T > + struct range_iterator; + + template< class T > + struct range_const_iterator; + + // + // Forward Range metafunctions + // + + template< class T > + struct range_difference; + + template< class T > + struct range_size; + + // + // Bidirectional Range metafunctions + // + + template< class T > + struct range_reverse_iterator; + + template< class T > + struct range_const_reverse_iterator; + + // + // Special metafunctions + // + + template< class T > + struct range_result_iterator; + + template< class T > + struct range_reverse_result_iterator; + + // + // Single Pass Range functions + // + + template< class T > + typename range_iterator::type + begin( T& c ); + + template< class T > + typename range_const_iterator::type + begin( const T& c ); + + template< class T > + typename range_iterator::type + end( T& c ); + + template< class T > + typename range_const_iterator::type + end( const T& c ); + + template< class T > + bool + empty( const T& c ); + + // + // Forward Range functions + // + + template< class T > + typename range_size::type + size( const T& c ); + + // + // Bidirectional Range functions + // + + template< class T > + typename range_reverse_iterator::type + rbegin( T& c ); + + template< class T > + typename range_const_reverse_iterator::type + rbegin( const T& c ); + + template< class T > + typename range_reverse_iterator::type + rend( T& c ); + + template< class T > + typename range_const_reverse_iterator::type + rend( const T& c ); + + // + // Special const Range functions + // + + template< class T > + typename range_const_iterator::type + const_begin( const T& r ); + + template< class T > + typename range_const_iterator::type + const_end( const T& r ); + + template< class T > + typename range_const_reverse_iterator::type + const_rbegin( const T& r ); + + template< class T > + typename range_const_reverse_iterator::type + const_rend( const T& r ); + +} // namespace 'boost' +`` + +[endsect] + + +[section Semantics] + +[h5 notation] + +[table + [[Type ] [Object] [Describes ]] + [[`X` ] [`x` ] [any type ]] + [[`T` ] [`t` ] [denotes behavior of the primary templates]] + [[`P` ] [`p` ] [denotes `std::pair` ]] + [[`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. + +[section Metafunctions] + +[table + [[Expression] [Return type] [Complexity]] + [[`range_value::type`] [`T::value_type`[br] +`boost::iterator_value::type`[br] +`A`[br] +`Char`] [compile time]] + [[`range_iterator::type`] [`T::iterator`[br] +`P::first_type`[br] +`A*`[br] +`Char*`] [compile time]] + [[`range_const_iterator::type`] [`T::const_iterator`[br] +`P::first_type`[br] +`const A*`[br] +`const Char*`] [compile time]] + [[`range_difference::type`] [`T::difference_type`[br] +`boost::iterator_difference::type`[br] +`std::ptrdiff_t`[br] +`std::ptrdiff_t`] [compile time]] + [[`range_size::type`] [`T::size_type`[br] +`std::size_t`[br] +`std::size_t`[br] +`std::size_t`] [compile time]] + [[`range_result_iterator::type`] [`range_const_iterator::type` if `X` is `const`[br] +`range_iterator::type` otherwise] [compile time]] + [[`range_reverse_iterator::type`] [`boost::reverse_iterator< typename range_iterator::type >`] [compile time]] + [[`range_const_reverse_iterator::type`] [`boost::reverse_iterator< typename range_const_iterator::type >`] [compile time]] + [[`range_reverse_result_iterator::type`] [`boost::reverse_iterator< typename range_result_iterator::type >`] [compile time]] +] + +The special metafunctions `range_result_iterator` and `range_reverse_result_iterator` are not part of any Range concept, but they are very useful when implementing certain Range classes like __sub_range__ because of their ability to select iterators based on constness. + +[endsect] + +[section Functions] + +[table + [[Expression] [Return type] [Returns] [Complexity]] + + [[`begin(x)`] [`range_result_iterator::type`] [`p.first` if `p` is of type `std::pair`[br] +`a` if `a` is an array[br] +`s` if `s` is a string literal[br] +`boost_range_begin(x)` if that expression would invoke a function found by ADL[br] +`t.begin()` otherwise] [constant time]] + + [[`end(x)`] [`range_result_iterator::type`] [`p.second` if `p` is of type `std::pair`[br] +`a + sz` if `a` is an array of size `sz`[br] +`s + std::char_traits::length( s )` if `s` is a `Char*`[br] +`s + sz - 1` if `s` is a string literal of size `sz`[br] +`boost_range_end(x)` if that expression would invoke a function found by ADL[br] +`t.end()` otherwise] [linear if `X` is `Char*` +constant time otherwise]] + + [[`empty(x)`] [`bool`] [`begin(x) == end( x )`] [linear if `X` is `Char*`[br] +constant time otherwise]] + + [[`size(x)`] [`range_size::type`] [`std::distance(p.first,p.second)` if `p` is of type `std::pair`[br] +`sz` if `a` is an array of size `sz`[br] +`end(s) - s` if `s` is a string literal or a `Char*`[br] +`boost_range_size(x)` if that expression would invoke a function found by ADL[br] +`t.size()` otherwise] [linear if `X` is `Char*` or if `std::distance()` is linear[br] +constant time otherwise]] + + [[`rbegin(x)`] [`range_reverse_result_iterator::type`] [`range_reverse_result_iterator::type( end(x) )`] [same as `end(x)`]] + + [[`rend(x)`] [`range_reverse_result_iterator::type`] [`range_reverse_result_iterator::type( begin(x) )`] [same as `begin(x)`]] + + [[`const_begin(x)`] [`range_const_iterator::type`] [`range_const_iterator::type( begin(x) )`] [same as `begin(x)`]] + + [[`const_end(x)`] [`range_const_iterator::type`] [`range_const_iterator::type( end(x) )`] [same as `end(x)`]] + + [[`const_rbegin(x)`] [`range_const_reverse_iterator::type`] [`range_const_reverse_iterator::type( rbegin(x) )`] [same as `rbegin(x)`]] + + [[`const_rend(x)`] [`range_const_reverse_iterator::type`] [`range_const_reverse_iterator::type( rend(x) )`] [same as `rend(x)`]] +] + +The special const functions are not part of any Range concept, but are very useful when you want to document clearly that your code is read-only. + +[endsect] + +[endsect] + +[section:extending Extending the library] + +[section:method_1 Method 1: provide member functions and nested types] + +This procedure assumes that you have control over the types that should be made conformant to a Range concept. If not, see [link boost.range.reference.extending.method_2 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. + +[table + [[Member function] [Related concept ]] + [[`begin()` ] [__single_pass_range__]] + [[`end()` ] [__single_pass_range__]] + [[`size()` ] [__forward_range__ ]] +] + +Notice that `rbegin()` and `rend()` member functions are not needed even though the container can support bidirectional iteration. + +The required member types are: + +[table + [[Member type ] [Related concept ]] + [[`iterator` ] [__single_pass_range__]] + [[`const_iterator`] [__single_pass_range__]] + [[`size_type` ] [__forward_range__ ]] +] + +Again one should notice that member types `reverse_iterator` and `const_reverse_iterator` are not needed. + +[endsect] + +[section:method_2 Method 2: provide free-standing functions and specialize metafunctions] + +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 [link boost.range.reference.extending.method_1 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. + +[table + [[Function ] [Related concept ]] + [[`boost_range_begin(x)`] [__single_pass_range__]] + [[`boost_range_end(x)` ] [__single_pass_range__]] + [[`boost_range_size(x)` ] [__forward_range__ ]] +] + +`boost_range_begin()` and `boost_range_end()` must be overloaded for both `const` and `mutable` reference arguments. + +You must also specialize 3 metafunctions for your type `X`: + +[table + [[Metafunction ] [Related concept ]] + [[`boost::range_iterator` ] [__single_pass_range__]] + [[`boost::range_const_iterator`] [__single_pass_range__]] + [[`boost::range_size` ] [__forward_range__ ]] +] + +A complete example is given here: + +`` + #include + #include // 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_iterator< Foo::Pair > + { + typedef T type; + }; + + template< class T > + struct range_const_iterator< Foo::Pair > + { + // + // Remark: this is defined similar to 'range_iterator' + // because the 'Pair' type does not distinguish + // between an iterator and a const_iterator. + // + typedef T type; + }; + + template< class T > + struct range_size< Foo::Pair > + { + + typedef std::size_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 boost_range_begin( Pair& x ) + { + return x.first; + } + + template< class T > + inline T boost_range_begin( const Pair& x ) + { + return x.first; + } + + template< class T > + inline T boost_range_end( Pair& x ) + { + return x.last; + } + + template< class T > + inline T boost_range_end( const Pair& x ) + { + return x.last; + } + + template< class T > + inline typename boost::range_size< Pair >::type + boost_range_size( const Pair& x ) + { + return std::distance(x.first,x.last); + } + + } // namespace 'Foo' + + #include + + int main() + { + typedef std::vector::iterator iter; + std::vector vec; + Foo::Pair pair = { vec.begin(), vec.end() }; + const Foo::Pair& 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_size< Foo::Pair >::type s = boost::size( pair ); + s = boost::size( cpair ); + boost::range_const_reverse_iterator< Foo::Pair >::type + ri = boost::rbegin( cpair ), + re = boost::rend( cpair ); + } +`` + +[endsect] + +[endsect] + +[endsect] + + + +[section Utilities] + +Having an abstraction that encapsulates a pair of iterators is very useful. The standard library uses `std::pair` in some circumstances, but that class is cumbersome to use because we need to specify two template arguments, and for all range algorithm purposes we must enforce the two template arguments to be the same. Moreover, `std::pair` is hardly self-documenting whereas more domain specific class names are. Therefore these two classes are provided: + +* Class `iterator_range` +* Class `sub_range` + +The `iterator_range` class is templated on an __forward_traversal_iterator__ and should be used whenever fairly general code is needed. The `sub_range` class is templated on an __forward_range__ and it is less general, but a bit easier to use since its template argument is easier to specify. The biggest difference is, however, that a `sub_range` can propagate constness because it knows what a corresponding `const_iterator` is. + +Both classes can be used as ranges since they implement the __minimal_interface__ required for this to work automatically. + +[section:iterator_range Class `iterator_range`] + +The intention of the `iterator_range` class is to encapsulate two iterators so they fulfill the __forward_range__ concept. A few other functions are also provided for convenience. + +If the template argument is not a model of __forward_traversal_iterator__, one can still use a subset of the interface. In particular, `size()` requires Forward Traversal Iterators whereas `empty()` only requires Single Pass Iterators. + +Recall that many default constructed iterators are singular and hence can only be assigned, but not compared or incremented or anything. However, if one creates a default constructed `iterator_range`, then one can still call all its member functions. This means that the `iterator_range` will still be usable in many contexts even though the iterators underneath are not. + +[h4 Synopsis] + +`` +namespace boost +{ + template< class ForwardTraversalIterator > + class iterator_range + { + public: // Forward Range types + typedef ... value_type; + typedef ... difference_type; + typedef ... size_type; + typedef ForwardTraversalIterator iterator; + typedef ForwardTraversalIterator const_iterator; + + public: // construction, assignment + template< class ForwardTraversalIterator2 > + iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End ); + + template< class ForwardRange > + iterator_range( ForwardRange& r ); + + template< class ForwardRange > + iterator_range( const ForwardRange& r ); + + template< class ForwardRange > + iterator_range& operator=( ForwardRange& r ); + + template< class ForwardRange > + iterator_range& operator=( const ForwardRange& r ); + + public: // Forward Range functions + iterator begin() const; + iterator end() const; + size_type size() const; + bool empty() const; + + public: // convenience + operator unspecified_bool_type() const; + bool equal( const iterator_range& ) const; + value_type& front() const; + value_type& back() const; + // for Random Access Range only: + value_type& operator[]( size_type at ) const; + }; + + // stream output + template< class ForwardTraversalIterator, class T, class Traits > + std::basic_ostream& + operator<<( std::basic_ostream& Os, + const iterator_range& r ); + + // comparison + template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > + bool operator==( const iterator_range& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator==( const iterator_range& l, + const ForwardRange& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator==( const ForwardRange& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > + bool operator!=( const iterator_range& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator!=( const iterator_range& l, + const ForwardRange& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator!=( const ForwardRange& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > + bool operator<( const iterator_range& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator<( const iterator_range& l, + const ForwardRange& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator<( const ForwardRange& l, + const iterator_range& r ); + + // external construction + template< class ForwardTraversalIterator > + iterator_range< ForwardTraversalIterator > + make_iterator_range( ForwardTraversalIterator Begin, + ForwardTraversalIterator End ); + + template< class ForwardRange > + iterator_range< typename iterator_of::type > + make_iterator_range( ForwardRange& r ); + + template< class ForwardRange > + iterator_range< typename const_iterator_of::type > + make_iterator_range( const ForwardRange& r ); + + template< class Range > + iterator_range< typename range_iterator::type > + make_iterator_range( Range& r, + typename range_difference::type advance_begin, + typename range_difference::type advance_end ); + + template< class Range > + iterator_range< typename range_const_iterator::type > + make_iterator_range( const Range& r, + typename range_difference::type advance_begin, + typename range_difference::type advance_end ); + + // convenience + template< class Sequence, class ForwardRange > + Sequence copy_range( const ForwardRange& r ); + +} // namespace 'boost' +`` + +If an instance of `iterator_range` is constructed by a client with two iterators, the client must ensure that the two iterators delimit a valid closed-open range [begin,end). + +It is worth noticing that the templated constructors and assignment operators allow conversion from `iterator_range` to `iterator_range`. Similarly, since the comparison operators have two template arguments, we can compare ranges whenever the iterators are comparable; for example when we are dealing with const and non-const iterators from the same container. + +[h4 Details member functions] + +`operator unspecified_bool_type() const;` + +[:['[*Returns]] `!empty();`] + +`bool equal( iterator_range& r ) const;` + +[:['[*Returns]] `begin() == r.begin() && end() == r.end();`] + +[h4 Details functions] + +`bool operator==( const ForwardRange1& l, const ForwardRange2& r );` + +[:['[*Returns]] `size(l) != size(r) ? false : std::equal( begin(l), end(l), begin(r) );`] + +`bool operator!=( const ForwardRange1& l, const ForwardRange2& r );` + +[:['[*Returns]] `!( l == r );`] + +`bool operator<( const ForwardRange1& l, const ForwardRange2& r );` + +[:['[*Returns]] `std::lexicographical_compare( begin(l), end(l), begin(r), end(r) );`] + +`` +iterator_range make_iterator_range( Range& r, + typename range_difference::type advance_begin, + typename range_difference::type advance_end ); +`` + +[:['[*Effects:]]] + +`` + iterator new_begin = begin( r ), + iterator new_end = end( r ); + std::advance( new_begin, advance_begin ); + std::advance( new_end, advance_end ); + return make_iterator_range( new_begin, new_end ); +`` + +`Sequence copy_range( const ForwardRange& r );` + +[:['[*Returns]] `Sequence( begin(r), end(r) );`] + +[endsect] + +[section:sub_range Class `sub_range`] + +The `sub_range` class inherits all its functionality from the __iterator_range__ class. The `sub_range` class is often easier to use because one must specify the __forward_range__ template argument instead of an iterator. Moreover, the sub_range class can propagate constness since it knows what a corresponding `const_iterator` is. + +[h4 Synopsis] + +`` +namespace boost +{ + template< class ForwardRange > + class sub_range : public iterator_range< typename range_result_iterator::type > + { + public: + typedef typename range_result_iterator::type iterator; + typedef typename range_const_iterator::type const_iterator; + + public: // construction, assignment + template< class ForwardTraversalIterator > + sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End ); + + template< class ForwardRange2 > + sub_range( ForwardRange2& r ); + + template< class ForwardRange2 > + sub_range( const Range2& r ); + + template< class ForwardRange2 > + sub_range& operator=( ForwardRange2& r ); + + template< class ForwardRange2 > + sub_range& operator=( const ForwardRange2& r ); + + public: // Forward Range functions + iterator begin(); + const_iterator begin() const; + iterator end(); + const_iterator end() const; + + public: // convenience + value_type& front(); + const value_type& front() const; + value_type& back(); + const value_type& back() const; + // for Random Access Range only: + value_type& operator[]( size_type at ); + const value_type& operator[]( size_type at ) const; + + public: + // rest of interface inherited from iterator_range + }; + +} // namespace 'boost' +`` + +The class should be trivial to use as seen below. Imagine that we have an algorithm that searches for a sub-string in a string. The result is an iterator_range, that delimits the match. We need to store the result from this algorithm. Here is an example of how we can do it with and without `sub_range` + +`` +std::string str("hello"); +iterator_range ir = find_first( str, "ll" ); +sub_range sub = find_first( str, "ll" ); +`` + +[endsect] + +[endsect] + + + +[section:style_guide Terminology and style guidelines] + +The use of a consistent terminology is as important for __ranges__ and range-based algorithms as it is for iterators and iterator-based algorithms. If a conventional set of names are adopted, we can avoid misunderstandings and write generic function prototypes that are ['self-documenting]. + +Since ranges are characterized by a specific underlying iterator type, we get a type of range for each type of iterator. Hence we can speak of the following types of ranges: + +* ['Value access] category: + * Readable Range + * Writeable Range + * Swappable Range + * Lvalue Range +* ['Traversal] category: + * __single_pass_range__ + * __forward_range__ + * __bidirectional_range__ + * __random_access_range__ + +Notice how we have used the categories from the __new_style_iterators__. + +Notice that an iterator (and therefore an range) has one ['traversal] property and one or more properties from the ['value access] category. So in reality we will mostly talk about mixtures such as + +* Random Access Readable Writeable Range +* Forward Lvalue Range + +By convention, we should always specify the ['traversal] property first as done above. This seems reasonable since there will only be one ['traversal] property, but perhaps many ['value access] properties. + +It might, however, be reasonable to specify only one category if the other category does not matter. For example, the __iterator_range__ can be constructed from a Forward Range. This means that we do not care about what ['value access] properties the Range has. Similarly, a Readable Range will be one that has the lowest possible ['traversal] property (Single Pass). + +As another example, consider how we specify the interface of `std::sort()`. Algorithms are usually more cumbersome to specify the interface of since both traversal and value access properties must be exactly defined. The iterator-based version looks like this: + +`` + template< class RandomAccessTraversalReadableWritableIterator > + void sort( RandomAccessTraversalReadableWritableIterator first, + RandomAccessTraversalReadableWritableIterator last ); +`` + +For ranges the interface becomes + +`` + template< class RandomAccessReadableWritableRange > + void sort( RandomAccessReadableWritableRange& r ); +`` + +[endsect] + + + +[section Library Headers] + +[table + [[Header ] [Includes ] [Related Concept ]] + [[`` ] [everything ] [- ]] + [[`` ] [every metafunction ] [- ]] + [[`` ] [every function ] [- ]] + [[`` ] [`range_value` ] [__single_pass_range__ ]] + [[`` ] [`range_iterator` ] [__single_pass_range__ ]] + [[`` ] [`range_const_iterator` ] [__single_pass_range__ ]] + [[`` ] [`range_difference` ] [__forward_range__ ]] + [[`` ] [`range_size` ] [__forward_range__ ]] + [[`` ] [`range_result_iterator` ] [- ]] + [[``] [`range_reverse_iterator` ] [__bidirectional_range__ ]] + [[``] + [`range_const_reverse_iterator`] + [_bidirectional_range__ ]] + [[``] + [`range_reverse_result_iterator`] + [- ]] + [[`` ] [`begin` and `const_begin` ] [__single_pass_range__ ]] + [[`` ] [`end` and `const_end` ] [__single_pass_range__ ]] + [[`` ] [`empty` ] [__single_pass_range__ ]] + [[`` ] [`size` ] [__forward_range__ ]] + [[`` ] [`rbegin` and `const_rbegin`] [__bidirectional_range__ ]] + [[`` ] [`rend` and `const_rend` ] [__bidirectional_range__ ]] + [[`` ] [`iterator_range` ] [- ]] + [[`` ] [`sub_range` ] [- ]] + [[`` ] [`concept checks` ] [- ]] +] + +[endsect] + + + +[section Examples] + +Some examples are given in the accompanying test files: + +* [@http://www.boost.org/libs/range/test/string.cpp string.cpp][br] +shows how to implement a container version of `std::find()` that works with `char[]`,`wchar_t[]`,`char*`,`wchar_t*`. + +[:[*Warning: ['support for null-terminated strings is deprecated and will disappear in the next Boost release (1.34).]]] + +* [@http://www.boost.org/libs/range/test/algorithm_example.cpp algorithm_example.cpp][br]shows the replace example from the introduction. + +* [@http://www.boost.org/libs/range/test/iterator_range.cpp iterator_range.cpp] + +* [@http://www.boost.org/libs/range/test/sub_range.cpp sub_range.cpp] + +* [@http://www.boost.org/libs/range/test/iterator_pair.cpp iterator_pair.cpp] + +* [@http://www.boost.org/libs/range/test/reversible_range.cpp reversible_range.cpp] + +* [@http://www.boost.org/libs/range/test/std_container.cpp std_container.cpp] + +* [@http://www.boost.org/libs/range/test/array.cpp array.cpp] + +[endsect] + + + +[section Portability] + +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 of __range_result_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: + +# do not use built-in arrays, +# do not pass rvalues to `begin()`, `end()` and `iterator_range` Range constructors and assignment operators, +# use `const_begin()` and `const_end()` whenever your code by intention is read-only; this will also solve most rvalue problems, +# do not rely on ADL: + * if you overload functions, include that header before the headers in this library, + * put all overloads in namespace boost. + + + +[endsect] + + + +[section FAQ] + +1. ['[*Why is there no difference between `range_iterator::type` and `range_const_iterator::type` for `std::pair`?]] + +[: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` object.] + +[:Note that an __iterator_range__ is somewhat more convenient than a `pair` and that a __sub_range__ does propagate const-ness.] + +2. ['[*Why is there not supplied more types or more functions?]] + +[: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.] + +3. ['[*How should I implement generic algorithms for ranges?]] + +[: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.] + +4. ['[*Why is there no Incrementable Range concept?]] + +[: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.] + +[endsect] + +[section:history_ack History and Acknowledgement] + +The library have been 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. + +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 + +* Pavol Droba for help with documentation and implementation +* Pavel Vozenilek for help with porting the library +* Jonathan Turkanis and John Torjo for help with documentation +* Hartmut Kaiser for being review manager +* Jonathan Turkanis for porting the lib (as far sa possible) to vc6 and vc7. + +The concept checks and their documentation was provided by Daniel Walker. + +[endsect] \ No newline at end of file From d759c2355260488b2d4af4a7e4fa30a982a2c00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 19:34:06 +0000 Subject: [PATCH 08/57] added test for operator() [SVN r40374] --- test/iterator_range.cpp | 1 + test/sub_range.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/test/iterator_range.cpp b/test/iterator_range.cpp index 7854a92..db531d3 100755 --- a/test/iterator_range.cpp +++ b/test/iterator_range.cpp @@ -95,6 +95,7 @@ void check_iterator_range() BOOST_CHECK_EQUAL( cr.front(), 'h' ); BOOST_CHECK_EQUAL( cr.back(), 'd' ); BOOST_CHECK_EQUAL( cr[1], 'e' ); + BOOST_CHECK_EQUAL( cr(1), 'e' ); rrr = make_iterator_range( str, 1, -1 ); BOOST_CHECK( rrr == as_literal("ello worl") ); diff --git a/test/sub_range.cpp b/test/sub_range.cpp index 3694105..7d5bf05 100755 --- a/test/sub_range.cpp +++ b/test/sub_range.cpp @@ -127,6 +127,7 @@ void check_sub_range() BOOST_CHECK_EQUAL( cr.front(), 'h' ); BOOST_CHECK_EQUAL( cr.back(), 'd' ); BOOST_CHECK_EQUAL( cr[1], 'e' ); + BOOST_CHECK_EQUAL( cr(1), 'e' ); rrr = make_iterator_range( str, 1, -1 ); BOOST_CHECK( rrr == as_literal("ello worl") ); From 17514e1d446652efa14ce43bc490518dafae6774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 19:34:38 +0000 Subject: [PATCH 09/57] added operator() to allow random access index with transform iterators [SVN r40375] --- include/boost/range/iterator_range.hpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index ebdbc3e..41b30af 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -348,10 +348,21 @@ namespace boost return *--last; } - reference operator[]( size_type sz ) const + reference operator[]( size_type at ) const { - BOOST_ASSERT( sz < size() ); - return m_Begin[sz]; + BOOST_ASSERT( at < size() ); + return m_Begin[at]; + } + + // + // When storing transform iterators, operator[]() + // fails because it returns by reference. Therefore + // operator()() is provided for these cases. + // + value_type operator()( size_type at ) const + { + BOOST_ASSERT( at < size() ); + return m_Begin[at]; } iterator_range& advance_begin( difference_type n ) From bbd9fdb7bda2fc2cd0214488b41e319f944662f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 19:50:59 +0000 Subject: [PATCH 10/57] displabed some warnings and applied Ticket #1284: sub_range_copy.patch [SVN r40376] --- include/boost/range/iterator_range.hpp | 3 +++ include/boost/range/sub_range.hpp | 30 +++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index 41b30af..bcead14 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -36,6 +36,9 @@ #endif #include +#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || BOOST_WORKAROUND(BOOST_MSVC, == 1400) + #pragma warning( disable : 4996 ) +#endif /*! \file Defines the \c iterator_class and related functions. diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index 346c0e0..30daaea 100755 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -11,6 +11,10 @@ #ifndef BOOST_RANGE_SUB_RANGE_HPP #define BOOST_RANGE_SUB_RANGE_HPP +#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || BOOST_WORKAROUND(BOOST_MSVC, == 1400) + #pragma warning( disable : 4996 ) +#endif + #include #include #include @@ -38,16 +42,12 @@ namespace boost public: sub_range() : base() { } - -/* - template< class ForwardRange2 > - sub_range( sub_range r ) : - -#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) - base( impl::adl_begin( r ), impl::adl_end( r ) ) -#else - base( r ) -#endif */ + +#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || BOOST_WORKAROUND(BOOST_MSVC, == 1400) + sub_range( const sub_range& r ) + : base( static_cast( r ) ) + { } +#endif template< class ForwardRange2 > sub_range( ForwardRange2& r ) : @@ -86,15 +86,11 @@ namespace boost { base::operator=( r ); return *this; - } + } - sub_range& operator=( sub_range r ) + sub_range& operator=( const sub_range& r ) { - // - // argument passed by value to avoid - // const_iterator to iterator conversion - // - base::operator=( r ); + base::operator=( static_cast(r) ); return *this; } From aa9158b199d46d248e5a78959e19c937a9a29ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 19:56:39 +0000 Subject: [PATCH 11/57] applied Ticket #1309 (new Patches) [SVN r40377] --- include/boost/range/iterator.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/boost/range/iterator.hpp b/include/boost/range/iterator.hpp index 3942cbc..21798c5 100755 --- a/include/boost/range/iterator.hpp +++ b/include/boost/range/iterator.hpp @@ -24,13 +24,45 @@ namespace boost { + +#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) + + namespace range_detail_vc7_1 + { + template< typename C, typename Sig = void(C) > + struct range_iterator + { + typedef BOOST_RANGE_DEDUCED_TYPENAME + mpl::eval_if_c< is_const::value, + range_const_iterator< typename remove_const::type >, + range_mutable_iterator >::type type; + }; + + template< typename C, typename T > + struct range_iterator< C, void(T[]) > + { + typedef T* type; + }; + } + +#endif + template< typename C > struct range_iterator { +#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) + + typedef BOOST_RANGE_DEDUCED_TYPENAME + range_detail_vc7_1::range_iterator::type type; + +#else + typedef BOOST_RANGE_DEDUCED_TYPENAME mpl::eval_if_c< is_const::value, range_const_iterator< typename remove_const::type >, range_mutable_iterator >::type type; + +#endif }; } // namespace boost From d130dff5ec5df3e135865deeac8a37181727f6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 20:08:35 +0000 Subject: [PATCH 12/57] cleanup [SVN r40378] --- .../range/detail/implementation_help.hpp | 79 ------------------- 1 file changed, 79 deletions(-) diff --git a/include/boost/range/detail/implementation_help.hpp b/include/boost/range/detail/implementation_help.hpp index 31b7aea..da086f0 100755 --- a/include/boost/range/detail/implementation_help.hpp +++ b/include/boost/range/detail/implementation_help.hpp @@ -57,55 +57,15 @@ namespace boost return const_cast( str_end( s, s ) ); } - /* - template< class T, std::size_t sz > - inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz], int ) - { - return boost_range_array + sz; - } - - template< class T, std::size_t sz > - inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz], int ) - { - return boost_range_array + sz; - } - - template< class T, std::size_t sz > - inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz], char_or_wchar_t_array_tag ) - { - return boost_range_array + sz - 1; - } - - template< class T, std::size_t sz > - inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz], char_or_wchar_t_array_tag ) - { - return boost_range_array + sz - 1; - } - */ - template< class T, std::size_t sz > inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz] ) { - /* - typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same::value || is_same::value, - char_or_wchar_t_array_tag, - int >::type tag; - - return array_end( boost_range_array, tag() ); - */ return boost_range_array + sz; } template< class T, std::size_t sz > inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz] ) { - /* - typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same::value || is_same::value, - char_or_wchar_t_array_tag, - int >::type tag; - - return array_end( boost_range_array, tag() ); - */ return boost_range_array + sz; } @@ -119,54 +79,15 @@ namespace boost return str_end( s ) - s; } - /* - template< class T, std::size_t sz > - inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz], int ) - { - return sz; - } - - template< class T, std::size_t sz > - inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz], int ) - { - return sz; - } - - template< class T, std::size_t sz > - inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz], char_or_wchar_t_array_tag ) - { - return sz - 1; - } - - template< class T, std::size_t sz > - inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz], char_or_wchar_t_array_tag ) - { - return sz - 1; - } - */ - template< class T, std::size_t sz > inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz] ) { - /* - typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same::value || is_same::value || - is_same::value || is_same::value, - char_or_wchar_t_array_tag, - int >::type tag; - return array_size( boost_range_array, tag() ); - */ return sz; } template< class T, std::size_t sz > inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz] ) { - /* - typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same::value || is_same::value, - char_or_wchar_t_array_tag, - int >::type tag; - return array_size( boost_range_array, tag() ); - */ return sz; } From f4cde208f23995a6cc86ca0a6da9c0567e8d2a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 20:23:05 +0000 Subject: [PATCH 13/57] Adding Shunsuke Sogame fantastic MFC/ATL mappings [SVN r40379] --- include/boost/range/atl.hpp | 733 +++++++++++++++++ include/boost/range/detail/microsoft.hpp | 935 +++++++++++++++++++++ include/boost/range/mfc.hpp | 984 +++++++++++++++++++++++ 3 files changed, 2652 insertions(+) create mode 100644 include/boost/range/atl.hpp create mode 100644 include/boost/range/detail/microsoft.hpp create mode 100644 include/boost/range/mfc.hpp diff --git a/include/boost/range/atl.hpp b/include/boost/range/atl.hpp new file mode 100644 index 0000000..ab492d9 --- /dev/null +++ b/include/boost/range/atl.hpp @@ -0,0 +1,733 @@ +#ifndef BOOST_RANGE_ATL_HPP +#define BOOST_RANGE_ATL_HPP + + + + +// Boost.Range ATL Extension +// +// Copyright Shunsuke Sogame 2005-2006. +// 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) + + + + +// config +// + + +#include // _ATL_VER + + +#if !defined(BOOST_RANGE_ATL_NO_COLLECTIONS) + #if (_ATL_VER < 0x0700) + #define BOOST_RANGE_ATL_NO_COLLECTIONS + #endif +#endif + + +#if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + #if (_ATL_VER < 0x0700) // dubious + #define BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX + #endif +#endif + + +#if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLESTRING) + #if (_MSC_VER < 1310) // from , but dubious + #define BOOST_RANGE_ATL_HAS_OLD_CSIMPLESTRING + #endif +#endif + + + + +// forward declarations +// + + +#include // IID + + +namespace ATL { + + +#if !defined(BOOST_RANGE_ATL_NO_COLLECTIONS) + + + // arrays + // + template< class E, class ETraits > + class CAtlArray; + + template< class E > + class CAutoPtrArray; + + template< class I, const IID *piid > + class CInterfaceArray; + + + // lists + // + template< class E, class ETraits > + class CAtlList; + + template< class E > + class CAutoPtrList; + + template< class E, class Allocator > + class CHeapPtrList; + + template< class I, const IID *piid > + class CInterfaceList; + + + // maps + // + template< class K, class V, class KTraits, class VTraits > + class CAtlMap; + + template< class K, class V, class KTraits, class VTraits > + class CRBTree; + + template< class K, class V, class KTraits, class VTraits > + class CRBMap; + + template< class K, class V, class KTraits, class VTraits > + class CRBMultiMap; + + + // strings + // +#if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLESTRING) + template< class BaseType, bool t_bMFCDLL > + class CSimpleStringT; +#else + template< class BaseType > + class CSimpleStringT; +#endif + + template< class BaseType, class StringTraits > + class CStringT; + + template< class StringType, int t_nChars > + class CFixedStringT; + + template< class BaseType, const int t_nSize > + class CStaticString; + + +#endif // !defined(BOOST_RANGE_ATL_NO_COLLECTIONS) + + + // simples + // +#if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + + template< class T, class TEqual > + class CSimpleArray; + + template< class TKey, class TVal, class TEqual > + class CSimpleMap; + +#else + + template< class T > + class CSimpleArray; + + template< class T > + class CSimpleValArray; + + template< class TKey, class TVal > + class CSimpleMap; + +#endif // !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + + + // pointers + // + template< class E > + class CAutoPtr; + + template< class T > + class CComPtr; + + template< class T, const IID *piid > + class CComQIPtr; + + template< class E, class Allocator > + class CHeapPtr; + + template< class T > + class CAdapt; + + +} // namespace ATL + + + + +// indirect_iterator customizations +// + + +#include +#include + + +namespace boost { + + + template< class E > + struct pointee< ATL::CAutoPtr > : + mpl::identity + { }; + + template< class T > + struct pointee< ATL::CComPtr > : + mpl::identity + { }; + + template< class T, const IID *piid > + struct pointee< ATL::CComQIPtr > : + mpl::identity + { }; + + template< class E, class Allocator > + struct pointee< ATL::CHeapPtr > : + mpl::identity + { }; + + template< class T > + struct pointee< ATL::CAdapt > : + pointee + { }; + + +} // namespace boost + + + + +// extended customizations +// + + +#include +#include +#include +#include +#include // CComBSTR + + +namespace boost { namespace range_detail_microsoft { + + +#if !defined(BOOST_RANGE_ATL_NO_COLLECTIONS) + + + // arrays + // + + struct atl_array_functions : + array_functions + { + template< class Iterator, class X > + Iterator end(X& x) // redefine + { + return x.GetData() + x.GetCount(); // no 'GetSize()' + } + }; + + + template< class E, class ETraits > + struct customization< ATL::CAtlArray > : + atl_array_functions + { + template< class X > + struct meta + { + typedef E val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + + template< class E > + struct customization< ATL::CAutoPtrArray > : + atl_array_functions + { + template< class X > + struct meta + { + // ATL::CAutoPtr/CHeapPtr is no assignable. + typedef ATL::CAutoPtr val_t; + typedef val_t *miter_t; + typedef val_t const *citer_t; + + typedef indirect_iterator mutable_iterator; + typedef indirect_iterator const_iterator; + }; + }; + + + template< class I, const IID *piid > + struct customization< ATL::CInterfaceArray > : + atl_array_functions + { + template< class X > + struct meta + { + typedef ATL::CComQIPtr val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + + template< class E, class ETraits > + struct customization< ATL::CAtlList > : + list_functions + { + template< class X > + struct meta + { + typedef E val_t; + + typedef list_iterator mutable_iterator; + typedef list_iterator const_iterator; + }; + }; + + + struct indirected_list_functions + { + template< class Iterator, class X > + Iterator begin(X& x) + { + typedef typename Iterator::base_type base_t; // == list_iterator + return Iterator(base_t(x, x.GetHeadPosition())); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + typedef typename Iterator::base_type base_t; + return Iterator(base_t(x, POSITION(0))); + } + }; + + + template< class E > + struct customization< ATL::CAutoPtrList > : + indirected_list_functions + { + template< class X > + struct meta + { + typedef ATL::CAutoPtr val_t; + typedef list_iterator miter_t; + typedef list_iterator citer_t; + + typedef indirect_iterator mutable_iterator; + typedef indirect_iterator const_iterator; + }; + }; + + + template< class E, class Allocator > + struct customization< ATL::CHeapPtrList > : + indirected_list_functions + { + template< class X > + struct meta + { + typedef ATL::CHeapPtr val_t; + typedef list_iterator miter_t; + typedef list_iterator citer_t; + + typedef indirect_iterator mutable_iterator; + typedef indirect_iterator const_iterator; + }; + }; + + + template< class I, const IID *piid > + struct customization< ATL::CInterfaceList > : + list_functions + { + template< class X > + struct meta + { + typedef ATL::CComQIPtr val_t; + + typedef list_iterator mutable_iterator; + typedef list_iterator const_iterator; + }; + }; + + + // maps + // + + struct atl_rb_tree_tag + { }; + + template< > + struct customization< atl_rb_tree_tag > : + indirected_list_functions + { + template< class X > + struct meta + { + typedef typename X::CPair val_t; + + typedef list_iterator miter_t; + typedef list_iterator citer_t; + + typedef indirect_iterator mutable_iterator; + typedef indirect_iterator const_iterator; + }; + }; + + + template< class K, class V, class KTraits, class VTraits > + struct customization< ATL::CAtlMap > : + customization< atl_rb_tree_tag > + { + template< class Iterator, class X > + Iterator begin(X& x) // redefine + { + typedef typename Iterator::base_type base_t; // == list_iterator + return Iterator(base_t(x, x.GetStartPosition())); // no 'GetHeadPosition' + } + }; + + + // strings + // + + struct atl_string_tag + { }; + + template< > + struct customization< atl_string_tag > + { + template< class X > + struct meta + { + typedef typename X::PXSTR mutable_iterator; + typedef typename X::PCXSTR const_iterator; + }; + + template< class Iterator, class X > + typename mutable_::type begin(X& x) + { + return x.GetBuffer(0); + } + + template< class Iterator, class X > + Iterator begin(X const& x) + { + return x.GetString(); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return begin(x) + x.GetLength(); + } + }; + + + template< class BaseType, const int t_nSize > + struct customization< ATL::CStaticString > + { + template< class X > + struct meta + { + typedef BaseType const *mutable_iterator; + typedef mutable_iterator const_iterator; + }; + + template< class Iterator, class X > + Iterator begin(X const& x) + { + return x; + } + + template< class Iterator, class X > + Iterator end(X const& x) + { + return begin(x) + X::GetLength(); + } + }; + + +#endif // !defined(BOOST_RANGE_ATL_NO_COLLECTIONS) + + + template< > + struct customization< ATL::CComBSTR > + { + template< class X > + struct meta + { + typedef OLECHAR *mutable_iterator; + typedef OLECHAR const *const_iterator; + }; + + template< class Iterator, class X > + Iterator begin(X& x) + { + return x.operator BSTR(); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return begin(x) + x.Length(); + } + }; + + + // simples + // + +#if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + template< class T, class TEqual > + struct customization< ATL::CSimpleArray > : +#else + template< class T > + struct customization< ATL::CSimpleArray > : +#endif + array_functions + { + template< class X > + struct meta + { + typedef T val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + +#if defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + + template< class T > + struct customization< ATL::CSimpleValArray > : + array_functions + { + template< class X > + struct meta + { + typedef T val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + +#endif // defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + + +#if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + template< class TKey, class TVal, class TEqual > + struct customization< ATL::CSimpleMap > +#else + template< class TKey, class TVal > + struct customization< ATL::CSimpleMap > +#endif + { + template< class X > + struct meta + { + typedef TKey k_val_t; + typedef k_val_t *k_miter_t; + typedef k_val_t const *k_citer_t; + + typedef TVal v_val_t; + typedef v_val_t *v_miter_t; + typedef v_val_t const *v_citer_t; + + // Topic: + // 'std::pair' can't contain references + // because of reference to reference problem. + + typedef zip_iterator< tuple > mutable_iterator; + typedef zip_iterator< tuple > const_iterator; + }; + + template< class Iterator, class X > + Iterator begin(X& x) + { + return Iterator(boost::make_tuple(x.m_aKey, x.m_aVal)); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return Iterator(boost::make_tuple(x.m_aKey + x.GetSize(), x.m_aVal + x.GetSize())); + } + }; + + +} } // namespace boost::range_detail_microsoft + + + + +// range customizations +// + + +#if !defined(BOOST_RANGE_ATL_NO_COLLECTIONS) + + + // arrays + // + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CAtlArray, 2 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CAutoPtrArray, 1 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CInterfaceArray, (class)(const IID *) + ) + + + // lists + // + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CAtlList, 2 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CAutoPtrList, 1 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CHeapPtrList, 2 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CInterfaceList, (class)(const IID *) + ) + + + //maps + // + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CAtlMap, 4 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::atl_rb_tree_tag, + (ATL, BOOST_PP_NIL), CRBTree, 4 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::atl_rb_tree_tag, + (ATL, BOOST_PP_NIL), CRBMap, 4 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::atl_rb_tree_tag, + (ATL, BOOST_PP_NIL), CRBMultiMap, 4 + ) + + + // strings + // + #if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLESTRING) + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::atl_string_tag, + (ATL, BOOST_PP_NIL), CSimpleStringT, (class)(bool) + ) + #else + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::atl_string_tag, + (ATL, BOOST_PP_NIL), CSimpleStringT, 1 + ) + #endif + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::atl_string_tag, + (ATL, BOOST_PP_NIL), CStringT, 2 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::atl_string_tag, + (ATL, BOOST_PP_NIL), CFixedStringT, (class)(int) + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CStaticString, (class)(const int) + ) + + +#endif // !defined(BOOST_RANGE_ATL_NO_COLLECTIONS) + + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CComBSTR +) + + +// simples +// +#if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CSimpleArray, 2 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CSimpleMap, 3 + ) + +#else + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CSimpleArray, 1 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CSimpleMap, 2 + ) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + (ATL, BOOST_PP_NIL), CSimpleValArray, 1 + ) + +#endif // !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX) + + + + +#endif diff --git a/include/boost/range/detail/microsoft.hpp b/include/boost/range/detail/microsoft.hpp new file mode 100644 index 0000000..6dfe1ca --- /dev/null +++ b/include/boost/range/detail/microsoft.hpp @@ -0,0 +1,935 @@ +#ifndef BOOST_RANGE_DETAIL_MICROSOFT_HPP +#define BOOST_RANGE_DETAIL_MICROSOFT_HPP + + + + +// Boost.Range MFC/ATL Extension +// +// Copyright Shunsuke Sogame 2005-2006. +// 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) + + + + +// config +// + + +#include + + +#define BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1 1 + + +#if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1) + #define BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator range_mutable_iterator + #define BOOST_RANGE_DETAIL_MICROSOFT_range_begin range_begin + #define BOOST_RANGE_DETAIL_MICROSOFT_range_end range_end +#else + #define BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator range_mutable_iterator + #define BOOST_RANGE_DETAIL_MICROSOFT_range_begin boost_range_begin + #define BOOST_RANGE_DETAIL_MICROSOFT_range_end boost_range_end +#endif + + + + +// yet another customization way +// + + +#include // iterator_difference +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // disable_if + +#if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1) + #include +#else + #include // distance + #include + #include + #include +#endif + + +namespace boost { namespace range_detail_microsoft { + + + // customization point + // + + template< class Tag > + struct customization; + + + template< class T > + struct customization_tag; + + + struct using_type_as_tag + { }; + + + // Topic: + // In fact, it is unnecessary for VC++. + // VC++'s behavior seems conforming, while GCC fails without this. + template< class Iterator, class T > + struct mutable_ : + disable_if< is_const, Iterator > + { }; + + + // helpers + // + + template< class Tag, class T > + struct customization_tag_of + { + typedef typename mpl::if_< is_same, + T, + Tag + >::type type; + }; + + + template< class T > + struct customization_of + { + typedef typename remove_cv::type bare_t; + typedef typename customization_tag::type tag_t; + typedef customization type; + }; + + + template< class T > + struct mutable_iterator_of + { + typedef typename remove_cv::type bare_t; + typedef typename customization_of::type cust_t; + typedef typename cust_t::template meta::mutable_iterator type; + }; + + + template< class T > + struct const_iterator_of + { + typedef typename remove_cv::type bare_t; + typedef typename customization_of::type cust_t; + typedef typename cust_t::template meta::const_iterator type; + }; + + + template< class T > + struct size_type_of + { + typedef typename range_detail_microsoft::mutable_iterator_of::type miter_t; + typedef typename iterator_difference::type type; + }; + + + template< class T > inline + typename mutable_iterator_of::type + begin_of(T& x) + { + typedef typename customization_of::type cust_t; + return cust_t().template begin::type>(x); + } + + + template< class T > inline + typename const_iterator_of::type + begin_of(T const& x) + { + typedef typename customization_of::type cust_t; + return cust_t().template begin::type>(x); + } + + + template< class T > inline + typename mutable_iterator_of::type + end_of(T& x) + { + typedef typename customization_of::type cust_t; + return cust_t().template end::type>(x); + } + + + template< class T > inline + typename const_iterator_of::type + end_of(T const& x) + { + typedef typename customization_of::type cust_t; + return cust_t().template end::type>(x); + } + + +#if defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1) + + template< class T > inline + typename size_type_of::type + size_of(T const& x) + { + return std::distance(boost::begin(x), boost::end(x)); + } + +#endif + + + template< class Range > + struct compatible_mutable_iterator : + BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator + { }; + + +} } // namespace boost::range_detail_microsoft + + +#define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open(NamespaceList) \ + BOOST_PP_LIST_FOR_EACH(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open_op, ~, NamespaceList) \ +/**/ + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open_op(r, data, elem) \ + namespace elem { \ + /**/ + + +#define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close(NamespaceList) \ + BOOST_PP_LIST_FOR_EACH(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close_op, ~, NamespaceList) \ +/**/ + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close_op(r, data, elem) \ + } \ + /**/ + + +#define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_expand_op(r, data, elem) \ + :: elem \ +/**/ + + +#define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE(Tag, NamespaceList, Name) \ + namespace boost { namespace range_detail_microsoft { \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_tag(Tag, BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + } } \ + \ + namespace boost { \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_mutable_iterator(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_const_iterator(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size_type(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + } \ + \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open(NamespaceList) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_begin(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_begin_const(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_end(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_end_const(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close(NamespaceList) \ +/**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name) \ + BOOST_PP_LIST_FOR_EACH(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_expand_op, ~, NamespaceList) :: Name \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_tag(Tag, Fullname) \ + template< > \ + struct customization_tag< Fullname > : \ + customization_tag_of< Tag, Fullname > \ + { }; \ + /**/ + + + // metafunctions + // + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_mutable_iterator(Fullname) \ + template< > \ + struct BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator< Fullname > : \ + range_detail_microsoft::mutable_iterator_of< Fullname > \ + { }; \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_const_iterator(Fullname) \ + template< > \ + struct range_const_iterator< Fullname > : \ + range_detail_microsoft::const_iterator_of< Fullname > \ + { }; \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size_type(Fullname) \ + template< > \ + struct range_size< Fullname > : \ + range_detail_microsoft::size_type_of< Fullname > \ + { }; \ + /**/ + + + // functions + // + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_begin(Fullname) \ + inline \ + boost::range_detail_microsoft::mutable_iterator_of< Fullname >::type \ + BOOST_RANGE_DETAIL_MICROSOFT_range_begin(Fullname& x) \ + { \ + return boost::range_detail_microsoft::begin_of(x); \ + } \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_begin_const(Fullname) \ + inline \ + boost::range_detail_microsoft::const_iterator_of< Fullname >::type \ + BOOST_RANGE_DETAIL_MICROSOFT_range_begin(Fullname const& x) \ + { \ + return boost::range_detail_microsoft::begin_of(x); \ + } \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_end(Fullname) \ + inline \ + boost::range_detail_microsoft::mutable_iterator_of< Fullname >::type \ + BOOST_RANGE_DETAIL_MICROSOFT_range_end(Fullname& x) \ + { \ + return boost::range_detail_microsoft::end_of(x); \ + } \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_end_const(Fullname) \ + inline \ + boost::range_detail_microsoft::const_iterator_of< Fullname >::type \ + BOOST_RANGE_DETAIL_MICROSOFT_range_end(Fullname const& x) \ + { \ + return boost::range_detail_microsoft::end_of(x); \ + } \ + /**/ + + + #if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1) + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size(Fullname) \ + /**/ + + #else + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size(Fullname) \ + inline \ + boost::range_detail_microsoft::size_type_of< Fullname >::type \ + boost_range_size(Fullname const& x) \ + { \ + return boost::range_detail_microsoft::size_of(x); \ + } \ + /**/ + + #endif + + +#define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(Tag, NamespaceList, Name, ParamSeqOrCount) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_impl( \ + Tag, NamespaceList, Name, \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_to_param_seq(ParamSeqOrCount) \ + ) \ +/**/ + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_to_param_seq(ParamSeqOrCount) \ + BOOST_PP_IIF(BOOST_PP_IS_UNARY(ParamSeqOrCount), \ + ParamSeqOrCount BOOST_PP_TUPLE_EAT(3), \ + BOOST_PP_REPEAT \ + )(ParamSeqOrCount, BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_to_param_seq_op, ~) \ + /**/ + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_to_param_seq_op(z, n, _) \ + (class) \ + /**/ + + +#define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_impl(Tag, NamespaceList, Name, ParamSeq) \ + namespace boost { namespace range_detail_microsoft { \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_tag( \ + Tag, \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + } } \ + \ + namespace boost { \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_mutable_iterator( \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_const_iterator( \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size_type( \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + } \ + \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open(NamespaceList) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_begin( \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_begin_const( \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_end( \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_end_const( \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size( \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + ) \ + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close(NamespaceList) \ +/**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq) \ + BOOST_PP_SEQ_FOR_EACH_I(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params_op, ~, ParamSeq) \ + /**/ + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params_op(r, data, i, elem) \ + BOOST_PP_COMMA_IF(i) elem BOOST_PP_CAT(T, i) \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \ + BOOST_PP_LIST_FOR_EACH(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_expand_op, ~, NamespaceList) \ + :: Name < BOOST_PP_ENUM_PARAMS(BOOST_PP_SEQ_SIZE(ParamSeq), T) > \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_tag(Tag, Params, Fullname) \ + template< Params > \ + struct customization_tag< Fullname > : \ + customization_tag_of< Tag, Fullname > \ + { }; \ + /**/ + + + // metafunctions + // + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_mutable_iterator(Params, Fullname) \ + template< Params > \ + struct BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator< Fullname > : \ + range_detail_microsoft::mutable_iterator_of< Fullname > \ + { }; \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_const_iterator(Params, Fullname) \ + template< Params > \ + struct range_const_iterator< Fullname > : \ + range_detail_microsoft::const_iterator_of< Fullname > \ + { }; \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size_type(Params, Fullname) \ + template< Params > \ + struct range_size< Fullname > : \ + range_detail_microsoft::size_type_of< Fullname > \ + { }; \ + /**/ + + + // functions + // + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_begin(Params, Fullname) \ + template< Params > inline \ + typename boost::range_detail_microsoft::mutable_iterator_of< Fullname >::type \ + BOOST_RANGE_DETAIL_MICROSOFT_range_begin(Fullname& x) \ + { \ + return boost::range_detail_microsoft::begin_of(x); \ + } \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_begin_const(Params, Fullname) \ + template< Params > inline \ + typename boost::range_detail_microsoft::const_iterator_of< Fullname >::type \ + BOOST_RANGE_DETAIL_MICROSOFT_range_begin(Fullname const& x) \ + { \ + return boost::range_detail_microsoft::begin_of(x); \ + } \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_end(Params, Fullname) \ + template< Params > inline \ + typename boost::range_detail_microsoft::mutable_iterator_of< Fullname >::type \ + BOOST_RANGE_DETAIL_MICROSOFT_range_end(Fullname& x) \ + { \ + return boost::range_detail_microsoft::end_of(x); \ + } \ + /**/ + + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_end_const(Params, Fullname) \ + template< Params > inline \ + typename boost::range_detail_microsoft::const_iterator_of< Fullname >::type \ + BOOST_RANGE_DETAIL_MICROSOFT_range_end(Fullname const& x) \ + { \ + return boost::range_detail_microsoft::end_of(x); \ + } \ + /**/ + + + #if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1) + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size(Params, Fullname) \ + /**/ + + #else + + #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size(Params, Fullname) \ + template< Params > inline \ + typename boost::range_detail_microsoft::size_type_of< Fullname >::type \ + boost_range_size(Fullname const& x) \ + { \ + return boost::range_detail_microsoft::size_of(x); \ + } \ + /**/ + + #endif + + + + +// list_iterator and helpers +// + + +#include +#include +#include +#include +#include + + +// POSITION's header is undocumented, so is NULL. +// +struct __POSITION; // incomplete, but used as just a pointer. +typedef __POSITION *POSITION; + + +namespace boost { namespace range_detail_microsoft { + + + template< + class ListT, + class Value, + class Reference, + class Traversal + > + struct list_iterator; + + + template< + class ListT, + class Value, + class Reference, + class Traversal + > + struct list_iterator_super + { + typedef typename mpl::if_< is_same, + Value&, + Reference + >::type ref_t; + + typedef typename mpl::if_< is_same, + bidirectional_traversal_tag, + Traversal + >::type trv_t; + + typedef iterator_facade< + list_iterator, + Value, + trv_t, + ref_t + > type; + }; + + + template< + class ListT, + class Value, + class Reference = use_default, + class Traversal = use_default + > + struct list_iterator : + list_iterator_super::type + { + private: + typedef list_iterator self_t; + typedef typename list_iterator_super::type super_t; + typedef typename super_t::reference ref_t; + + public: + explicit list_iterator() + { } + + explicit list_iterator(ListT& lst, POSITION pos) : + m_plst(boost::addressof(lst)), m_pos(pos) + { } + + template< class, class, class, class > friend struct list_iterator; + template< class ListT_, class Value_, class Reference_, class Traversal_> + list_iterator(list_iterator const& other) : + m_plst(other.m_plst), m_pos(other.m_pos) + { } + + private: + ListT *m_plst; + POSITION m_pos; + + friend class iterator_core_access; + ref_t dereference() const + { + BOOST_ASSERT(m_pos != 0 && "out of range"); + return m_plst->GetAt(m_pos); + } + + // A B C D x + // Head Tail NULL(0) + // + void increment() + { + BOOST_ASSERT(m_pos != 0 && "out of range"); + m_plst->GetNext(m_pos); + } + + void decrement() + { + if (m_pos == 0) { + m_pos = m_plst->GetTailPosition(); + return; + } + + m_plst->GetPrev(m_pos); + } + + bool equal(self_t const& other) const + { + BOOST_ASSERT(m_plst == other.m_plst && "iterators incompatible"); + return m_pos == other.m_pos; + } + }; + + + // customization helpers + // + + struct array_functions + { + template< class Iterator, class X > + Iterator begin(X& x) + { + return x.GetData(); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return begin(x) + x.GetSize(); + } + }; + + + struct list_functions + { + template< class Iterator, class X > + Iterator begin(X& x) + { + return Iterator(x, x.GetHeadPosition()); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return Iterator(x, POSITION(0)); + } + }; + + +} } // namespace boost::range_detail_microsoft + + + + +// test +// + + +#if defined(BOOST_RANGE_DETAIL_MICROSOFT_TEST) + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace boost { namespace range_detail_microsoft { + + + template< class Range1, class Range2 > + bool test_equals(Range1 const& rng1, Range2 const& rng2) + { + return + boost::distance(rng1) == boost::distance(rng2) && + std::equal(boost::begin(rng1), boost::end(rng1), boost::begin(rng2)) + ; + } + + + template< class AssocContainer, class PairT > + bool test_find_key_and_mapped(AssocContainer const& ac, PairT const& pa) + { + typedef typename boost::range_const_iterator::type iter_t; + for (iter_t it = boost::const_begin(ac), last = boost::const_end(ac); it != last; ++it) { + if (it->first == pa.first && it->second == pa.second) + return true; + } + + return false; + } + + + // test functions + // + + template< class Range > + bool test_emptiness(Range& ) + { + bool result = true; + + Range emptyRng; + result = result && boost::empty(emptyRng); + + return result; + } + + + template< class Range > + bool test_trivial(Range& rng) + { + bool result = true; + + // convertibility check + typedef typename range_const_iterator::type citer_t; + citer_t cit = boost::begin(rng); + (void)cit; // unused + + // mutability check + typedef typename range_value::type val_t; + val_t v = *boost::begin(rng); + *boost::begin(rng) = v; + result = result && *boost::begin(rng) == v; + + return result; + } + + + template< class Range > + bool test_forward(Range& rng) + { + boost::function_requires< ForwardRangeConcept >(); + + bool result = (test_trivial)(rng); + + typedef typename range_value::type val_t; + + std::vector saved; + std::copy(boost::begin(rng), boost::end(rng), std::back_inserter(saved)); + std::rotate(boost::begin(saved), boost::next(boost::begin(saved)), boost::end(saved)); + + std::rotate(boost::begin(rng), boost::next(boost::begin(rng)), boost::end(rng)); + + return result && (test_equals)(saved, rng); + }; + + + template< class Range > + bool test_bidirectional(Range& rng) + { + boost::function_requires< BidirectionalRangeConcept >(); + + bool result = (test_forward)(rng); + + typedef typename range_value::type val_t; + + std::vector saved; + std::copy(boost::begin(rng), boost::end(rng), std::back_inserter(saved)); + + result = result && (test_equals)( + boost::make_iterator_range(boost::rbegin(saved), boost::rend(saved)), + boost::make_iterator_range(boost::rbegin(rng), boost::rend(rng)) + ); + + return result; + } + + + template< class Range > + bool test_random_access(Range& rng) + { + boost::function_requires< RandomAccessRangeConcept >(); + + bool result = (test_bidirectional)(rng); + + typedef typename range_value::type val_t; + + std::vector saved; + std::copy(boost::begin(rng), boost::end(rng), std::back_inserter(saved)); + std::sort(boost::begin(saved), boost::end(saved)); + + std::random_shuffle(boost::begin(rng), boost::end(rng)); + std::sort(boost::begin(rng), boost::end(rng)); + result = result && (test_equals)(rng, saved); + + std::random_shuffle(boost::begin(rng), boost::end(rng)); + std::stable_sort(boost::begin(rng), boost::end(rng)); + result = result && (test_equals)(rng, saved); + + std::random_shuffle(boost::begin(rng), boost::end(rng)); + std::partial_sort(boost::begin(rng), boost::end(rng), boost::end(rng)); + result = result && (test_equals)(rng, saved); + + return result; + } + + + // initializer + // + + template< class ArrayT, class SampleRange > + bool test_init_array(ArrayT& arr, SampleRange const& sample) + { + typedef typename range_const_iterator::type iter_t; + typedef typename range_value::type val_t; + + for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) { + val_t v = *it; // works around ATL3 CSimpleArray + arr.Add(v); + } + + return (test_equals)(arr, sample); + } + + + template< class ListT, class SampleRange > + bool test_init_list(ListT& lst, SampleRange const& sample) + { + typedef typename range_const_iterator::type iter_t; + + for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) { + lst.AddTail(*it); + } + + return (test_equals)(lst, sample); + } + + + template< class StringT, class SampleRange > + bool test_init_string(StringT& str, SampleRange const& sample) + { + typedef typename range_const_iterator::type iter_t; + typedef typename range_value::type val_t; + + for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) { + str += *it; + } + + return (test_equals)(str, sample); + } + + + template< class MapT, class SampleMap > + bool test_init_map(MapT& map, SampleMap const& sample) + { + typedef typename range_const_iterator::type iter_t; + + for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) { + map.SetAt(it->first, it->second); + } + + return boost::distance(map) == boost::distance(sample); + } + + + // metafunction test + // + + template< class Range, class Iter > + struct test_mutable_iter : + boost::is_same< typename boost::BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator::type, Iter > + { }; + + + template< class Range, class Iter > + struct test_const_iter : + boost::is_same< typename boost::range_const_iterator::type, Iter > + { }; + + +} } // namespace boost::range_detail_microsoft + + +#endif // defined(BOOST_RANGE_DETAIL_MICROSOFT_TEST) + + + + +#endif diff --git a/include/boost/range/mfc.hpp b/include/boost/range/mfc.hpp new file mode 100644 index 0000000..058e54e --- /dev/null +++ b/include/boost/range/mfc.hpp @@ -0,0 +1,984 @@ +#ifndef BOOST_RANGE_MFC_HPP +#define BOOST_RANGE_MFC_HPP + + + + +// Boost.Range MFC Extension +// +// Copyright Shunsuke Sogame 2005-2006. +// 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) + + + + +// config +// + + +#include // _MFC_VER + + +#if !defined(BOOST_RANGE_MFC_NO_CPAIR) + #if (_MFC_VER < 0x0700) // dubious + #define BOOST_RANGE_MFC_NO_CPAIR + #endif +#endif + + +#if !defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) + #if (_MFC_VER < 0x0700) // dubious + #define BOOST_RANGE_MFC_HAS_LEGACY_STRING + #endif +#endif + + +// A const collection of old MFC doesn't return const reference. +// +#if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + #if (_MFC_VER < 0x0700) // dubious + #define BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF + #endif +#endif + + + + +// forward declarations +// + + +template< class Type, class ArgType > +class CArray; + +template< class Type, class ArgType > +class CList; + +template< class Key, class ArgKey, class Mapped, class ArgMapped > +class CMap; + +template< class BaseClass, class PtrType > +class CTypedPtrArray; + +template< class BaseClass, class PtrType > +class CTypedPtrList; + +template< class BaseClass, class KeyPtrType, class MappedPtrType > +class CTypedPtrMap; + + + + +// extended customizations +// + + +#include // ptrdiff_t +#include // pair +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // legacy CString +#include // CXXXArray, CXXXList, CMapXXXToXXX +#include + + +namespace boost { namespace range_detail_microsoft { + + + // mfc_ptr_array_iterator + // + // 'void **' is not convertible to 'void const **', + // so we define... + // + + template< class ArrayT, class PtrType > + struct mfc_ptr_array_iterator; + + template< class ArrayT, class PtrType > + struct mfc_ptr_array_iterator_super + { + typedef iterator_adaptor< + mfc_ptr_array_iterator, + std::ptrdiff_t, // Base! + PtrType, // Value + random_access_traversal_tag, + use_default, + std::ptrdiff_t // Difference + > type; + }; + + template< class ArrayT, class PtrType > + struct mfc_ptr_array_iterator : + mfc_ptr_array_iterator_super::type + { + private: + typedef mfc_ptr_array_iterator self_t; + typedef typename mfc_ptr_array_iterator_super::type super_t; + typedef typename super_t::reference ref_t; + + public: + explicit mfc_ptr_array_iterator() + { } + + explicit mfc_ptr_array_iterator(ArrayT& arr, INT_PTR index) : + super_t(index), m_parr(boost::addressof(arr)) + { } + + template< class, class > friend struct mfc_ptr_array_iterator; + template< class ArrayT_, class PtrType_ > + mfc_ptr_array_iterator(mfc_ptr_array_iterator const& other) : + super_t(other.base()), m_parr(other.m_parr) + { } + + private: + ArrayT *m_parr; + + friend class iterator_core_access; + ref_t dereference() const + { + BOOST_ASSERT(0 <= this->base() && this->base() < m_parr->GetSize() && "out of range"); + return *( m_parr->GetData() + this->base() ); + } + + bool equal(self_t const& other) const + { + BOOST_ASSERT(m_parr == other.m_parr && "iterators incompatible"); + return this->base() == other.base(); + } + }; + + struct mfc_ptr_array_functions + { + template< class Iterator, class X > + Iterator begin(X& x) + { + return Iterator(x, 0); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return Iterator(x, x.GetSize()); + } + }; + + + // arrays + // + + template< > + struct customization< ::CByteArray > : + array_functions + { + template< class X > + struct meta + { + typedef BYTE val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + + template< > + struct customization< ::CDWordArray > : + array_functions + { + template< class X > + struct meta + { + typedef DWORD val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + + template< > + struct customization< ::CObArray > : + mfc_ptr_array_functions + { + template< class X > + struct meta + { + typedef mfc_ptr_array_iterator mutable_iterator; + typedef mfc_ptr_array_iterator const_iterator; + }; + }; + + + template< > + struct customization< ::CPtrArray > : + mfc_ptr_array_functions + { + template< class X > + struct meta + { + typedef mfc_ptr_array_iterator mutable_iterator; + typedef mfc_ptr_array_iterator const_iterator; + }; + }; + + + template< > + struct customization< ::CStringArray > : + array_functions + { + template< class X > + struct meta + { + typedef ::CString val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + + template< > + struct customization< ::CUIntArray > : + array_functions + { + template< class X > + struct meta + { + typedef UINT val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + + template< > + struct customization< ::CWordArray > : + array_functions + { + template< class X > + struct meta + { + typedef WORD val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + + // lists + // + + template< > + struct customization< ::CObList > : + list_functions + { + template< class X > + struct meta + { + typedef list_iterator mutable_iterator; + #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + typedef list_iterator const_iterator; + #else + typedef list_iterator const_iterator; + #endif + }; + }; + + + template< > + struct customization< ::CPtrList > : + list_functions + { + template< class X > + struct meta + { + typedef list_iterator mutable_iterator; + #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + typedef list_iterator const_iterator; + #else + typedef list_iterator const_iterator; + #endif + }; + }; + + + template< > + struct customization< ::CStringList > : + list_functions + { + template< class X > + struct meta + { + typedef ::CString val_t; + + typedef list_iterator mutable_iterator; + #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + typedef list_iterator const_iterator; + #else + typedef list_iterator const_iterator; + #endif + }; + }; + + + // mfc_map_iterator + // + + template< class MapT, class KeyT, class MappedT > + struct mfc_map_iterator; + + template< class MapT, class KeyT, class MappedT > + struct mfc_map_iterator_super + { + typedef iterator_facade< + mfc_map_iterator, + std::pair, + forward_traversal_tag, + std::pair const + > type; + }; + + template< class MapT, class KeyT, class MappedT > + struct mfc_map_iterator : + mfc_map_iterator_super::type + { + private: + typedef mfc_map_iterator self_t; + typedef typename mfc_map_iterator_super::type super_t; + typedef typename super_t::reference ref_t; + + public: + explicit mfc_map_iterator() + { } + + explicit mfc_map_iterator(MapT const& map, POSITION pos) : + m_pmap(boost::addressof(map)), m_posNext(pos) + { + increment(); + } + + explicit mfc_map_iterator(MapT const& map) : + m_pmap(&map), m_pos(0) // end iterator + { } + + template< class, class, class > friend struct mfc_map_iterator; + template< class MapT_, class KeyT_, class MappedT_> + mfc_map_iterator(mfc_map_iterator const& other) : + m_pmap(other.m_pmap), + m_pos(other.m_pos), m_posNext(other.m_posNext), + m_key(other.m_key), m_mapped(other.m_mapped) + { } + + private: + MapT const *m_pmap; + POSITION m_pos, m_posNext; + KeyT m_key; MappedT m_mapped; + + friend class iterator_core_access; + ref_t dereference() const + { + BOOST_ASSERT(m_pos != 0 && "out of range"); + return std::make_pair(m_key, m_mapped); + } + + void increment() + { + BOOST_ASSERT(m_pos != 0 && "out of range"); + + if (m_posNext == 0) { + m_pos = 0; + return; + } + + m_pos = m_posNext; + m_pmap->GetNextAssoc(m_posNext, m_key, m_mapped); + } + + bool equal(self_t const& other) const + { + BOOST_ASSERT(m_pmap == other.m_pmap && "iterators incompatible"); + return m_pos == other.m_pos; + } + }; + + struct mfc_map_functions + { + template< class Iterator, class X > + Iterator begin(X& x) + { + return Iterator(x, x.GetStartPosition()); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return Iterator(x); + } + }; + + +#if !defined(BOOST_RANGE_MFC_NO_CPAIR) + + + // mfc_cpair_map_iterator + // + // used by ::CMap and ::CMapStringToString + // + + template< class MapT, class PairT > + struct mfc_cpair_map_iterator; + + template< class MapT, class PairT > + struct mfc_pget_map_iterator_super + { + typedef iterator_facade< + mfc_cpair_map_iterator, + PairT, + forward_traversal_tag + > type; + }; + + template< class MapT, class PairT > + struct mfc_cpair_map_iterator : + mfc_pget_map_iterator_super::type + { + private: + typedef mfc_cpair_map_iterator self_t; + typedef typename mfc_pget_map_iterator_super::type super_t; + typedef typename super_t::reference ref_t; + + public: + explicit mfc_cpair_map_iterator() + { } + + explicit mfc_cpair_map_iterator(MapT& map, PairT *pp) : + m_pmap(boost::addressof(map)), m_pp(pp) + { } + + template< class, class > friend struct mfc_cpair_map_iterator; + template< class MapT_, class PairT_> + mfc_cpair_map_iterator(mfc_cpair_map_iterator const& other) : + m_pmap(other.m_pmap), m_pp(other.m_pp) + { } + + private: + MapT *m_pmap; + PairT *m_pp; + + friend class iterator_core_access; + ref_t dereference() const + { + BOOST_ASSERT(m_pp != 0 && "out of range"); + return *m_pp; + } + + void increment() + { + BOOST_ASSERT(m_pp != 0 && "out of range"); + m_pp = m_pmap->PGetNextAssoc(m_pp); + } + + bool equal(self_t const& other) const + { + BOOST_ASSERT(m_pmap == other.m_pmap && "iterators incompatible"); + return m_pp == other.m_pp; + } + }; + + struct mfc_cpair_map_functions + { + template< class Iterator, class X > + Iterator begin(X& x) + { + // Workaround: + // Assertion fails if empty. + // MFC document is wrong. + #if !defined(NDEBUG) + if (x.GetCount() == 0) + return Iterator(x, 0); + #endif + + return Iterator(x, x.PGetFirstAssoc()); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return Iterator(x, 0); + } + }; + + +#endif // !defined(BOOST_RANGE_MFC_NO_CPAIR) + + + // maps + // + + template< > + struct customization< ::CMapPtrToWord > : + mfc_map_functions + { + template< class X > + struct meta + { + typedef void *key_t; + typedef WORD mapped_t; + + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + }; + }; + + + template< > + struct customization< ::CMapPtrToPtr > : + mfc_map_functions + { + template< class X > + struct meta + { + typedef void *key_t; + typedef void *mapped_t; + + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + }; + }; + + + template< > + struct customization< ::CMapStringToOb > : + mfc_map_functions + { + template< class X > + struct meta + { + typedef ::CString key_t; + typedef ::CObject *mapped_t; + + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + }; + }; + + + template< > + struct customization< ::CMapStringToPtr > : + mfc_map_functions + { + template< class X > + struct meta + { + typedef ::CString key_t; + typedef void *mapped_t; + + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + }; + }; + + + template< > + struct customization< ::CMapStringToString > : + #if !defined(BOOST_RANGE_MFC_NO_CPAIR) + mfc_cpair_map_functions + #else + mfc_map_functions + #endif + { + template< class X > + struct meta + { + #if !defined(BOOST_RANGE_MFC_NO_CPAIR) + typedef typename X::CPair pair_t; + + typedef mfc_cpair_map_iterator mutable_iterator; + typedef mfc_cpair_map_iterator const_iterator; + #else + typedef ::CString key_t; + typedef ::CString mapped_t; + + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + #endif + }; + }; + + + template< > + struct customization< ::CMapWordToOb > : + mfc_map_functions + { + template< class X > + struct meta + { + typedef WORD key_t; + typedef ::CObject *mapped_t; + + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + }; + }; + + + template< > + struct customization< ::CMapWordToPtr > : + mfc_map_functions + { + template< class X > + struct meta + { + typedef WORD key_t; + typedef void *mapped_t; + + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + }; + }; + + + // templates + // + + template< class Type, class ArgType > + struct customization< ::CArray > : + array_functions + { + template< class X > + struct meta + { + typedef Type val_t; + + typedef val_t *mutable_iterator; + typedef val_t const *const_iterator; + }; + }; + + + template< class Type, class ArgType > + struct customization< ::CList > : + list_functions + { + template< class X > + struct meta + { + typedef Type val_t; + + typedef list_iterator mutable_iterator; + #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + typedef list_iterator const_iterator; + #else + typedef list_iterator const_iterator; + #endif + }; + }; + + + template< class Key, class ArgKey, class Mapped, class ArgMapped > + struct customization< ::CMap > : + #if !defined(BOOST_RANGE_MFC_NO_CPAIR) + mfc_cpair_map_functions + #else + mfc_map_functions + #endif + { + template< class X > + struct meta + { + #if !defined(BOOST_RANGE_MFC_NO_CPAIR) + typedef typename X::CPair pair_t; + + typedef mfc_cpair_map_iterator mutable_iterator; + typedef mfc_cpair_map_iterator const_iterator; + #else + typedef Key key_t; + typedef Mapped mapped_t; + + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + #endif + }; + }; + + + template< class BaseClass, class PtrType > + struct customization< ::CTypedPtrArray > + { + template< class X > + struct fun + { + typedef typename remove_pointer::type val_t; + + typedef typename mpl::if_< is_const, + val_t const, + val_t + >::type val_t_; + + typedef val_t_ * const result_type; + + template< class PtrType_ > + result_type operator()(PtrType_ p) const + { + return static_cast(p); + } + }; + + template< class X > + struct meta + { + typedef typename compatible_mutable_iterator::type miter_t; + typedef typename range_const_iterator::type citer_t; + + typedef transform_iterator, miter_t> mutable_iterator; + typedef transform_iterator, citer_t> const_iterator; + }; + + template< class Iterator, class X > + Iterator begin(X& x) + { + return Iterator(boost::begin(x), fun()); + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return Iterator(boost::end(x), fun()); + } + }; + + + template< class BaseClass, class PtrType > + struct customization< ::CTypedPtrList > : + list_functions + { + template< class X > + struct meta + { + typedef typename remove_pointer::type val_t; + + // not l-value + typedef list_iterator mutable_iterator; + typedef list_iterator const_iterator; + }; + }; + + + template< class BaseClass, class KeyPtrType, class MappedPtrType > + struct customization< ::CTypedPtrMap > : + mfc_map_functions + { + template< class X > + struct meta + { + typedef mfc_map_iterator mutable_iterator; + typedef mutable_iterator const_iterator; + }; + }; + + + // strings + // + +#if defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) + + template< > + struct customization< ::CString > + { + template< class X > + struct meta + { + // LPTSTR/LPCTSTR is not always defined in . + typedef TCHAR *mutable_iterator; + typedef TCHAR const *const_iterator; + }; + + template< class Iterator, class X > + typename mutable_::type begin(X& x) + { + return x.GetBuffer(0); + } + + template< class Iterator, class X > + Iterator begin(X const& x) + { + return x; + } + + template< class Iterator, class X > + Iterator end(X& x) + { + return begin(x) + x.GetLength(); + } + }; + +#endif // defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) + + +} } // namespace boost::range_detail_microsoft + + + + +// range customizations +// + + +// arrays +// +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CByteArray +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CDWordArray +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CStringArray +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CUIntArray +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CWordArray +) + + +// lists +// +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CObList +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CPtrList +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CStringList +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CObArray +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CPtrArray +) + + +// maps +// +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CMapPtrToWord +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CMapPtrToPtr +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CMapStringToOb +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CMapStringToPtr +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CMapStringToString +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CMapWordToOb +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CMapWordToPtr +) + + +// templates +// +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CArray, 2 +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CList, 2 +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CMap, 4 +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CTypedPtrArray, 2 +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CTypedPtrList, 2 +) + +BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CTypedPtrMap, 3 +) + + +// strings +// +#if defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) + + BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( + boost::range_detail_microsoft::using_type_as_tag, + BOOST_PP_NIL, CString + ) + +#endif + + + + +#endif From 4db083cd6dd8675f83503ab172eef00b4e44e3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 23 Oct 2007 20:28:52 +0000 Subject: [PATCH 14/57] Shunsuke Sogame's MFC/ATL docs and tests [SVN r40381] --- doc/mfc_atl.html | 313 +++++++++++++++++++ doc/mfc_atl.rst | 232 ++++++++++++++ test/atl.cpp | 623 +++++++++++++++++++++++++++++++++++++ test/mfc.cpp | 789 +++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 1892 insertions(+), 65 deletions(-) create mode 100644 doc/mfc_atl.html create mode 100644 doc/mfc_atl.rst create mode 100644 test/atl.cpp diff --git a/doc/mfc_atl.html b/doc/mfc_atl.html new file mode 100644 index 0000000..5717cc8 --- /dev/null +++ b/doc/mfc_atl.html @@ -0,0 +1,313 @@ + + + + + + +Boost Range MFC/ATL Extension + + + + + + +
+

Boost Range MFC/ATL Extension

+ +++ + + + + + + + + + +
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).
+
+

Overview

+

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));
+        ...
+    }
+}
+
+ +
+
+

Requirements

+ +
+
+

MFC Ranges

+

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.

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RangeTraversal Categoryrange_reference<Range>::type
CArray<T,A>Random AccessT&
CList<T,A>BidirectionalT&
CMap<K,AK,M,AM>ForwardRange::CPair&
CTypedPtrArray<B,T*>Random AccessT* const
CTypedPtrList<B,T*>BidirectionalT* const
CTypedPtrMap<B,T*,V*>Forwardstd::pair<T*,V*> const
CByteArrayRandom AccessBYTE&
CDWordArrayRandom AccessDWORD&
CObArrayRandom AccessCObject* &
CPtrArrayRandom Accessvoid* &
CStringArrayRandom AccessCString&
CUIntArrayRandom AccessUINT&
CWordArrayRandom AccessWORD&
CObListBidirectionalCObject* &
CPtrListBidirectionalvoid* &
CStringListBidirectionalCString&
CMapPtrToWordForwardstd::pair<void*,WORD> const
CMapPtrToPtrForwardstd::pair<void*,void*> const
CMapStringToObForwardstd::pair<String,CObject*> const
CMapStringToStringForwardRange::CPair&
CMapWordToObForwardstd::pair<WORD,CObject*> const
CMapWordToPtrForwardstd::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.

+
+
+

ATL 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.

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RangeTraversal Categoryrange_reference<Range>::type
CAtlArray<E,ET>Random AccessE&
CAutoPtrArray<E>Random AccessE&
CInterfaceArray<I,pi>Random AccessCComQIPtr<I,pi>&
CAtlList<E,ET>BidirectionalE&
CAutoPtrList<E>BidirectionalE&
CHeapPtrList<E,A>BidirectionalE&
CInterfaceList<I,pi>BidirectionalCComQIPtr<I,pi>&
CAtlMap<K,V,KT,VT>ForwardRange::CPair&
CRBTree<K,V,KT,VT>BidirectionalRange::CPair&
CRBMap<K,V,KT,VT>BidirectionalRange::CPair&
CRBMultiMap<K,V,KT,VT>BidirectionalRange::CPair&
CSimpleStringT<B,b>Random AccessB&
CStringT<B,ST>Random AccessB&
CFixedStringT<S,n>Random Accessrange_reference<S>::type
CStringT<B,ST>Random AccessB&
CComBSTRRandom AccessOLECHAR&
CSimpleArray<T,TE>Random AccessT&
+

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.

+
+
+

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.

+
+ +
+ + + diff --git a/doc/mfc_atl.rst b/doc/mfc_atl.rst new file mode 100644 index 0000000..3dcd8fe --- /dev/null +++ b/doc/mfc_atl.rst @@ -0,0 +1,232 @@ + +++++++++++++++++++++++++++++++++ + |Boost| Range MFC/ATL Extension +++++++++++++++++++++++++++++++++ + +.. |Boost| image:: http://www.boost.org/libs/ptr_container/doc/boost.png + + + +: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__). + +__ http://www.boost.org/LICENSE_1_0.txt + + + +======== +Overview +======== + +Boost.Range MFC/ATL Extension provides `Boost.Range`_ support for MFC/ATL collection and string types. + + +.. parsed-literal:: + + CTypedPtrArray \*> myArray; + ... + BOOST_FOREACH (CList \*theList, myArray) + { + BOOST_FOREACH (CString& str, \*theList) + { + boost::to_upper(str); + std::sort(boost::begin(str), boost::end(str)); + ... + } + } + + + +* `Requirements`_ +* `MFC Ranges`_ +* `ATL Ranges`_ +* `const Ranges`_ +* `References`_ + + + +============ +Requirements +============ + +- `Boost C++ Libraries Version 1.34.0`__ or later (no compilation required) +- Visual C++ 7.1 or Visual C++ 8.0 + +__ Boost_ + + + +========== +MFC Ranges +========== + +If the ```` 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::type`` +============================= ================== ======================================= +``CArray`` Random Access ``T&`` +----------------------------- ------------------ --------------------------------------- +``CList`` Bidirectional ``T&`` +----------------------------- ------------------ --------------------------------------- +``CMap`` Forward ``Range::CPair&`` +----------------------------- ------------------ --------------------------------------- +``CTypedPtrArray`` Random Access ``T* const`` +----------------------------- ------------------ --------------------------------------- +``CTypedPtrList`` Bidirectional ``T* const`` +----------------------------- ------------------ --------------------------------------- +``CTypedPtrMap`` Forward ``std::pair 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 const`` +----------------------------- ------------------ --------------------------------------- +``CMapPtrToPtr`` Forward ``std::pair const`` +----------------------------- ------------------ --------------------------------------- +``CMapStringToOb`` Forward ``std::pair const`` +----------------------------- ------------------ --------------------------------------- +``CMapStringToString`` Forward ``Range::CPair&`` +----------------------------- ------------------ --------------------------------------- +``CMapWordToOb`` Forward ``std::pair const`` +----------------------------- ------------------ --------------------------------------- +``CMapWordToPtr`` Forward ``std::pair 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::type``. +``range_value::type`` is the same as ``remove_reference::type>::type``, +``range_difference::type`` is the same as ``std::ptrdiff_t``, and +``range_pointer::type`` is the same as ``add_pointer::type>::type``. +As for ``const Range``, see `const Ranges`_. + + + +========== +ATL Ranges +========== + +If the ```` 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::type`` +============================= ================== ======================================= +``CAtlArray`` Random Access ``E&`` +----------------------------- ------------------ --------------------------------------- +``CAutoPtrArray`` Random Access ``E&`` +----------------------------- ------------------ --------------------------------------- +``CInterfaceArray`` Random Access ``CComQIPtr&`` +----------------------------- ------------------ --------------------------------------- +``CAtlList`` Bidirectional ``E&`` +----------------------------- ------------------ --------------------------------------- +``CAutoPtrList`` Bidirectional ``E&`` +----------------------------- ------------------ --------------------------------------- +``CHeapPtrList`` Bidirectional ``E&`` +----------------------------- ------------------ --------------------------------------- +``CInterfaceList`` Bidirectional ``CComQIPtr&`` +----------------------------- ------------------ --------------------------------------- +``CAtlMap`` Forward ``Range::CPair&`` +----------------------------- ------------------ --------------------------------------- +``CRBTree`` Bidirectional ``Range::CPair&`` +----------------------------- ------------------ --------------------------------------- +``CRBMap`` Bidirectional ``Range::CPair&`` +----------------------------- ------------------ --------------------------------------- +``CRBMultiMap`` Bidirectional ``Range::CPair&`` +----------------------------- ------------------ --------------------------------------- +``CSimpleStringT`` Random Access ``B&`` +----------------------------- ------------------ --------------------------------------- +``CStringT`` Random Access ``B&`` +----------------------------- ------------------ --------------------------------------- +``CFixedStringT`` Random Access ``range_reference::type`` +----------------------------- ------------------ --------------------------------------- +``CStringT`` Random Access ``B&`` +----------------------------- ------------------ --------------------------------------- +``CComBSTR`` Random Access ``OLECHAR&`` +----------------------------- ------------------ --------------------------------------- +``CSimpleArray`` 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::type``. +``range_value::type`` is the same as ``remove_reference::type``, +``range_difference::type`` is the same as ``std::ptrdiff_t``, and +``range_pointer::type`` is the same as ``add_pointer::type>::type``. +As for ``const Range``, see `const Ranges`_. + + + +============ +const Ranges +============ + +``range_reference::type`` is defined by the following algorithm. +Let ``Range`` be any type listed above and ``ReF`` be the same as ``range_reference::type``. + + +.. parsed-literal:: + + 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::type`` is the same as ``range_value::type``, +``range_difference::type`` is the same as ``std::ptrdiff_t``, and +``range_pointer::type`` is the same as ``add_pointer::type>::type>::type``. + + + +========== +References +========== +- `Boost.Range`_ +- `MFC Collections`__ +- `ATL Collection Classes`__ + +__ http://msdn2.microsoft.com/en-us/library/942860sh.aspx +__ http://msdn2.microsoft.com/en-US/library/15e672bd.aspx + + + +.. _Boost C++ Libraries: http://www.boost.org/ +.. _Boost: `Boost C++ Libraries`_ +.. _Boost.Range: http://www.boost.org/libs/range/ +.. _forward: http://www.boost.org/libs/range/doc/range.html#forward_range +.. _bidirectional: http://www.boost.org/libs/range/doc/range.html#forward_range +.. _random access: http://www.boost.org/libs/range/doc/range.html#random_access_range + diff --git a/test/atl.cpp b/test/atl.cpp new file mode 100644 index 0000000..50905b1 --- /dev/null +++ b/test/atl.cpp @@ -0,0 +1,623 @@ + + +// Boost.Range ATL Extension +// +// Copyright Shunsuke Sogame 2005-2006. +// 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) + + +// #include + +#include +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS +#define _ATL_NO_AUTOMATIC_NAMESPACE + +#define BOOST_LIB_NAME boost_test_exec_monitor +#include + +#define BOOST_RANGE_DETAIL_MICROSOFT_TEST +#include // can be placed first + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include + + +#include // for ATL3 CSimpleArray/CSimpleValArray +#if !(_ATL_VER < 0x0700) + #include + #include + #include + #include +#endif + + +namespace brdm = boost::range_detail_microsoft; + + +#if !(_ATL_VER < 0x0700) + + +template< class ArrayT, class SampleRange > +bool test_init_auto_ptr_array(ArrayT& arr, SampleRange& sample) +{ + typedef typename boost::range_iterator::type iter_t; + + for (iter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) { + arr.Add(*it); // moves ownership + } + + return boost::distance(arr) == boost::distance(sample); +} + + +template< class ListT, class SampleRange > +bool test_init_auto_ptr_list(ListT& lst, SampleRange& sample) +{ + typedef typename boost::range_iterator::type iter_t; + typedef typename boost::range_value::type val_t; + + for (iter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) { + lst.AddTail(*it); // moves ownership + } + + return boost::distance(lst) == boost::distance(sample); +} + + +// Workaround: +// CRBTree provides no easy access function, but yes, it is the range! +// +template< class AtlMapT, class KeyT, class MappedT > +bool test_atl_map_has(AtlMapT& map, const KeyT& k, const MappedT m) +{ + typedef typename boost::range_iterator::type iter_t; + + for (iter_t it = boost::begin(map), last = boost::end(map); it != last; ++it) { + if (it->m_key == k && it->m_value == m) + return true; + } + + return false; +} + + +template< class AtlMapT, class MapT > +bool test_atl_map(AtlMapT& map, const MapT& sample) +{ + typedef typename boost::range_iterator::type iter_t; + typedef typename boost::range_const_iterator::type siter_t; + + bool result = true; + + result = result && (boost::distance(map) == boost::distance(sample)); + if (!result) + return false; + + { + for (iter_t it = boost::begin(map), last = boost::end(map); it != last; ++it) { + result = result && brdm::test_find_key_and_mapped(sample, std::make_pair(it->m_key, it->m_value)); + } + } + + { + for (siter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) { + result = result && (test_atl_map_has)(map, it->first, it->second); + } + } + + return result; +} + + +template< class MapT, class SampleMap > +bool test_init_atl_multimap(MapT& map, const SampleMap& sample) +{ + typedef typename boost::range_const_iterator::type iter_t; + + for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) { + map.Insert(it->first, it->second); + } + + return boost::distance(map) == boost::distance(sample); +} + + +// arrays +// + +template< class Range > +void test_CAtlArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ATL::CAtlArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class ValT, class Range > +void test_CAutoPtrArray(Range& sample) +{ + typedef ValT val_t; + + typedef ATL::CAutoPtrArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter *> >::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter const*> >::value )); + + rng_t rng; + BOOST_CHECK( ::test_init_auto_ptr_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class I, class Range > +void test_CInterfaceArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ATL::CInterfaceArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter * >::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter const* >::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +// lists +// + +template< class Range > +void test_CAtlList(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ATL::CAtlList rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator >::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_list(rng, sample) ); + BOOST_CHECK( brdm::test_bidirectional(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class ValT, class Range > +void test_CAutoPtrList(Range& sample) +{ + typedef ValT val_t; + + typedef ATL::CAutoPtrList rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, boost::indirect_iterator< brdm::list_iterator > > >::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, boost::indirect_iterator< brdm::list_iterator const> > >::value )); + + rng_t rng; + BOOST_CHECK( ::test_init_auto_ptr_list(rng, sample) ); + BOOST_CHECK( brdm::test_bidirectional(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class ValT, class Range > +void test_CHeapPtrList(const Range& sample) +{ + typedef ValT val_t; + + typedef ATL::CHeapPtrList rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, boost::indirect_iterator< brdm::list_iterator > > >::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, boost::indirect_iterator< brdm::list_iterator const> > >::value )); + + rng_t rng; + BOOST_CHECK( ::test_init_auto_ptr_list(rng, sample) ); + BOOST_CHECK( brdm::test_bidirectional(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class I, class Range > +void test_CInterfaceList(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ATL::CInterfaceList rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator > >::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator const> >::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_list(rng, sample) ); + BOOST_CHECK( brdm::test_bidirectional(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +// strings +// + +template< class Range > +void test_CSimpleStringT(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef typename boost::mpl::if_< boost::is_same, + ATL::CAtlStringA, + ATL::CAtlStringW + >::type derived_t; + + typedef ATL::CSimpleStringT rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + derived_t drng; + rng_t& rng = drng; + BOOST_CHECK( brdm::test_init_string(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + // BOOST_CHECK( brdm::test_emptiness(rng) ); no default constructible +} + + +template< int n, class Range > +void test_CFixedStringT(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef typename boost::mpl::if_< boost::is_same, + ATL::CAtlStringA, + ATL::CAtlStringW + >::type base_t; + + typedef ATL::CFixedStringT rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_string(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CStringT(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef typename boost::mpl::if_< boost::is_same, + ATL::CAtlStringA, // == CStringT + ATL::CAtlStringW // == CStringT + >::type rng_t; + + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_string(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CStaticString(const Range& sample) +{ +#if !defined(BOOST_RANGE_ATL_NO_TEST_UNDOCUMENTED_RANGE) + { + typedef ATL::CStaticString rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng("hello static string"); + BOOST_CHECK( *(boost::begin(rng)+4) == 'o' ); + BOOST_CHECK( *(boost::end(rng)-3) == 'i' ); + } + + { + typedef ATL::CStaticString rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng(L"hello static string"); + BOOST_CHECK( *(boost::begin(rng)+4) == L'o' ); + BOOST_CHECK( *(boost::end(rng)-3) == L'i' ); + } +#endif + + (void)sample; // unused +} + + +#endif // !(_ATL_VER < 0x0700) + + +template< class Range > +void test_CComBSTR(const Range& sample) +{ + typedef ATL::CComBSTR rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng(OLESTR("hello CComBSTR range!")); + BOOST_CHECK( brdm::test_equals(rng, std::string("hello CComBSTR range!")) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); + + (void)sample; // unused +} + + +// simples +// + +template< class Range > +void test_CSimpleArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ATL::CSimpleArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CSimpleMap(const Range& sample) +{ +#if !defined(BOOST_RANGE_ATL_NO_TEST_UNDOCUMENTED_RANGE) + + typedef ATL::CSimpleMap rng_t; + + rng_t rng; + rng.Add(3, 3.0); + rng.Add(4, 2.0); + + BOOST_CHECK( boost::begin(rng)->get<0>() == 3.0 ); + BOOST_CHECK( (boost::end(rng)-1)->get<1>() == 2.0 ); + +#endif + + (void)sample; // unused +} + + +template< class Range > +void test_CSimpleValArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ATL::CSimpleArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +// maps +// + +template< class MapT > +void test_CAtlMap(const MapT& sample) +{ + typedef typename MapT::key_type k_t; + typedef typename MapT::mapped_type m_t; + + typedef ATL::CAtlMap rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); + BOOST_CHECK( ::test_atl_map(rng, sample) ); +} + + +template< class MapT > +void test_CRBTree(const MapT& sample) +{ + typedef typename MapT::key_type k_t; + typedef typename MapT::mapped_type m_t; + + typedef ATL::CRBMap derived_t; + typedef ATL::CRBTree rng_t; + + derived_t drng; + rng_t& rng = drng; + + boost::function_requires< boost::BidirectionalRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(drng, sample) ); + BOOST_CHECK( ::test_atl_map(rng, sample) ); +} + + +template< class MapT > +void test_CRBMap(const MapT& sample) +{ + typedef typename MapT::key_type k_t; + typedef typename MapT::mapped_type m_t; + + typedef ATL::CRBMap rng_t; + + rng_t rng; + boost::function_requires< boost::BidirectionalRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); + BOOST_CHECK( ::test_atl_map(rng, sample) ); +} + + +template< class MapT > +void test_CRBMultiMap(const MapT& sample) +{ + typedef typename MapT::key_type k_t; + typedef typename MapT::mapped_type m_t; + + typedef ATL::CRBMultiMap rng_t; + + rng_t rng; + boost::function_requires< boost::BidirectionalRangeConcept >(); + BOOST_CHECK( ::test_init_atl_multimap(rng, sample) ); + BOOST_CHECK( ::test_atl_map(rng, sample) ); +} + + +// main test +// + +void test_atl() +{ + + // ordinary ranges + // + { + std::string sample("rebecca judy and mary whiteberry chat monchy"); +#if !(_ATL_VER < 0x0700) + ::test_CAtlArray(sample); + ::test_CAtlList(sample); + ::test_CSimpleStringT(sample); + ::test_CFixedStringT<44>(sample); + ::test_CStringT(sample); + ::test_CStaticString(sample); +#endif + ::test_CComBSTR(sample); + ::test_CSimpleArray(sample); + ::test_CSimpleMap(sample); + ::test_CSimpleValArray(sample); + } + + + { + std::wstring sample(L"rebecca judy and mary whiteberry chat monchy"); +#if !(_ATL_VER < 0x0700) + ::test_CAtlArray(sample); + ::test_CAtlList(sample); + ::test_CSimpleStringT(sample); + ::test_CFixedStringT<44>(sample); + ::test_CStringT(sample); + ::test_CStaticString(sample); +#endif + ::test_CComBSTR(sample); + ::test_CSimpleArray(sample); + ::test_CSimpleMap(sample); + ::test_CSimpleValArray(sample); + } + + // pointer ranges + // +#if !(_ATL_VER < 0x0700) + { + typedef ATL::CAutoPtr ptr_t; + ptr_t + ptr0(new int(3)), ptr1(new int(4)), ptr2(new int(5)), ptr3(new int(4)), + ptr4(new int(1)), ptr5(new int(2)), ptr6(new int(4)), ptr7(new int(0)); + + ptr_t ptrs[8] = { + ptr0, ptr1, ptr2, ptr3, ptr4, ptr5, ptr6, ptr7 + }; + + boost::iterator_range< ptr_t * > workaround(ptrs, ptrs+8); + ::test_CAutoPtrArray(workaround); + } + + { + typedef ATL::CAutoPtr ptr_t; + ptr_t + ptr0(new int(3)), ptr1(new int(4)), ptr2(new int(5)), ptr3(new int(4)), + ptr4(new int(1)), ptr5(new int(2)), ptr6(new int(4)), ptr7(new int(0)); + + ptr_t ptrs[8] = { + ptr0, ptr1, ptr2, ptr3, ptr4, ptr5, ptr6, ptr7 + }; + + boost::iterator_range< ptr_t * > workaround(ptrs, ptrs+8); + ::test_CAutoPtrList(workaround); + } + + { + typedef ATL::CHeapPtr ptr_t; + ptr_t ptrs[5]; { + ptrs[0].AllocateBytes(sizeof(int)); + ptrs[1].AllocateBytes(sizeof(int)); + ptrs[2].AllocateBytes(sizeof(int)); + ptrs[3].AllocateBytes(sizeof(int)); + ptrs[4].AllocateBytes(sizeof(int)); + } + + boost::iterator_range< ptr_t * > workaround(ptrs, ptrs+5); + ::test_CHeapPtrList(workaround); + } + + + { + typedef ATL::CComQIPtr ptr_t; + ptr_t ptrs[8]; + + boost::iterator_range< ptr_t * > workaround(ptrs, ptrs+8); + ::test_CInterfaceArray(workaround); + ::test_CInterfaceList(workaround); + } +#endif + + // maps + // + { +#if !(_ATL_VER < 0x0700) + std::map sample; { + sample[0] = "hello"; + sample[1] = "range"; + sample[2] = "atl"; + sample[3] = "mfc"; + sample[4] = "collections"; + } + + ::test_CAtlMap(sample); + ::test_CRBTree(sample); + ::test_CRBMap(sample); + ::test_CRBMultiMap(sample); +#endif + } + + +} // test_atl + + +#include +using boost::unit_test::test_suite; + + +test_suite * +init_unit_test_suite(int argc, char* argv[]) +{ + test_suite *test = BOOST_TEST_SUITE("ATL Range Test Suite"); + test->add(BOOST_TEST_CASE(&test_atl)); + + (void)argc, (void)argv; // unused + return test; +} diff --git a/test/mfc.cpp b/test/mfc.cpp index c429993..29f2234 100755 --- a/test/mfc.cpp +++ b/test/mfc.cpp @@ -1,86 +1,745 @@ -// Boost.Range library -// -// Copyright Thorsten Ottosen 2003-2004. Use, modification and -// distribution is subject to 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) -// -// For more information, see http://www.boost.org/libs/range/ + + +// Boost.Range MFC Extension // +// Copyright Shunsuke Sogame 2005-2006. +// 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) -#define _MSL_USING_NAMESPACE 1 -#include +#include // must be here -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) -# pragma warn -8091 // supress warning in Boost.Test -# pragma warn -8057 // unused argument argc/argv in Boost.Test -#endif - -#define BOOST_RANGE_ENABLE_MFC -#define BOOST_RANGE_ENABLE_MCF_CARRAY - -/* -#define WIN32 -#define _WINDOWS -#define _MBCS -#define _AFXDLL -#define _ATL_DLL -*/ - -///Od /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_MBCS" /D "_AFXDLL" /D "_ATL_DLL" /Gm /EHsc /RTC1 -// /MDd /Zc:wchar_t /Yu"stdafx.h" /Fp"Debug/Foo.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Wp64 /ZI /TP - -#include -#include -#include +// #include #include -#include +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS +#define _ATL_NO_AUTOMATIC_NAMESPACE + +#define BOOST_LIB_NAME boost_test_exec_monitor +#include + +#define BOOST_RANGE_DETAIL_MICROSOFT_TEST +#include // can be placed first -void check_mfc() +#include +#include +// #include +#include +#include +#include +#include +#include + + +#include +#include +#include + +#if !(_ATL_VER < 0x0700) + #include + #include + #include +#endif + + +namespace brdm = boost::range_detail_microsoft; + + +// helpers +// + +template< class MfcMapT, class MapT > +bool test_mfc_map(MfcMapT& map, const MapT& sample) { - CString s = "hello world"; - BOOST_CHECK( boost::begin( s ) + boost::size( s ) == boost::end( s ) ); - BOOST_CHECK( boost::size( s ) == boost::size( "hello world" ) ); - BOOST_CHECK( !boost::empty( s ) ); - const CString cs( s ); - BOOST_CHECK( boost::begin( cs ) + boost::size( cs ) == boost::end( cs ) ); - BOOST_CHECK( boost::size( cs ) == boost::size( "hello world" ) ); - BOOST_CHECK( !boost::empty( cs ) ); - - CArray a; - BOOST_CHECK( boost::empty( a ) ); - a.Add( 5 ); - a.Add( 10 ); - BOOST_CHECK( boost::begin( a ) + boost::size( a ) == boost::end( a ) ); - BOOST_CHECK( boost::size( a ) == 2 ); - BOOST_CHECK( !boost::empty( a ) ); - const CArray& ca = a; - BOOST_CHECK( boost::begin( ca ) + boost::size( ca ) == boost::end( ca ) ); - BOOST_CHECK( boost::size( ca ) == 2 ); - BOOST_CHECK( !boost::empty( ca ) ); - + typedef typename boost::range_iterator::type iter_t; + typedef typename boost::range_const_iterator::type siter_t; + + bool result = true; + + result = result && (boost::distance(map) == boost::distance(sample)); + if (!result) + return false; + + { + for (iter_t it = boost::begin(map), last = boost::end(map); it != last; ++it) { + result = result && brdm::test_find_key_and_mapped(sample, *it); + } + } + + { + for (siter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) { + result = result && (map[it->first] == it->second); + } + } + + return result; } +template< class MfcMapT, class MapT > +bool test_mfc_cpair_map(MfcMapT& map, const MapT& sample) +{ + typedef typename boost::range_iterator::type iter_t; + typedef typename boost::range_const_iterator::type siter_t; + + bool result = true; + + result = result && (boost::distance(map) == boost::distance(sample)); + if (!result) + return false; + + { + for (iter_t it = boost::begin(map), last = boost::end(map); it != last; ++it) { + result = result && brdm::test_find_key_and_mapped(sample, std::make_pair(it->key, it->value)); + } + } + + { + for (siter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) { + result = result && (map[it->first] == it->second); + } + } + + return result; +} + + +// arrays +// +template< class Range > +void test_CByteArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CByteArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CDWordArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CDWordArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CObArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CObArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter >::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter >::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CPtrArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CPtrArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter >::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter >::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CStringArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CStringArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CUIntArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CUIntArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CWordArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CWordArray rng_t; + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +// lists +// + +template< class Range > +void test_CObList(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CObList rng_t; + + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator >::value )); +#if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); +#else + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); +#endif + + rng_t rng; + BOOST_CHECK( brdm::test_init_list(rng, sample) ); + BOOST_CHECK( brdm::test_bidirectional(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CPtrList(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CPtrList rng_t; + + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator >::value )); +#if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); +#else + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); +#endif + + rng_t rng; + BOOST_CHECK( brdm::test_init_list(rng, sample) ); + BOOST_CHECK( brdm::test_bidirectional(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CStringList(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CStringList rng_t; + + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator >::value )); +#if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); +#else + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); +#endif + + rng_t rng; + BOOST_CHECK( brdm::test_init_list(rng, sample) ); + BOOST_CHECK( brdm::test_bidirectional(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +// maps +// + +template< class MapT > +void test_CMapPtrToWord(const MapT& sample) +{ + typedef ::CMapPtrToWord rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); + BOOST_CHECK( ::test_mfc_map(rng, sample) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class MapT > +void test_CMapPtrToPtr(const MapT& sample) +{ + typedef ::CMapPtrToPtr rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); + BOOST_CHECK( ::test_mfc_map(rng, sample) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class MapT > +void test_CMapStringToOb(const MapT& sample) +{ + typedef ::CMapStringToOb rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); + BOOST_CHECK( ::test_mfc_map(rng, sample) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class MapT > +void test_CMapStringToPtr(const MapT& sample) +{ + typedef ::CMapStringToPtr rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); + BOOST_CHECK( ::test_mfc_map(rng, sample) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class MapT > +void test_CMapStringToString(const MapT& sample) +{ + typedef ::CMapStringToString rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); +#if !defined(BOOST_RANGE_MFC_NO_CPAIR) + BOOST_CHECK( ::test_mfc_cpair_map(rng, sample) ); +#endif + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class MapT > +void test_CMapWordToOb(const MapT& sample) +{ + typedef ::CMapWordToOb rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); + BOOST_CHECK( ::test_mfc_map(rng, sample) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class MapT > +void test_CMapWordToPtr(const MapT& sample) +{ + typedef ::CMapWordToPtr rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); + BOOST_CHECK( ::test_mfc_map(rng, sample) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +// templates +// + +template< class Range > +void test_CArray(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CArray rng_t; // An old MFC needs the second template argument. + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_array(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class Range > +void test_CList(const Range& sample) +{ + typedef typename boost::range_value::type val_t; + + typedef ::CList rng_t; + + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator >::value )); +#if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); +#else + BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator >::value )); +#endif + + rng_t rng; + BOOST_CHECK( brdm::test_init_list(rng, sample) ); + BOOST_CHECK( brdm::test_bidirectional(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +template< class MapT > +void test_CMap(const MapT& sample) +{ + typedef typename MapT::key_type k_t; + typedef typename MapT::mapped_type m_t; + + typedef ::CMap rng_t; + + rng_t rng; + boost::function_requires< boost::ForwardRangeConcept >(); + BOOST_CHECK( brdm::test_init_map(rng, sample) ); +#if !defined(BOOST_RANGE_MFC_NO_CPAIR) + BOOST_CHECK( ::test_mfc_cpair_map(rng, sample) ); +#endif + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +void test_CTypedPtrArray() +{ + typedef ::CTypedPtrArray< ::CPtrArray, int * > rng_t; + boost::function_requires< boost::RandomAccessRangeConcept >(); + + rng_t rng; + int o1, o2, o3, o4, o5; + int *data[] = { &o1, &o2, &o3, &o4, &o5 }; + BOOST_CHECK( brdm::test_init_array(rng, boost::make_iterator_range(data, data+5)) ); + + BOOST_CHECK( *(boost::begin(rng) + 2) == &o3 ); + BOOST_CHECK( *(boost::end(rng) - 1) == &o5 ); + + // BOOST_CHECK( brdm::test_random_access(rng) ); this range is not mutable + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +void test_CTypedPtrList() +{ + typedef ::CTypedPtrList< ::CObList, ::CObList * > rng_t; + boost::function_requires< boost::BidirectionalRangeConcept >(); + + rng_t rng; + + ::CObList o1, o2, o3, o4, o5; + ::CObList *data[] = { &o1, &o2, &o3, &o4, &o5 }; + BOOST_CHECK( brdm::test_init_list(rng, data) ); + + boost::range_iterator::type it = boost::begin(rng); + std::advance(it, 1); + BOOST_CHECK( *it == &o2 ); + std::advance(it, 2); + BOOST_CHECK( *it == &o4 ); + + // BOOST_CHECK( brdm::test_bidirectional(rng) ); this range is not mutable + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +void test_CTypedPtrMap() +{ + typedef ::CTypedPtrMap< ::CMapStringToPtr, ::CString, int *> rng_t; + boost::function_requires< boost::ForwardRangeConcept >(); + + rng_t rng; + ::CString o0(_T('a')), o1(_T('c')), o2(_T('f')), o3(_T('q')), o4(_T('g')); + int d0, d1, d2, d3, d4; + std::map< ::CString, int * > data; + data[o0] = &d0, data[o1] = &d1, data[o2] = &d2, data[o3] = &d3, data[o4] = &d4; + + BOOST_CHECK( brdm::test_init_map(rng, data) ); + BOOST_CHECK( ::test_mfc_map(rng, data) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); +} + + +// strings +// +#if defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) + + template< class Range > + void test_CString(const Range& sample) + { + typedef typename boost::range_value::type val_t; + + typedef ::CString rng_t; // An old MFC needs the second template argument. + BOOST_STATIC_ASSERT(( brdm::test_mutable_iter::value )); + BOOST_STATIC_ASSERT(( brdm::test_const_iter ::value )); + + rng_t rng; + BOOST_CHECK( brdm::test_init_string(rng, sample) ); + BOOST_CHECK( brdm::test_random_access(rng) ); + BOOST_CHECK( brdm::test_emptiness(rng) ); + } + +#endif + + +struct CPerson +{ + void hello_range() { }; +}; + + +void test_mfc() +{ +#if 0 + // overview + // + { + CTypedPtrArray *> myArray; + // ... + BOOST_FOREACH (CList *theList, myArray) + { + BOOST_FOREACH (CString& str, *theList) + { + boost::to_upper(str); + std::sort(boost::begin(str), boost::end(str)); + // ... + } + } + } +#endif + + // arrays + // + { + BYTE data[] = { 4,5,1,3,5,12,3,1,3,1,6,1,3,60,1,1,5,1,3,1,10 }; + + ::test_CByteArray(boost::make_iterator_range(data, data+22)); + } + + { + DWORD data[] = { 4,5,1,3,5,12,3,1,3,1,6,1,3,60,1,1,5,1,3,1,10 }; + + test_CDWordArray(boost::make_iterator_range(data, data+22)); + } + + { + ::CObArray o1, o2, o3, o4, o5; + ::CObject *data[] = { &o1, &o2, &o3, &o4, &o5 }; + + ::test_CObArray(boost::make_iterator_range(data, data+5)); + } + + { + ::CPtrArray o1, o2, o3, o4, o5; + void *data[] = { &o1, &o2, &o3, &o4, &o5 }; + + ::test_CPtrArray(boost::make_iterator_range(data, data+5)); + } + + { + ::CString data[] = { + ::CString(_T('0')), ::CString(_T('1')), ::CString(_T('2')), ::CString(_T('3')), + ::CString(_T('4')), ::CString(_T('5')), ::CString(_T('6')), ::CString(_T('7')) + }; + + ::test_CStringArray(boost::make_iterator_range(data, data+8)); + } + + { + ::CUIntArray rng; + UINT data[] = { 4,5,1,3,5,12,3,1,3,1,6,1,3,60,1,1,5,1,3,1,10 }; + + ::test_CUIntArray(boost::make_iterator_range(data, data+22)); + } + + { + ::CWordArray rng; + WORD data[] = { 4,5,1,3,5,12,3,1,3,1,6,1,3,60,1,1,5,1,3,1,10 }; + + ::test_CWordArray(boost::make_iterator_range(data, data+22)); + } + + + // lists + // + { + ::CObList rng; + ::CObList o1, o2, o3, o4, o5; + ::CObject *data[] = { &o1, &o2, &o3, &o4, &o5 }; + + ::test_CObList(boost::make_iterator_range(data, data+5)); + } + + { + ::CPtrList rng; + ::CPtrList o1, o2, o3, o4, o5; + void *data[] = { &o1, &o2, &o3, &o4, &o5 }; + + ::test_CPtrList(boost::make_iterator_range(data, data+5)); + } + + { + ::CString data[] = { + ::CString(_T('0')), ::CString(_T('1')), ::CString(_T('2')), ::CString(_T('3')), + ::CString(_T('4')), ::CString(_T('5')), ::CString(_T('6')), ::CString(_T('7')) + }; + + ::test_CStringList(boost::make_iterator_range(data, data+8)); + } + + + // maps + // + { + std::map data; + int o0, o1, o2, o3, o4; + data[&o0] = 15, data[&o1] = 14, data[&o2] = 3, data[&o3] = 6, data[&o4] = 1; + + ::test_CMapPtrToWord(data); + } + + { + std::map data; + int o0, o1, o2, o3, o4; + data[&o0] = &o3, data[&o1] = &o2, data[&o2] = &o1, data[&o3] = &o0, data[&o4] = &o4; + + ::test_CMapPtrToPtr(data); + } + + { + std::map< ::CString, CObject * > data; + CObArray o0, o1, o2, o3, o4; + data[ ::CString('0') ] = &o0, data[ ::CString('1') ] = &o1, data[ ::CString('2') ] = &o2, + data[ ::CString('3') ] = &o3, data[ ::CString('4') ] = &o4; + + ::test_CMapStringToOb(data); + } + + { + std::map< ::CString, void * > data; + CObArray o0, o1, o2, o3, o4; + data[ ::CString('0') ] = &o0, data[ ::CString('1') ] = &o1, data[ ::CString('2') ] = &o2, + data[ ::CString('3') ] = &o3, data[ ::CString('4') ] = &o4; + + ::test_CMapStringToPtr(data); + } + + { + std::map< ::CString, ::CString > data; + CString o0('a'), o1('b'), o2('c'), o3('d'), o4('e'); + data[ ::CString('0') ] = o0, data[ ::CString('1') ] = o1, data[ ::CString('2') ] = o2, + data[ ::CString('3') ] = o3, data[ ::CString('4') ] = o4; + + ::test_CMapStringToString(data); + } + + { + std::map< WORD, CObject * > data; + ::CDWordArray o0, o1, o2, o3, o4; + data[21] = &o3, data[52] = &o2, data[12] = &o1, data[76] = &o0, data[54] = &o4; + + ::test_CMapWordToOb(data); + } + + { + std::map< WORD, void * > data; + ::CDWordArray o0, o1, o2, o3, o4; + data[21] = &o3, data[52] = &o2, data[12] = &o1, data[76] = &o0, data[54] = &o4; + + ::test_CMapWordToPtr(data); + } + + // templates + // + { + std::string data("0987654321qwertyuiop"); + ::test_CArray(data); + ::test_CList(data); + } + + { + std::wstring data(L"asdfghjklzxcvbnm"); + ::test_CArray(data); + ::test_CList(data); + } + + { + std::map< int, std::string > data; + data[0] = "abcde", data[1] = "ajfie", data[2] = "lij", data[3] = "abc", data[4] = "ioiu"; + + ::test_CMap(data); + } + + + // typed + // + { + ::test_CTypedPtrArray(); + ::test_CTypedPtrList(); + ::test_CTypedPtrMap(); + } + + + // strings + // +#if defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) + { + std::string data("123456789 abcdefghijklmn"); + ::test_CString(data); + } +#endif + + +} // test_mfc + #include using boost::unit_test::test_suite; -test_suite* init_unit_test_suite( int argc, char* argv[] ) +test_suite * +init_unit_test_suite(int argc, char* argv[]) { - test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); - - test->add( BOOST_TEST_CASE( &check_mfc ) ); + test_suite *test = BOOST_TEST_SUITE("MFC Range Test Suite"); + test->add(BOOST_TEST_CASE(&test_mfc)); + (void)argc, (void)argv; // unused return test; } - - - - - - From 8984de1c744aa6c1312ac3395951cfef126fa2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Wed, 24 Oct 2007 15:18:22 +0000 Subject: [PATCH 15/57] roll back of ADL names [SVN r40422] --- test/extension_mechanism.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/extension_mechanism.cpp b/test/extension_mechanism.cpp index 828b5cd..2fd7929 100755 --- a/test/extension_mechanism.cpp +++ b/test/extension_mechanism.cpp @@ -57,24 +57,24 @@ namespace Foo // to be defined because X defines the proper set of // nested types. // - inline X::iterator boost_range_begin( X& x ) + inline X::iterator range_begin( X& x ) { return x.vec.begin(); } - inline X::const_iterator boost_range_begin( const X& x ) + inline X::const_iterator range_begin( const X& x ) { return x.vec.begin(); } - inline X::iterator boost_range_end( X& x ) + inline X::iterator range_end( X& x ) { return x.vec.end(); } - inline X::const_iterator boost_range_end( const X& x ) + inline X::const_iterator range_end( const X& x ) { return x.vec.end(); } From 82768af3d2f06a49a0774f20ce078313e2c94350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Wed, 24 Oct 2007 15:19:16 +0000 Subject: [PATCH 16/57] roll-back of ADL names [SVN r40423] --- include/boost/range/begin.hpp | 14 +++++++------- include/boost/range/detail/microsoft.hpp | 4 ++-- include/boost/range/end.hpp | 14 +++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/boost/range/begin.hpp b/include/boost/range/begin.hpp index 2f2cb3b..e8251c9 100755 --- a/include/boost/range/begin.hpp +++ b/include/boost/range/begin.hpp @@ -39,7 +39,7 @@ namespace range_detail template< typename C > inline BOOST_DEDUCED_TYPENAME range_iterator::type - boost_range_begin( C& c ) + range_begin( C& c ) { return c.begin(); } @@ -49,13 +49,13 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename Iterator > - inline Iterator boost_range_begin( const std::pair& p ) + inline Iterator range_begin( const std::pair& p ) { return p.first; } template< typename Iterator > - inline Iterator boost_range_begin( std::pair& p ) + inline Iterator range_begin( std::pair& p ) { return p.first; } @@ -68,13 +68,13 @@ namespace range_detail // May this be discarded? Or is it needed for bad compilers? // template< typename T, std::size_t sz > - inline const T* boost_range_begin( const T (&array)[sz] ) + inline const T* range_begin( const T (&array)[sz] ) { return array; } template< typename T, std::size_t sz > - inline T* boost_range_begin( T (&array)[sz] ) + inline T* range_begin( T (&array)[sz] ) { return array; } @@ -95,7 +95,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator::type begin( T& r ) /**/ using namespace range_detail; #endif - return boost_range_begin( r ); + return range_begin( r ); } template< class T > @@ -106,7 +106,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator::type begin( const T& r ) /**/ using namespace range_detail; #endif - return boost_range_begin( r ); + return range_begin( r ); } } // namespace boost diff --git a/include/boost/range/detail/microsoft.hpp b/include/boost/range/detail/microsoft.hpp index 6dfe1ca..2c4b1ed 100644 --- a/include/boost/range/detail/microsoft.hpp +++ b/include/boost/range/detail/microsoft.hpp @@ -30,8 +30,8 @@ #define BOOST_RANGE_DETAIL_MICROSOFT_range_end range_end #else #define BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator range_mutable_iterator - #define BOOST_RANGE_DETAIL_MICROSOFT_range_begin boost_range_begin - #define BOOST_RANGE_DETAIL_MICROSOFT_range_end boost_range_end + #define BOOST_RANGE_DETAIL_MICROSOFT_range_begin range_begin + #define BOOST_RANGE_DETAIL_MICROSOFT_range_end range_end #endif diff --git a/include/boost/range/end.hpp b/include/boost/range/end.hpp index 59bae67..be2f495 100755 --- a/include/boost/range/end.hpp +++ b/include/boost/range/end.hpp @@ -40,7 +40,7 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename C > inline BOOST_DEDUCED_TYPENAME range_iterator::type - boost_range_end( C& c ) + range_end( C& c ) { return c.end(); } @@ -50,13 +50,13 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename Iterator > - inline Iterator boost_range_end( const std::pair& p ) + inline Iterator range_end( const std::pair& p ) { return p.second; } template< typename Iterator > - inline Iterator boost_range_end( std::pair& p ) + inline Iterator range_end( std::pair& p ) { return p.second; } @@ -66,13 +66,13 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename T, std::size_t sz > - inline const T* boost_range_end( const T (&array)[sz] ) + inline const T* range_end( const T (&array)[sz] ) { return range_detail::array_end( array ); } template< typename T, std::size_t sz > - inline T* boost_range_end( T (&array)[sz] ) + inline T* range_end( T (&array)[sz] ) { return range_detail::array_end( array ); } @@ -91,7 +91,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator::type end( T& r ) /**/ using namespace range_detail; #endif - return boost_range_end( r ); + return range_end( r ); } template< class T > @@ -102,7 +102,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator::type end( const T& r ) /**/ using namespace range_detail; #endif - return boost_range_end( r ); + return range_end( r ); } } // namespace 'boost' From 336c12b60f1e457333addbd2c575abe6e80c6a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Wed, 24 Oct 2007 15:53:54 +0000 Subject: [PATCH 17/57] removed deprecated mfc stuff [SVN r40425] --- include/boost/range/detail/mfc/carray.hpp | 97 ---------------------- include/boost/range/detail/mfc/cstring.hpp | 92 -------------------- 2 files changed, 189 deletions(-) delete mode 100755 include/boost/range/detail/mfc/carray.hpp delete mode 100755 include/boost/range/detail/mfc/cstring.hpp diff --git a/include/boost/range/detail/mfc/carray.hpp b/include/boost/range/detail/mfc/carray.hpp deleted file mode 100755 index 71ab5cb..0000000 --- a/include/boost/range/detail/mfc/carray.hpp +++ /dev/null @@ -1,97 +0,0 @@ -// Boost.Range library -// -// Copyright Thorsten Ottosen 2003-2004. Use, modification and -// distribution is subject to 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) -// -// For more information, see http://www.boost.org/libs/range/ -// - -#if !defined( BOOST_RANGE_DETAIL_MFC_CARRAY_HPP ) && defined( BOOST_RANGE_ENABLE_MCF_CARRAY ) -#define BOOST_RANGE_DETAIL_MFC_CARRAY_HPP - -#if defined(_MSC_VER) && (_MSC_VER >= 1200) -# pragma once -#endif - -#include // for CArray -#include -#include - -namespace boost -{ - template< class T, class U > - struct range_iterator< CArray > - { - typedef T* type; - }; - - // - // Why is this needed?!? - // - template< class T, class U > - struct range_iterator< const CArray > - { - typedef T* type; - }; - - template< class T, class U > - struct range_const_iterator< CArray > - { - typedef const T* type; - }; - - template< class T, class U > - struct range_difference< CArray > - { - typedef std::ptrdiff_t type; - }; - - template< class T, class U > - struct range_size< CArray > - { - typedef int type; - }; - - template< class T, class U > - struct range_value< CArray > - { - typedef T type; - }; - - template< class T, class U > - T* boost_range_begin( CArray& r ) - { - return r.GetData(); - } - - template< class T, class U > - const T* boost_range_begin( const CArray& r ) - { - return r.GetData(); - } - - template< class T, class U > - int boost_range_size( const CArray& r ) - { - return r.GetSize(); - } - - template< class T, class U > - T* boost_range_end( CArray& r ) - { - return boost_range_begin( r ) + boost_range_size( r ); - } - - template< class T, class U > - const T* boost_range_end( const CArray& r ) - { - return boost_range_begin( r ) + boost_range_size( r ); - } - - // default 'empty()' ok - -} // namespace 'boost' - -#endif diff --git a/include/boost/range/detail/mfc/cstring.hpp b/include/boost/range/detail/mfc/cstring.hpp deleted file mode 100755 index ccb0745..0000000 --- a/include/boost/range/detail/mfc/cstring.hpp +++ /dev/null @@ -1,92 +0,0 @@ -// Boost.Range library -// -// Copyright Thorsten Ottosen 2003-2004. Use, modification and -// distribution is subject to 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) -// -// For more information, see http://www.boost.org/libs/range/ -// - -#if !defined(BOOST_RANGE_DETAIL_MFC_CSTRING_HPP) && defined(BOOST_RANGE_ENABLE_MFC) -#define BOOST_RANGE_DETAIL_MFC_CSTRING_HPP - -#if defined(_MSC_VER) && (_MSC_VER >= 1200) -# pragma once -#endif - -#include // for CString -#include -#include - -namespace boost -{ - template<> - struct range_iterator< CString > - { - typedef TCHAR* type; - }; - - // - // Why is this needed?!? - // - template<> - struct range_iterator< const CString > - { - typedef TCHAR* type; - }; - - template<> - struct range_const_iterator< CString > - { - typedef const TCHAR* type; - }; - - template<> - struct range_difference< CString > - { - typedef std::ptrdiff_t type; - }; - - template<> - struct range_size< CString > - { - typedef int type; - }; - - template<> - struct range_value< CString > - { - typedef TCHAR type; - }; - - TCHAR* boost_range_begin( CString& r ) - { - return r.GetBuffer(0); - } - - const TCHAR* boost_range_begin( const CString& r ) - { - return (LPCTSTR)r; - } - - int boost_range_size( const CString& r ) - { - return r.GetLength(); - } - - TCHAR* boost_range_end( CString& r ) - { - return boost_range_begin( r ) + boost_range_size( r ); - } - - const TCHAR* range_adl_end( const CString& r ) - { - return boost_range_begin( r ) + boost_range_size( r ); - } - - // default 'empty()' ok - -} // namespace 'boost' - -#endif From 01826978d63f2d8a87b6ba5b40170205ec101820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 27 Oct 2007 15:57:20 +0000 Subject: [PATCH 18/57] cleaned up deprecated headers [SVN r40506] --- .../boost/range/const_reverse_iterator.hpp | 32 ------------------ include/boost/range/metafunctions.hpp | 3 -- include/boost/range/result_iterator.hpp | 33 ------------------- .../boost/range/reverse_result_iterator.hpp | 32 ------------------ 4 files changed, 100 deletions(-) delete mode 100755 include/boost/range/const_reverse_iterator.hpp delete mode 100755 include/boost/range/result_iterator.hpp delete mode 100755 include/boost/range/reverse_result_iterator.hpp diff --git a/include/boost/range/const_reverse_iterator.hpp b/include/boost/range/const_reverse_iterator.hpp deleted file mode 100755 index 215bcc7..0000000 --- a/include/boost/range/const_reverse_iterator.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Boost.Range library -// -// Copyright Thorsten Ottosen 2003-2004. Use, modification and -// distribution is subject to 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) -// -// For more information, see http://www.boost.org/libs/range/ -// - -#ifndef BOOST_RANGE_CONST_REVERSE_ITERATOR_HPP -#define BOOST_RANGE_CONST_REVERSE_ITERATOR_HPP - -#if defined(_MSC_VER) && (_MSC_VER >= 1200) -# pragma once -#endif - -#include - -namespace boost -{ - // - // This interface is deprecated, use range_reverse_iterator - // - - template< typename C > - struct range_const_reverse_iterator : range_reverse_iterator - { }; - -} // namespace boost - -#endif diff --git a/include/boost/range/metafunctions.hpp b/include/boost/range/metafunctions.hpp index 5b25a8f..1ce7f85 100755 --- a/include/boost/range/metafunctions.hpp +++ b/include/boost/range/metafunctions.hpp @@ -16,10 +16,7 @@ #endif #include -#include #include -#include -#include #include #include #include diff --git a/include/boost/range/result_iterator.hpp b/include/boost/range/result_iterator.hpp deleted file mode 100755 index ba09c5f..0000000 --- a/include/boost/range/result_iterator.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Boost.Range library -// -// Copyright Thorsten Ottosen 2003-2004. Use, modification and -// distribution is subject to 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) -// -// For more information, see http://www.boost.org/libs/range/ -// - -#ifndef BOOST_RANGE_RESULT_ITERATOR_HPP -#define BOOST_RANGE_RESULT_ITERATOR_HPP - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include - -namespace boost -{ - // - // This interface is deprecated, use range_iterator - // - - template< typename C > - struct range_result_iterator : range_iterator - { }; - -} // namespace boost - - -#endif diff --git a/include/boost/range/reverse_result_iterator.hpp b/include/boost/range/reverse_result_iterator.hpp deleted file mode 100755 index 62bf135..0000000 --- a/include/boost/range/reverse_result_iterator.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Boost.Range library -// -// Copyright Thorsten Ottosen 2003-2004. Use, modification and -// distribution is subject to 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) -// -// For more information, see http://www.boost.org/libs/range/ -// - -#ifndef BOOST_RANGE_REVERSE_RESULT_ITERATOR_HPP -#define BOOST_RANGE_REVERSE_RESULT_ITERATOR_HPP - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include - -namespace boost -{ - // - // This interface is deprecated, use range_reverse_iterator - // - - template< typename C > - struct range_reverse_result_iterator : range_reverse_iterator - { }; - -} // namespace boost - -#endif From f6e555dda333202f4e83c0e4f0ee0a9991933374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 27 Oct 2007 15:57:56 +0000 Subject: [PATCH 19/57] updated example to new syntax [SVN r40507] --- test/algorithm_example.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/algorithm_example.cpp b/test/algorithm_example.cpp index 3bfb71f..d14a597 100755 --- a/test/algorithm_example.cpp +++ b/test/algorithm_example.cpp @@ -37,7 +37,7 @@ namespace } template< typename Range, typename T > - inline typename boost::range_const_iterator::type + inline typename boost::range_iterator::type find( const Range& c, const T& value ) { return std::find( boost::begin( c ), boost::end( c ), value ); @@ -47,7 +47,7 @@ namespace // replace first value and return its index // template< class Range, class T > - inline typename boost::range_size::type + inline typename boost::range_difference::type my_generic_replace( Range& c, const T& value, const T& replacement ) { typename boost::range_iterator::type found = find( c, value ); From 4767db522b0ea7a1a3033568ed35b36c88a7aa46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 27 Oct 2007 15:58:22 +0000 Subject: [PATCH 20/57] first update ... more to come [SVN r40508] --- doc/Jamfile.v2 | 12 +- doc/boost_range.html | 1208 ++++++++++++++++++++-------------------- doc/headers.html | 54 +- doc/intro.html | 20 +- doc/utility_class.html | 6 +- 5 files changed, 656 insertions(+), 644 deletions(-) diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 4f7b44b..0fafdd7 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -2,7 +2,7 @@ use-project boost : $(BOOST_ROOT) ; -#import boostbook : boostbook ; +import boostbook : boostbook ; import quickbook ; xml boost_range : boost_range.qbk ; @@ -11,8 +11,12 @@ boostbook standalone : boost_range : - generate.section.toc.level=4 - chunk.first.sections=7 - toc.section.depth=10 + toc.max.depth=2 + toc.section.depth=4 + chunk.section.depth=2 + +# generate.section.toc.level=4 +# chunk.first.sections=7 +# toc.section.depth=10 ; diff --git a/doc/boost_range.html b/doc/boost_range.html index 303f9d6..e652436 100644 --- a/doc/boost_range.html +++ b/doc/boost_range.html @@ -1,86 +1,83 @@ - - Boost.Range Reference - - - - - - - - - -


- Boost.Range -

-
-

Synopsis and Reference -

- -
- -

Overview

-

- Four types of objects are currently supported by the library: -

    -
  • - standard-like containers -
  • - std::pair<iterator,iterator> -
  • - null terminated strings (this includes char[],wchar_t[], - char*, and wchar_t*) -

    - Warning: support for null-terminated strings is deprecated and will - disappear in the next Boost release (1.34). -

    -
  • - built-in arrays -
  • -
- 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 - iterator_range implements the minimal - interface required to make the class a Forward - Range - . -

-

- Please also see Range concepts for more details. -

- -

Synopsis

-

-

+    
+        Boost.Range Reference 
+        
+        
+    
+    
+        
+            
+                
+                
+            
+        


+ Boost.Range +

+
+

Synopsis and Reference +

+ +
+ +

Overview

+

+ Three types of objects are currently supported by the library: +

    +
  • + standard-like containers +
  • + std::pair<iterator,iterator> +
  • + built-in arrays +
  • +
+ 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 + iterator_range implements the minimal + interface required to make the class a Forward + Range + . +

+

+ Please also see Range concepts for more details. +

+ +

Synopsis

+

+

 namespace boost
 {
     //
     // Single Pass Range metafunctions
     //
-    
-    template< class T >
-    struct range_value;
-                 
+                   
     template< class T >
     struct range_iterator;
     
     template< class T >
-    struct range_const_iterator;
+    struct range_value;
+  
+    template< class T >
+    struct range_pointer;
     
+    template< class T >
+    struct range_category;
+
     //
     // Forward Range metafunctions
     //
@@ -89,10 +86,6 @@ class=identifier>range_const_iterator;
     struct range_difference;
     
-    template< class T >
-    struct range_size;
-    
     //
     // Bidirectional Range metafunctions
     //
@@ -102,24 +95,14 @@ class=identifier>range_size;
 href="#range_reverse_iterator">range_reverse_iterator;
 
-    template< class T >
-    struct range_const_reverse_iterator;
-    
     //
-    // Special metafunctions
+    // Random Access Range metafunctions
     //
     
     template< class T >
-    struct range_result_iterator;
-                 
-    template< class T >
-    struct range_reverse_result_iterator;
-
+    struct range_size;
+    
     //
     // Single Pass Range functions
     //
@@ -129,7 +112,7 @@ class=identifier>range_reverse_result_iterator;
     begin( T& c );
     
     template< class T >
-    typename range_const_iterator<T>::type
+    typename range_iterator<T>::type
     begin( const T& c );
         
     template< class T >
@@ -137,7 +120,7 @@ class=identifier>range_reverse_result_iterator;
     end( T& c );
                       
     template< class T >
-    typename range_const_iterator<T>::type
+    typename range_iterator<T>::type
     end( const T& c );
     
     template< class T >
@@ -149,8 +132,8 @@ class=identifier>range_reverse_result_iterator;
     //
     
     template< class T >
-    typename range_size<T>::type
-    size( const T& c );
+    typename range_difference<T>::type
+    distance( const T& c );
                             
     //
     // Bidirectional Range functions
@@ -161,7 +144,7 @@ class=identifier>range_reverse_result_iterator;
     rbegin( T& c );
     
     template< class T >
-    typename range_const_reverse_iterator<T>::type
+    typename range_reverse_iterator<T>::type
     rbegin( const T& c );
         
     template< class T >
@@ -169,535 +152,544 @@ class=identifier>range_reverse_result_iterator;
     rend( T& c );
                       
     template< class T >
-    typename range_const_reverse_iterator<T>::type
+    typename range_reverse_iterator<T>::type
     rend( const T& c );
     
+	               
+    //
+    // Random Access Range functions
+    //
+    
+    template< class T >
+    typename range_size<T>::type
+    size( const T& c );
+	
     //
     // Special const Range functions
     // 
     
     template< class T >
-    typename range_const_iterator<T>::type 
+    typename range_iterator<const T>::type 
     const_begin( const T& r );
     
     template< class T >
-    typename range_const_iterator<T>::type 
+    typename range_iterator<const T>::type 
     const_end( const T& r );
     
     template< class T >
-    typename range_const_reverse_iterator<T>::type 
+    typename range_reverse_iterator<const T>::type 
     const_rbegin( const T& r );
     
     template< class T >
-    typename range_const_reverse_iterator<T>::type 
+    typename range_reverse_iterator<const T>::type 
     const_rend( 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. -

-

Metafunctions

-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Expression - Return type - Complexity
range_value<X>::typeT::value_type
- boost::iterator_value<P::first_type>::type
- A
- Char -
compile time
range_iterator<X>::typeT::iterator
- P::first_type
- A*
- Char* -
compile time
range_const_iterator<X>::typeT::const_iterator
- P::first_type
- const A*
- const Char* -
compile time
range_difference<X>::typeT::difference_type
- boost::iterator_difference<P::first_type>::type
- std::ptrdiff_t
- std::ptrdiff_t
-
compile time
range_size<X>::typeT::size_type
- std::size_t
- std::size_t
- std::size_t
-
compile time
range_result_iterator<X>::typerange_const_iterator<X>::type if X is const -
- range_iterator<X>::type otherwise -
compile time
range_reverse_iterator<X>::typeboost::reverse_iterator< typename range_iterator<T>::type >
-
compile time
range_const_reverse_iterator<X>::typeboost::reverse_iterator< typename range_const_iterator<T>::type > -
-
compile time
range_reverse_result_iterator<X>::typeboost::reverse_iterator< typename range_result_iterator<T>::type - > - compile time
-

-

- The special metafunctions range_result_iterator and range_reverse_result_iterator - are not part of any Range concept, but they are very useful when implementing - certain Range classes like sub_range - because of their ability to select iterators based on constness. -

-

Functions

-

- - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- Expression - Return type - Returns - Complexity
begin(x)range_result_iterator<X>::type - p.first if p is of type std::pair<T>
- a if a is an array
- s if s is a string literal
- boost_range_begin(x) if that expression would invoke a function found by ADL
- t.begin() otherwise +

+ +

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. +

+

Metafunctions

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Expression + Return type + Complexity
range_value<X>::typeT::value_type
+ boost::iterator_value<P::first_type>::type
+ A
+ Char +
compile time
range_iterator<X>::typeT::iterator
+ P::first_type
+ A*
+ Char* +
compile time
range_const_iterator<X>::typeT::const_iterator
+ P::first_type
+ const A*
+ const Char* +
compile time
range_difference<X>::typeT::difference_type
+ boost::iterator_difference<P::first_type>::type
+ std::ptrdiff_t
+ std::ptrdiff_t
+
compile time
range_size<X>::typeT::size_type
+ std::size_t
+ std::size_t
+ std::size_t
+
compile time
range_result_iterator<X>::typerange_const_iterator<X>::type if X is const +
+ range_iterator<X>::type otherwise +
compile time
range_reverse_iterator<X>::typeboost::reverse_iterator< typename range_iterator<T>::type >
+
compile time
range_const_reverse_iterator<X>::typeboost::reverse_iterator< typename range_const_iterator<T>::type > +
+
compile time
range_reverse_result_iterator<X>::typeboost::reverse_iterator< typename range_result_iterator<T>::type + > + compile time
+

+

+ The special metafunctions range_result_iterator and range_reverse_result_iterator + are not part of any Range concept, but they are very useful when implementing + certain Range classes like sub_range + because of their ability to select iterators based on constness. +

+

Functions

+

+ + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ Expression + Return type + Returns + Complexity
begin(x)range_result_iterator<X>::type + p.first if p is of type std::pair<T>
+ a if a is an array
+ s if s is a string literal
+ boost_range_begin(x) if that expression would invoke a function found by ADL
+ t.begin() otherwise -
constant time
end(x)range_result_iterator<X>::type - p.second if p is of type std::pair<T>
- a + sz if a is an array of size sz
- s + std::char_traits<X>::length( s ) if s is a Char* -
- s + sz - 1 if s is a string literal of size sz -
- boost_range_end(x) if that expression would invoke a function found by ADL
- t.end() otherwise - -
linear if X is Char* -
- constant time otherwise
empty(x)boolbegin(x) == end( x )
-
linear if X is Char* -
- constant time otherwise
-
size(x)range_size<X>::type - std::distance(p.first,p.second) if p is of type std::pair<T>
- sz if a is an array of size sz
- end(s) - s if s is a string literal or a Char*
- boost_range_size(x) if that expression would invoke a function found by ADL
- t.size() otherwise -
linear if X is Char* -
- or if std::distance() is linear -
- constant time otherwise
rbegin(x)range_reverse_result_iterator<X>::typerange_reverse_result_iterator<X>::type( end(x) ) -
-
same as end(x) -
rend(x)range_reverse_result_iterator<X>::typerange_reverse_result_iterator<X>::type( begin(x) ) - same as begin(x)
const_begin(x)range_const_iterator<X>::typerange_const_iterator<X>::type( begin(x) ) -
-
same as begin(x) -
const_end(x)range_const_iterator<X>::typerange_const_iterator<X>::type( end(x) ) - same as end(x)
const_rbegin(x)range_const_reverse_iterator<X>::typerange_const_reverse_iterator<X>::type( rbegin(x) ) -
-
same as rbegin(x) -
const_rend(x)range_const_reverse_iterator<X>::typerange_const_reverse_iterator<X>::type( rend(x) ) - same as rend(x)
-

-

- The special const functions are not part of any Range concept, but - are very useful when you want to document clearly that your code is read-only. -

-
- -

Extending the library

- +
constant time
end(x)range_result_iterator<X>::type + p.second if p is of type std::pair<T>
+ a + sz if a is an array of size sz
+ s + std::char_traits<X>::length( s ) if s is a Char* +
+ s + sz - 1 if s is a string literal of size sz +
+ boost_range_end(x) if that expression would invoke a function found by ADL
+ t.end() otherwise + +
linear if X is Char* +
+ constant time otherwise
empty(x)boolbegin(x) == end( x )
+
linear if X is Char* +
+ constant time otherwise
+
size(x)range_size<X>::type + std::distance(p.first,p.second) if p is of type std::pair<T>
+ sz if a is an array of size sz
+ end(s) - s if s is a string literal or a Char*
+ boost_range_size(x) if that expression would invoke a function found by ADL
+ t.size() otherwise +
linear if X is Char* +
+ or if std::distance() is linear +
+ constant time otherwise
rbegin(x)range_reverse_result_iterator<X>::typerange_reverse_result_iterator<X>::type( end(x) ) +
+
same as end(x) +
rend(x)range_reverse_result_iterator<X>::typerange_reverse_result_iterator<X>::type( begin(x) ) + same as begin(x)
const_begin(x)range_const_iterator<X>::typerange_const_iterator<X>::type( begin(x) ) +
+
same as begin(x) +
const_end(x)range_const_iterator<X>::typerange_const_iterator<X>::type( end(x) ) + same as end(x)
const_rbegin(x)range_const_reverse_iterator<X>::typerange_const_reverse_iterator<X>::type( rbegin(x) ) +
+
same as rbegin(x) +
const_rend(x)range_const_reverse_iterator<X>::typerange_const_reverse_iterator<X>::type( rend(x) ) + same as rend(x)
+

+

+ The special const functions are not part of any Range concept, but + are very useful when you want to document clearly that your code is read-only. +

+
+ +

Extending the library

+ - + - -

Method 1: provide member functions and nested types

- -

- 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
size()Forward 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
iteratorSingle Pass Range
const_iteratorSingle Pass Range
size_typeForward Range
-

-

- Again one should notice that member types reverse_iterator and const_reverse_iterator - are not needed. -

- -

Method 2: provide free-standing functions and specialize metafunctions

+ +

Method 1: provide member functions and nested types

+ +

+ 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
size()Forward 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
iteratorSingle Pass Range
const_iteratorSingle Pass Range
size_typeForward Range
+

+

+ Again one should notice that member types reverse_iterator and const_reverse_iterator + are not needed. +

+ +

Method 2: provide free-standing functions and specialize metafunctions

-

- 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
boost_range_begin(x)Single Pass Range
boost_range_end(x) - Single Pass Range
boost_range_size(x)Forward Range
-

-

boost_range_begin() and boost_range_end() must be - overloaded for both const and mutable reference arguments. -

- -

- You must also specialize 3 metafunctions for your type X: -

-

- - - - - - - - - - - - - - - - -
- Metafunction - Related concept
boost::range_iteratorSingle Pass Range
boost::range_const_iteratorSingle Pass Range
boost::range_sizeForward Range
-

-

- A complete example is given here: -

-
-
+        

+ 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
boost_range_begin(x)Single Pass Range
boost_range_end(x) + Single Pass Range
boost_range_size(x)Forward Range
+

+

boost_range_begin() and boost_range_end() must be + overloaded for both const and mutable reference arguments. +

+ +

+ You must also specialize 3 metafunctions for your type X: +

+

+ + + + + + + + + + + + + + + + +
+ Metafunction + Related concept
boost::range_iteratorSingle Pass Range
boost::range_const_iteratorSingle Pass Range
boost::range_sizeForward 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;	
-	};
+    //
+    // 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.
-	//
+    //
+    // Specialize metafunctions. We must include the range.hpp header.
+    // We must open the 'boost' namespace.
+    //
 
-	template< class T >
-	struct range_iterator< Foo::Pair<T> >
-	{
-		typedef T type;
-	};
+    template< class T >
+    struct range_iterator< Foo::Pair<T> >
+    {
+        typedef T type;
+    };
 
-	template< class T >
-	struct range_const_iterator< Foo::Pair<T> >
-	{
-		//
-		// Remark: this is defined similar to 'range_iterator'
-		//         because the 'Pair' type does not distinguish
-		//         between an iterator and a const_iterator.
-		//
-		typedef T type;
-	};
+    template< class T >
+    struct range_const_iterator< Foo::Pair<T> >
+    {
+        //
+        // Remark: this is defined similar to 'range_iterator'
+        //         because the 'Pair' type does not distinguish
+        //         between an iterator and a const_iterator.
+        //
+        typedef T type;
+    };
 
-	template< class T >
-	struct range_size< Foo::Pair<T> >
-	{
+    template< class T >
+    struct range_size< Foo::Pair<T> >
+    {
 
-		typedef std::size_t type;
-	};
+        typedef std::size_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 boost_range_begin( Pair<T>& x )
-	{ 
-		return x.first;
-	}
+    //
+    // The required functions. These should be defined in
+    // the same namespace as 'Pair', in this case 
+    // in namespace 'Foo'.
+    //
+    
+    template< class T >
+    inline T boost_range_begin( Pair<T>& x )
+    { 
+        return x.first;
+    }
 
-	template< class T >
-	inline T boost_range_begin( const Pair<T>& x )
-	{ 
-		return x.first;
-	}
+    template< class T >
+    inline T boost_range_begin( const Pair<T>& x )
+    { 
+        return x.first;
+    }
 
-	template< class T >
-	inline T boost_range_end( Pair<T>& x )
-	{ 
-		return x.last;
-	}
+    template< class T >
+    inline T boost_range_end( Pair<T>& x )
+    { 
+        return x.last;
+    }
 
-	template< class T >
-	inline T boost_range_end( const Pair<T>& x )
-	{ 
-		return x.last;
-	}
+    template< class T >
+    inline T boost_range_end( const Pair<T>& x )
+    { 
+        return x.last;
+    }
 
-	template< class T >
-	inline typename boost::range_size< Pair<T> >::type
-	boost_range_size( const Pair<T>& x )
-	{
-		return std::distance(x.first,x.last);
-	}
+    template< class T >
+    inline typename boost::range_size< Pair<T> >::type
+    boost_range_size( const Pair<T>& x )
+    {
+        return std::distance(x.first,x.last);
+    }
 
 } // namespace 'Foo'
 
@@ -705,41 +697,41 @@ class=identifier>T& 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_size< Foo::Pair<iter> >::type s = boost::size( pair );
-	s      = boost::size( cpair );
-	boost::range_const_reverse_iterator< Foo::Pair<iter> >::type
-	ri     = boost::rbegin( cpair ),
-	re     = boost::rend( cpair );
-}	
+    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_size< Foo::Pair<iter> >::type s = boost::size( pair );
+    s      = boost::size( cpair );
+    boost::range_const_reverse_iterator< Foo::Pair<iter> >::type
+    ri     = boost::rbegin( cpair ),
+    re     = boost::rend( cpair );
+}    
 
- -
-

- (C) Copyright Thorsten Ottosen 2003-2004 -

-
-
-
-
-
-
-
-
-
-
-
-
- + +
+

+ (C) Copyright Thorsten Ottosen 2003-2004 +

+
+
+
+
+
+
+
+
+
+
+
+
+ diff --git a/doc/headers.html b/doc/headers.html index f8b12a3..1539ae8 100755 --- a/doc/headers.html +++ b/doc/headers.html @@ -49,6 +49,12 @@ range_iterator Single Pass Range + + + <boost/range/mutable_iterator.hpp> + range_mutable_iterator + Single Pass Range <boost/range/const_iterator.hpp> @@ -67,27 +73,24 @@ range_size Forward Range - - <boost/range/result_iterator.hpp> - range_result_iterator + + <boost/range/pointer.hpp> + range_pointer - + + <boost/range/category.hpp> + range_category + - + + <boost/range/reverse_iterator.hpp> range_reverse_iterator Bidirectional Range - - <boost/range/const_reverse_iterator.hpp> - range_const_reverse_iterator - Bidirectional Range - - - <boost/range/reverse_result_iterator.hpp> - range_reverse_result_iterator - - - <boost/range/begin.hpp> @@ -108,11 +111,17 @@ <boost/range/empty.hpp> empty Single Pass Range + + + <boost/range/distance.hpp> + distance + Forward Range <boost/range/size.hpp> size - Forward Range + Random Access Range + <boost/range/rbegin.hpp> @@ -130,6 +139,21 @@ Bidirectional Range + + <boost/range/as_array.hpp> + + as_array + + - + + + <boost/range/as_literal.hpp> + + as_literal + + - + + <boost/range/iterator_range.hpp>
  • - correct handling of null-terminated strings -

    - Warning: support for null-terminated strings is deprecated and will - disappear in the next Boost release (1.34). -

    + safe use of built-in arrays
  • -
  • - safe use of built-in arrays (for legacy code; why else would you use - built-in arrays?)
  • - Below are given a small example (the complete example can be found here - ): -

    + Below are given a small example (the complete example can be found here):
     
         //
    @@ -89,7 +81,7 @@ free-standing functions so syntactic and/or semantic differences can be removed.
         }
     
         template< class ForwardReadableRange, class T >
    -    inline typename boost::range_const_iterator< inline typename boost::range_iterator< const ForwardReadableRange >::type
         find( const ForwardReadableRange& c, const T& value )
         {
    @@ -100,7 +92,7 @@ class=identifier>ForwardReadableRange >::template< class ForwardReadableWriteableRange, class T >
    -    inline typename boost::range_size< ForwardReadableWriteableRange >::type
    +    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 );
    @@ -146,7 +138,7 @@ Notice that we have to
     
         

    - (C) Copyright Thorsten Ottosen 2003-2004 + (C) Copyright Thorsten Ottosen 2003-2007


    diff --git a/doc/utility_class.html b/doc/utility_class.html index 33c95ae..57bf5dc 100644 --- a/doc/utility_class.html +++ b/doc/utility_class.html @@ -173,11 +173,11 @@ class=keyword>const;
    ForwardTraversalIterator End ); template< class ForwardRange > - iterator_range< typename iterator_of<ForwardRange>::type > + iterator_range< typename iterator<ForwardRange>::type > make_iterator_range( ForwardRange& r ); template< class ForwardRange > - iterator_range< typename const_iterator_of<ForwardRange>::type > + iterator_range< typename const_iterator<ForwardRange>::type > make_iterator_range( const ForwardRange& r ); template< class Range > @@ -305,7 +305,7 @@ class can propagate constness since it knows what a corresponding sub_range( ForwardRange2& r ); template< class ForwardRange2 > - sub_range( const Range2& r ); + sub_range( const ForwardRange2& r ); template< class ForwardRange2 > sub_range& operator=( ForwardRange2& r ); From 3f98d69c9452606ab28d3f362f04b799d01bff3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 27 Oct 2007 22:00:47 +0000 Subject: [PATCH 21/57] added mfc/atl link [SVN r40514] --- index.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 05a90d3..29af65a 100755 --- a/index.html +++ b/index.html @@ -51,7 +51,9 @@
  • Terminology and style guidelines
  • Headers
  • -
  • Examples +
  • Examples +
  • MFC/ATL mapping (courtesy of Shunsuke + Sogame)
  • Portability
  • FAQ
  • History and acknowledgment From 00e70244a5663b316e3d66e755cf5f30c7b046ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sun, 28 Oct 2007 10:11:10 +0000 Subject: [PATCH 22/57] fixes broken one from trunk ... still not finished [SVN r40520] --- include/boost/range/concepts.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/boost/range/concepts.hpp b/include/boost/range/concepts.hpp index 2441d43..0732e26 100755 --- a/include/boost/range/concepts.hpp +++ b/include/boost/range/concepts.hpp @@ -60,7 +60,8 @@ namespace boost { struct SinglePassRangeConcept { typedef typename range_value::type range_value; typedef typename range_iterator::type range_iterator; - typedef typename range_const_iterator::type range_const_iterator; + //typedef typename range_iterator::type range_const_iterator; + void constraints() { function_requires< @@ -80,7 +81,6 @@ namespace boost { } T a; range_iterator i; - range_const_iterator ci; bool b; }; @@ -88,7 +88,6 @@ namespace boost { template struct ForwardRangeConcept { typedef typename range_difference::type range_difference; - typedef typename range_size::type range_size; void constraints() { function_requires< @@ -99,17 +98,13 @@ namespace boost { typename range_iterator::type > >(); - s = boost::size(a); } - T a; - range_size s; }; //! Check if a type T models the BidirectionalRange range concept. template struct BidirectionalRangeConcept { typedef typename range_reverse_iterator::type range_reverse_iterator; - typedef typename range_const_reverse_iterator::type range_const_reverse_iterator; void constraints() { function_requires< @@ -131,12 +126,13 @@ namespace boost { } T a; range_reverse_iterator i; - range_const_reverse_iterator ci; }; //! Check if a type T models the RandomAccessRange range concept. template struct RandomAccessRangeConcept { + typedef typename range_size::type range_size; + void constraints() { function_requires< @@ -147,7 +143,12 @@ namespace boost { typename range_iterator::type > >(); - } + + s = boost::size(a); + } + + T a; + range_size s; }; } // namespace boost From 2e298b5e60f783cbe60cd526f68e96a61a994af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sun, 28 Oct 2007 10:11:54 +0000 Subject: [PATCH 23/57] adds test for inclusion of concept header [SVN r40521] --- test/iterator_pair.cpp | 1 + test/mfc.cpp | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/iterator_pair.cpp b/test/iterator_pair.cpp index 094a7c2..d50a1f7 100755 --- a/test/iterator_pair.cpp +++ b/test/iterator_pair.cpp @@ -15,6 +15,7 @@ # pragma warn -8057 // unused argument argc/argv in Boost.Test #endif +#include #include #include #include diff --git a/test/mfc.cpp b/test/mfc.cpp index 29f2234..7a13e8e 100755 --- a/test/mfc.cpp +++ b/test/mfc.cpp @@ -1,5 +1,3 @@ - - // Boost.Range MFC Extension // // Copyright Shunsuke Sogame 2005-2006. From 06c54ccd481fea5ba519ce719b14ab1cddcbb04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 30 Oct 2007 19:47:40 +0000 Subject: [PATCH 24/57] current version gave problem in regression ... to be updated later [SVN r40612] --- include/boost/range/concepts.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/range/concepts.hpp b/include/boost/range/concepts.hpp index 0732e26..5faf2de 100755 --- a/include/boost/range/concepts.hpp +++ b/include/boost/range/concepts.hpp @@ -76,8 +76,8 @@ namespace boost { } void const_constraints(const T& a) { - ci = boost::begin(a); - ci = boost::end(a); + //ci = boost::begin(a); + //ci = boost::end(a); } T a; range_iterator i; @@ -121,8 +121,8 @@ namespace boost { } void const_constraints(const T& a) { - ci = boost::rbegin(a); - ci = boost::rend(a); + //ci = boost::rbegin(a); + //ci = boost::rend(a); } T a; range_reverse_iterator i; From 68a63cab853db8bf85a05b24c90485af55b843ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Wed, 31 Oct 2007 21:48:11 +0000 Subject: [PATCH 25/57] added deprecated headers again for backward compatibility sake [SVN r40629] --- .../boost/range/const_reverse_iterator.hpp | 32 ++++++++++++++++++ include/boost/range/metafunctions.hpp | 3 ++ include/boost/range/result_iterator.hpp | 33 +++++++++++++++++++ .../boost/range/reverse_result_iterator.hpp | 32 ++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100755 include/boost/range/const_reverse_iterator.hpp create mode 100755 include/boost/range/result_iterator.hpp create mode 100755 include/boost/range/reverse_result_iterator.hpp diff --git a/include/boost/range/const_reverse_iterator.hpp b/include/boost/range/const_reverse_iterator.hpp new file mode 100755 index 0000000..215bcc7 --- /dev/null +++ b/include/boost/range/const_reverse_iterator.hpp @@ -0,0 +1,32 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + +#ifndef BOOST_RANGE_CONST_REVERSE_ITERATOR_HPP +#define BOOST_RANGE_CONST_REVERSE_ITERATOR_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#include + +namespace boost +{ + // + // This interface is deprecated, use range_reverse_iterator + // + + template< typename C > + struct range_const_reverse_iterator : range_reverse_iterator + { }; + +} // namespace boost + +#endif diff --git a/include/boost/range/metafunctions.hpp b/include/boost/range/metafunctions.hpp index 1ce7f85..5b25a8f 100755 --- a/include/boost/range/metafunctions.hpp +++ b/include/boost/range/metafunctions.hpp @@ -16,7 +16,10 @@ #endif #include +#include #include +#include +#include #include #include #include diff --git a/include/boost/range/result_iterator.hpp b/include/boost/range/result_iterator.hpp new file mode 100755 index 0000000..ba09c5f --- /dev/null +++ b/include/boost/range/result_iterator.hpp @@ -0,0 +1,33 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + +#ifndef BOOST_RANGE_RESULT_ITERATOR_HPP +#define BOOST_RANGE_RESULT_ITERATOR_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +#include + +namespace boost +{ + // + // This interface is deprecated, use range_iterator + // + + template< typename C > + struct range_result_iterator : range_iterator + { }; + +} // namespace boost + + +#endif diff --git a/include/boost/range/reverse_result_iterator.hpp b/include/boost/range/reverse_result_iterator.hpp new file mode 100755 index 0000000..62bf135 --- /dev/null +++ b/include/boost/range/reverse_result_iterator.hpp @@ -0,0 +1,32 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + +#ifndef BOOST_RANGE_REVERSE_RESULT_ITERATOR_HPP +#define BOOST_RANGE_REVERSE_RESULT_ITERATOR_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +#include + +namespace boost +{ + // + // This interface is deprecated, use range_reverse_iterator + // + + template< typename C > + struct range_reverse_result_iterator : range_reverse_iterator + { }; + +} // namespace boost + +#endif From 93deddde63f533ef461a69ab6f357dc990ff90e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 9 Nov 2007 10:27:42 +0000 Subject: [PATCH 26/57] major update wrt. new range concepts [SVN r40962] --- doc/boost_range.html | 185 +++++++++---------------- doc/examples.html | 4 - doc/intro.html | 10 +- doc/mfc_atl.html | 300 ++++++++++++++++++++++++++++++++++++++--- doc/mfc_atl.rst | 8 +- doc/portability.html | 2 +- doc/range.html | 209 ++++------------------------ doc/utility_class.html | 19 +-- 8 files changed, 393 insertions(+), 344 deletions(-) diff --git a/doc/boost_range.html b/doc/boost_range.html index e652436..d8d956d 100644 --- a/doc/boost_range.html +++ b/doc/boost_range.html @@ -94,14 +94,6 @@ class=identifier>range_difference; struct range_reverse_iterator; - - // - // Random Access Range metafunctions - // - - template< class T > - struct range_size; // // Single Pass Range functions @@ -112,7 +104,7 @@ class=identifier>range_size; begin( T& c ); template< class T > - typename range_iterator<T>::type + typename range_iterator<const T>::type begin( const T& c ); template< class T > @@ -120,7 +112,7 @@ class=identifier>range_size; end( T& c ); template< class T > - typename range_iterator<T>::type + typename range_iterator<const T>::type end( const T& c ); template< class T > @@ -144,7 +136,7 @@ class=identifier>range_size; rbegin( T& c ); template< class T > - typename range_reverse_iterator<T>::type + typename range_reverse_iterator<const T>::type rbegin( const T& c ); template< class T > @@ -152,11 +144,10 @@ class=identifier>range_size; rend( T& c ); template< class T > - typename range_reverse_iterator<T>::type + typename range_reverse_iterator<const T>::type rend( const T& c ); - // // Random Access Range functions // @@ -164,7 +155,7 @@ class=identifier>T& template< class T > typename range_size<T>::type size( const T& c ); - + // // Special const Range functions // @@ -247,10 +238,8 @@ class=identifier>T& range_value<X>::type - T::value_type
    - boost::iterator_value<P::first_type>::type
    - A
    - Char + boost::iterator_value<range_iterator<X>::type>::type + compile time @@ -264,7 +253,7 @@ class=identifier>T
    & - range_const_iterator<X>::type + range_iterator<const X>::type T::const_iterator
    P::first_type
    const A*
    @@ -274,20 +263,11 @@ class=identifier>T
    & range_difference<X>::type - T::difference_type
    - boost::iterator_difference<P::first_type>::type
    - std::ptrdiff_t
    - std::ptrdiff_t
    + + boost::iterator_difference<range_iterator<X>::type>::type + compile time - - - range_size<X>::type - T::size_type
    - std::size_t
    - std::size_t
    - std::size_t
    - compile time @@ -301,31 +281,18 @@ class=identifier>T
    & range_reverse_iterator<X>::type - boost::reverse_iterator< typename range_iterator<T>::type >
    + boost::reverse_iterator<range_iterator<X>::type>
    compile time - range_const_reverse_iterator<X>::type - boost::reverse_iterator< typename range_const_iterator<T>::type > + range_reverse_iterator<const X>::type + boost::reverse_iterator<range_iterator<const X>::type>
    compile time - - - range_reverse_result_iterator<X>::type - boost::reverse_iterator< typename range_result_iterator<T>::type - > - compile time -

    -

    - The special metafunctions range_result_iterator and range_reverse_result_iterator - are not part of any Range concept, but they are very useful when implementing - certain Range classes like sub_range - because of their ability to select iterators based on constness. -

    Functions

    @@ -347,7 +314,7 @@ class=identifier>T& p.first if p is of type std::pair<T>
    a if a is an array
    s if s is a string literal
    - boost_range_begin(x) if that expression would invoke a function found by ADL
    + range_begin(x) if that expression would invoke a function found by ADL
    t.begin() otherwise
    @@ -363,7 +330,7 @@ class=identifier>T& s + sz - 1 if s is a string literal of size sz
    - boost_range_end(x) if that expression would invoke a function found by ADL
    + range_end(x) if that expression would invoke a function found by ADL
    t.end() otherwise
    + + + + + + + + + - - + + - - + @@ -408,15 +380,15 @@ class=identifier>T& - - + - - + @@ -424,15 +396,15 @@ class=identifier>T& - - + - - + @@ -440,21 +412,22 @@ class=identifier>T& - - +
    constant timelinear if X is Char* @@ -380,27 +347,32 @@ class=identifier>T&
    distance(x)range_difference<X>::type + + std::distance(boost::begin(x),boost::end(x)) + + -
    size(x)range_size<X>::type - std::distance(p.first,p.second) if p is of type std::pair<T>
    - sz if a is an array of size sz
    - end(s) - s if s is a string literal or a Char*
    - boost_range_size(x) if that expression would invoke a function found by ADL
    - t.size() otherwise -
    linear if X is Char* -
    - or if std::distance() is linear -
    - constant time otherwise
    range_difference<X>::type boost::end(x) - boost::begin(x) + + constant time
    rbegin(x)range_reverse_result_iterator<X>::typerange_reverse_result_iterator<X>::type( end(x) ) + range_reverse_iterator<X>::typerange_reverse_iterator<X>::type( end(x) )
    same as end(x) rend(x)range_reverse_result_iterator<X>::typerange_reverse_result_iterator<X>::type( begin(x) ) + range_reverse_iterator<X>::typerange_reverse_iterator<X>::type( begin(x) ) same as begin(x)
    const_begin(x)range_const_iterator<X>::typerange_const_iterator<X>::type( begin(x) ) + range_iterator<const X>::typerange_iterator<const X>::type( begin(x) )
    same as begin(x) const_end(x)range_const_iterator<X>::typerange_const_iterator<X>::type( end(x) ) + range_iterator<const X>::typerange_iterator<const X>::type( end(x) ) same as end(x)
    const_rbegin(x)range_const_reverse_iterator<X>::typerange_const_reverse_iterator<X>::type( rbegin(x) ) + range_reverse_iterator<const X>::typerange_reverse_iterator<const X>::type( rbegin(x) )
    same as rbegin(x) const_rend(x)range_const_reverse_iterator<X>::typerange_const_reverse_iterator<X>::type( rend(x) ) + range_reverse_iterator<const X>::typerange_reverse_iterator<const X>::type( rend(x) ) same as rend(x)

    - The special const functions are not part of any Range concept, but - are very useful when you want to document clearly that your code is read-only. + The special const_-named functions are useful when you + want to document clearly that your code is read-only.


    Extending the library

    @@ -491,10 +464,6 @@ class=identifier>T
    & Single Pass Range - - size() - Forward Range -

    @@ -520,10 +489,6 @@ class=identifier>T& const_iterator Single Pass Range - - size_type - Forward Range -

    @@ -554,26 +519,23 @@ class=identifier>T& Related concept - boost_range_begin(x) + range_begin(x) Single Pass Range - boost_range_end(x) + range_end(x) Single Pass Range - - boost_range_size(x) - Forward Range - +

    -

    boost_range_begin() and boost_range_end() must be +

    range_begin() and range_end() must be overloaded for both const and mutable reference arguments.

    - You must also specialize 3 metafunctions for your type X: + You must also specialize two metafunctions for your type X:

    @@ -583,17 +545,14 @@ class=identifier>T& Related concept - + - - - - +
    boost::range_iteratorboost::range_mutable_iterator Single Pass Range
    boost::range_const_iterator Single Pass Range
    boost::range_sizeForward Range

    @@ -627,7 +586,7 @@ class=identifier>T& template< class T > - struct range_iterator< Foo::Pair<T> > + struct range_mutable_iterator< Foo::Pair<T> > { typedef T type; }; @@ -636,20 +595,13 @@ class=identifier>T& struct range_const_iterator< Foo::Pair<T> > { // - // Remark: this is defined similar to 'range_iterator' + // 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; }; - template< class T > - struct range_size< Foo::Pair<T> > - { - - typedef std::size_t type; - }; - } // namespace 'boost' namespace Foo @@ -661,36 +613,29 @@ class=identifier>T& template< class T > - inline T boost_range_begin( Pair<T>& x ) + inline T range_begin( Pair<T>& x ) { return x.first; } template< class T > - inline T boost_range_begin( const Pair<T>& x ) + inline T range_begin( const Pair<T>& x ) { return x.first; } template< class T > - inline T boost_range_end( Pair<T>& x ) + inline T range_end( Pair<T>& x ) { return x.last; } template< class T > - inline T boost_range_end( const Pair<T>& x ) + inline T range_end( const Pair<T>& x ) { return x.last; } - template< class T > - inline typename boost::range_size< Pair<T> >::type - boost_range_size( const Pair<T>& x ) - { - return std::distance(x.first,x.last); - } - } // namespace 'Foo' #include <vector> @@ -699,7 +644,7 @@ class=identifier>T& { typedef std::vector<int>::iterator iter; std::vector<int> vec; - Foo::Pair<iter> pair = { vec.begin(), vec.end() }; + Foo::Pair<iter> pair = { vec.begin(), vec.end() }; const Foo::Pair<iter>& cpair = pair; // // Notice that we call 'begin' etc with qualification. @@ -708,9 +653,9 @@ class=identifier>T& iter e = boost::end( pair ); i = boost::begin( cpair ); e = boost::end( cpair ); - boost::range_size< Foo::Pair<iter> >::type s = boost::size( pair ); + boost::range_difference< Foo::Pair<iter> >::type s = boost::size( pair ); s = boost::size( cpair ); - boost::range_const_reverse_iterator< Foo::Pair<iter> >::type + boost::range_reverse_iterator< const Foo::Pair<iter> >::type ri = boost::rbegin( cpair ), re = boost::rend( cpair ); } @@ -719,7 +664,7 @@ class=identifier>T&

    - (C) Copyright Thorsten Ottosen 2003-2004 + (C) Copyright Thorsten Ottosen 2003-2007



    diff --git a/doc/examples.html b/doc/examples.html index 6db7253..0ea235d 100755 --- a/doc/examples.html +++ b/doc/examples.html @@ -26,10 +26,6 @@
  • shows how to implement a container version of std::find() that works with char[],wchar_t[],char*,wchar_t*. -

    - Warning: support for null-terminated strings is deprecated and will - disappear in the next Boost release (1.34). -

  • algorithm_example.cpp diff --git a/doc/intro.html b/doc/intro.html index b0542b2..8478d3e 100755 --- a/doc/intro.html +++ b/doc/intro.html @@ -35,16 +35,14 @@ 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. + works with containers, provided a suitable adapter is used.

    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. + 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. diff --git a/doc/mfc_atl.html b/doc/mfc_atl.html index 5717cc8..a022fe3 100644 --- a/doc/mfc_atl.html +++ b/doc/mfc_atl.html @@ -3,14 +3,289 @@ - + Boost Range MFC/ATL Extension @@ -33,7 +308,7 @@

    Overview

    -

    Boost.Range MFC/ATL Extension provides Boost.Range support for MFC/ATL collection and string types.

    +

    Boost.Range MFC/ATL Extension provides Boost.Range support for MFC/ATL collection and string types.

     CTypedPtrArray<CPtrArray, CList<CString> *> myArray;
     ...
    @@ -64,7 +339,7 @@ BOOST_FOREACH (CList<CString> *theList, myArray)
     

    MFC Ranges

    -

    If the <boost/range/mfc.hpp> is included before or after Boost.Range headers, +

    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.

    @@ -170,7 +445,7 @@ The table below lists the Traversal Category and
    -

    Other Boost.Range metafunctions are defined by the following. +

    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 @@ -179,7 +454,7 @@ As for const

    ATL Ranges

    -

    If the <boost/range/atl.hpp> is included before or after Boost.Range headers, +

    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.

    @@ -265,7 +540,7 @@ The table below lists the Traversal Category and
    -

    Other Boost.Range metafunctions are defined by the following. +

    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 @@ -288,7 +563,7 @@ else if (there is a type X such that X* const is the same as ReF) else return ReF

  • -

    Other Boost.Range metafunctions are defined by the following. +

    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.

    @@ -296,18 +571,11 @@ else - - diff --git a/doc/mfc_atl.rst b/doc/mfc_atl.rst index 3dcd8fe..67498fb 100644 --- a/doc/mfc_atl.rst +++ b/doc/mfc_atl.rst @@ -225,8 +225,8 @@ __ http://msdn2.microsoft.com/en-US/library/15e672bd.aspx .. _Boost C++ Libraries: http://www.boost.org/ .. _Boost: `Boost C++ Libraries`_ -.. _Boost.Range: http://www.boost.org/libs/range/ -.. _forward: http://www.boost.org/libs/range/doc/range.html#forward_range -.. _bidirectional: http://www.boost.org/libs/range/doc/range.html#forward_range -.. _random access: http://www.boost.org/libs/range/doc/range.html#random_access_range +.. _Boost.Range: ../index.html +.. _forward: range.html#forward_range +.. _bidirectional: range.html#forward_range +.. _random access: range.html#random_access_range diff --git a/doc/portability.html b/doc/portability.html index ae3a264..20b1355 100755 --- a/doc/portability.html +++ b/doc/portability.html @@ -36,7 +36,7 @@ href="http://boost.sourceforge.net/regression-logs/developer/range.html">here Notice also that some compilers cannot do function template ordering properly. In that case one must rely of range_result_iterator + href="boost_range.html#range_iterator">range_iterator and a single function definition instead of overloaded versions for const and non-const arguments. diff --git a/doc/range.html b/doc/range.html index 03a773d..dfe9345 100755 --- a/doc/range.html +++ b/doc/range.html @@ -50,7 +50,7 @@ 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 - fewer requirements than a Container. + much fewer requirements than a Container.

    The motivation for the Range concept is @@ -78,9 +78,9 @@ 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 its - iterators support. See also terminology and style guidelines. - for more information about naming of ranges.

    + 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 @@ -118,11 +118,7 @@ Single Pass Iterator

    Associated types

    - - - - + @@ -132,7 +128,7 @@ Single Pass Iterator - + @@ -161,20 +157,16 @@ Single Pass Iterator - - - - - +
    Value typeboost::range_value<X>::typeThe type of the object stored in a Range. -
    Iterator type boost::range_iterator<X>::type
    Const iterator typeboost::range_const_iterator<X>::typeboost::range_iterator<const X>::type A type of iterator that may be used to examine, but not to modify, a Range's elements.
    Beginning of range boost::begin(a) boost::range_iterator<X>::type if -a is mutable, boost::range_const_iterator<X>::type +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_const_iterator<X>::type +a is mutable, boost::range_iterator<const X>::type otherwise
    Is range empty?boost::empty(a)Convertible to bool

    Expression semantics

    @@ -188,7 +180,7 @@ otherwise 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::size(a) == 0. + It is past-the-end if and only if boost::distance(a) == 0. boost::end(a) @@ -196,19 +188,14 @@ otherwise Range. boost::end(a) is past-the-end. - - boost::empty(a) - Equivalent to boost::begin(a) == boost::end(a). (But possibly - faster.) -  -  - +

    Complexity guarantees

    - All three functions are at most amortized linear time. For most practical - purposes, one can expect boost::begin(a), boost::end(a) and boost::empty(a) - to be amortized constant time. + 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.

    Invariants

    @@ -227,14 +214,17 @@ otherwise

    See also

    -

    - Container -

    -

    implementation of +

    Extending the library for UDTs

    +

    Implementation of metafunctions

    -

    implementation of +

    Implementation of functions

    +

    + Container +

    +

    Forward Range

    @@ -261,76 +251,8 @@ href="../../iterator/doc/new-iter-concepts.html#forward-traversal-iterators-lib-

    Refinement of

    Single Pass Range -

    Associated types

    - -
    - - - - - - - - - - -
    Distance typeboost::range_difference<X>::typeA signed integral type used to represent the distance between - two of the Range's iterators. This type must be the same as the iterator's - distance type.
    Size typeboost::range_size<X>::typeAn unsigned integral type that can represent any nonnegative - value of the Range's distance type.
    - -

    Valid expressions

    - - - - - - - - - - - - -
    NameExpressionReturn type
    Size of rangeboost::size(a)boost::range_size<X>::type
    - -

    Expression semantics

    - - - - - - - - - - - - -
    ExpressionSemanticsPostcondition
    boost::size(a)Returns the size of the Range, that is, its number -of elements. Note boost::size(a) == 0u is equivalent to -boost::empty(a).boost::size(a) >= 0
    - -

    Complexity guarantees

    - -

    boost::size(a) is at most amortized linear time.

    - -

    Invariants

    -

    - - - -
    Range sizeboost::size(a) is equal to the distance from boost::begin(a) - to boost::end(a).
    -

    - -

    See also

    -

    implementation of - metafunctions

    - -

    implementation of - functions

    - +

    +

    Bidirectional Range

    @@ -356,83 +278,8 @@ s-lib-bidirectional-traversal-iterators">Bidirectional Traversal Iterator.

    Refinement of

    Forward Range -

    Associated types

    - - - - - - - - - - - - -
    Reverse Iterator typeboost::range_reverse_iterator<X>::typeThe type of iterator used to iterate through a Range's elements - in reverse order. The iterator's value type is expected to be the Range's value - type. A conversion from the reverse iterator type to the const reverse iterator - type must exist.
    Const reverse iterator typeboost::range_const_reverse_iterator<X>::typeA type of reverse iterator that may be used to examine, but not - to modify, a Range's elements.
    - - -

    Valid expressions

    - - - - - - - - - - - - - - - - - - - -
    NameExpressionReturn typeSemantics
    Beginning of rangeboost::rbegin(a)boost::range_reverse_iterator<X>::type if -a is mutable, boost::range_const_reverse_iterator<X>::type -otherwise.Equivalent to -boost::range_reverse_iterator<X>::type(boost::end(a)).
    End of rangeboost::rend(a)boost::range_reverse_iterator<X>::type if -a is mutable, boost::range_const_reverse_iterator<X>::type -otherwise.Equivalent to -boost::range_reverse_iterator<X>::type(boost::begin(a)).
    - -

    Complexity guarantees

    - - boost::rbegin(a) has the same complexity as boost::end(a) and boost::rend(a) - has the same complexity as boost::begin(a) from Forward Range. - -

    Invariants

    -

    - - - - - - - - - -
    Valid reverse rangeFor any Bidirectional Range a, [boost::rbegin(a),boost::rend(a)) - is a valid range, that is, boost::rend(a) is reachable from boost::rbegin(a) - in a finite number of increments.
    CompletenessAn algorithm that iterates through the range [boost::rbegin(a),boost::rend(a)) - will pass through every element of a.
    -

    - -

    See also

    -

    implementation of metafunctions

    - -

    implementation of - functions

    + +


    @@ -455,7 +302,7 @@ href="../../iterator/doc/new-iter-concepts.html#random-access-traversal-iterator

    Concept Checking

    Each of the range concepts has a corresponding concept checking - class in the file boost/range/concepts.hpp. These classes may be + class in the file . These classes may be used in conjunction with the
    Boost Concept Check library to insure that the type of a template parameter @@ -529,7 +376,7 @@ href="../../iterator/doc/new-iter-concepts.html#random-access-traversal-iterator Jeremy Siek - Copyright © 2004 + Copyright © 2004-2007 Thorsten Ottosen. diff --git a/doc/utility_class.html b/doc/utility_class.html index 57bf5dc..16df096 100644 --- a/doc/utility_class.html +++ b/doc/utility_class.html @@ -59,19 +59,16 @@ corresponding const_iterator is.

    If the template argument is not a model of Forward Traversal Iterator, one can still use a subset of the interface. In particular, size() requires - Forward Traversal Iterators whereas empty() only requires Single + Random Access Iterators whereas empty() only requires Single Pass Iterators.

    Recall that many default constructed iterators are singular and hence can only be assigned, but not compared or - incremented or anything. However, if one creates a default constructed - iterator_range, then one - can still call all its member functions. This means that the - iterator_range will still be usable in many contexts even - though the iterators underneath are not. -

    + incremented or anything. Likewise, if one creates a default constructed + iterator_range, then one have to be careful about not doing + anything besides copying.

    Synopsis

    @@ -82,9 +79,6 @@ corresponding const_iterator is.

    class iterator_range { public: // Forward Range types - typedef ... value_type; - typedef ... difference_type; - typedef ... size_type; typedef ForwardTraversalIterator iterator; typedef ForwardTraversalIterator const_iterator; @@ -117,10 +111,11 @@ class=identifier>equal( const iterator_range& ) const; - value_type& front() const; - value_type& back() const; + referencefront() const; + reference back() const; // for Random Access Range only: value_type& operator[]( size_type at ) const; + value_typecial>& operator()( size_type at ) const; }; // stream output From 1509d5603ba1e4bfc4a8bfe832bb918da4617cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 9 Nov 2007 13:13:06 +0000 Subject: [PATCH 27/57] minor editorial issue [SVN r40964] --- index.html | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 29af65a..5313690 100755 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@

    - Copyright © 2003-2004 Thorsten Ottosen + Copyright © 2003-2007 Thorsten Ottosen

    Use, modification and distribution is subject to the Boost Software License, Version 1.0 @@ -52,18 +52,14 @@

  • Terminology and style guidelines
  • Headers
  • Examples -
  • MFC/ATL mapping (courtesy of Shunsuke - Sogame)
  • +
  • MFC/ATL mapping (courtesy of Shunsuke + Sogame)
  • Portability
  • FAQ
  • History and acknowledgment -
    -

    - (C) Copyright Thorsten Ottosen 2003-2004 -



    From 2605b9ee45eee0df583c6093603e1ea3c87d2b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 9 Nov 2007 13:30:57 +0000 Subject: [PATCH 28/57] update of new concepts, and replacement of range_size::type with range_difference::type throughut the library [SVN r40965] --- include/boost/range/concepts.hpp | 47 +++++++++----------------- include/boost/range/iterator_range.hpp | 27 ++++----------- include/boost/range/size.hpp | 7 ++-- include/boost/range/sub_range.hpp | 11 +++--- 4 files changed, 34 insertions(+), 58 deletions(-) diff --git a/include/boost/range/concepts.hpp b/include/boost/range/concepts.hpp index 5faf2de..d9c122f 100755 --- a/include/boost/range/concepts.hpp +++ b/include/boost/range/concepts.hpp @@ -13,8 +13,8 @@ #include #include -#include -#include +#include +#include /*! * \file @@ -57,10 +57,10 @@ namespace boost { //! Check if a type T models the SinglePassRange range concept. template - struct SinglePassRangeConcept { - typedef typename range_value::type range_value; - typedef typename range_iterator::type range_iterator; - //typedef typename range_iterator::type range_const_iterator; + struct SinglePassRangeConcept + { + typedef typename range_iterator::type range_const_iterator; + typedef typename range_iterator::type range_iterator; void constraints() { @@ -71,23 +71,24 @@ namespace boost { >(); i = boost::begin(a); i = boost::end(a); - b = boost::empty(a); const_constraints(a); } + void const_constraints(const T& a) { - //ci = boost::begin(a); - //ci = boost::end(a); + ci = boost::begin(a); + ci = boost::end(a); } T a; range_iterator i; + range_const_iterator ci; bool b; }; //! Check if a type T models the ForwardRange range concept. template - struct ForwardRangeConcept { - typedef typename range_difference::type range_difference; + struct ForwardRangeConcept + { void constraints() { function_requires< @@ -103,8 +104,8 @@ namespace boost { //! Check if a type T models the BidirectionalRange range concept. template - struct BidirectionalRangeConcept { - typedef typename range_reverse_iterator::type range_reverse_iterator; + struct BidirectionalRangeConcept + { void constraints() { function_requires< @@ -115,24 +116,13 @@ namespace boost { typename range_iterator::type > >(); - i = boost::rbegin(a); - i = boost::rend(a); - const_constraints(a); - } - void const_constraints(const T& a) - { - //ci = boost::rbegin(a); - //ci = boost::rend(a); } - T a; - range_reverse_iterator i; }; //! Check if a type T models the RandomAccessRange range concept. template - struct RandomAccessRangeConcept { - typedef typename range_size::type range_size; - + struct RandomAccessRangeConcept + { void constraints() { function_requires< @@ -143,12 +133,7 @@ namespace boost { typename range_iterator::type > >(); - - s = boost::size(a); } - - T a; - range_size s; }; } // namespace boost diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index bcead14..9df24c0 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -73,7 +73,7 @@ namespace boost template< class Left, class Right > inline bool equal( const Left& l, const Right& r ) { - typedef BOOST_DEDUCED_TYPENAME boost::range_size::type sz_type; + typedef BOOST_DEDUCED_TYPENAME boost::range_difference::type sz_type; sz_type l_size = boost::size( l ), r_size = boost::size( r ); @@ -166,20 +166,7 @@ namespace boost , singular( true ) #endif { } -/* -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) - iterator_range( this_type r ) : - : m_Begin(r.begin()), m_End(r.end()) - { } - - this_type& operator=( this_type r ) - { - m_Begin = r.begin(); - m_End = r.end(); - return *this; - } -#endif -*/ + //! Constructor from a pair of iterators template< class Iterator > iterator_range( Iterator Begin, Iterator End ) : @@ -283,7 +270,7 @@ namespace boost return m_End; } - size_type size() const + difference_type size() const { BOOST_ASSERT( !is_singular() ); return m_End - m_Begin; @@ -351,9 +338,9 @@ namespace boost return *--last; } - reference operator[]( size_type at ) const + reference operator[]( difference_type at ) const { - BOOST_ASSERT( at < size() ); + BOOST_ASSERT( at >= 0 && at < size() ); return m_Begin[at]; } @@ -362,9 +349,9 @@ namespace boost // fails because it returns by reference. Therefore // operator()() is provided for these cases. // - value_type operator()( size_type at ) const + value_type operator()( difference_type at ) const { - BOOST_ASSERT( at < size() ); + BOOST_ASSERT( at >= 0 && at < size() ); return m_Begin[at]; } diff --git a/include/boost/range/size.hpp b/include/boost/range/size.hpp index eb021a5..311a692 100755 --- a/include/boost/range/size.hpp +++ b/include/boost/range/size.hpp @@ -17,14 +17,17 @@ #include #include -#include +#include +#include namespace boost { template< class T > - inline BOOST_DEDUCED_TYPENAME range_size::type size( const T& r ) + inline BOOST_DEDUCED_TYPENAME range_difference::type size( const T& r ) { + BOOST_ASSERT( (boost::end( r ) - boost::begin( r )) >= 0 && + "reachability invariant broken!" ); return boost::end( r ) - boost::begin( r ); } diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index 30daaea..802454b 100755 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -38,6 +38,7 @@ namespace boost typedef BOOST_DEDUCED_TYPENAME range_iterator::type const_iterator; typedef BOOST_DEDUCED_TYPENAME range_difference::type difference_type; typedef BOOST_DEDUCED_TYPENAME range_size::type size_type; + typedef BOOST_DEDUCED_TYPENAME base::reference reference; public: sub_range() : base() @@ -100,11 +101,11 @@ namespace boost const_iterator begin() const { return base::begin(); } iterator end() { return base::end(); } const_iterator end() const { return base::end(); } - size_type size() const { return base::size(); } + difference_type size() const { return base::size(); } public: // convenience - value_type& front() + reference front() { return base::front(); } @@ -114,7 +115,7 @@ namespace boost return base::front(); } - value_type& back() + reference back() { return base::back(); } @@ -124,12 +125,12 @@ namespace boost return base::back(); } - value_type& operator[]( size_type sz ) + reference operator[]( difference_type sz ) { return base::operator[](sz); } - const value_type& operator[]( size_type sz ) const + const value_type& operator[]( difference_type sz ) const { return base::operator[](sz); } From 7b3857a9a81fe2f9e8deffd0ed6950463c48a8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 9 Nov 2007 13:31:43 +0000 Subject: [PATCH 29/57] minor tweaks to avoid warnings ... extension mechanism updated to follow new protocol [SVN r40966] --- test/algorithm_example.cpp | 4 ++-- test/array.cpp | 2 +- test/extension_mechanism.cpp | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/algorithm_example.cpp b/test/algorithm_example.cpp index d14a597..85e2b22 100755 --- a/test/algorithm_example.cpp +++ b/test/algorithm_example.cpp @@ -64,14 +64,14 @@ void check_algorithm() // // usage // - const unsigned N = 5; + const int N = 5; std::vector my_vector; int values[] = { 1,2,3,4,5,6,7,8,9 }; my_vector.assign( values, values + 9 ); typedef std::vector::iterator iterator; std::pair my_view( boost::begin( my_vector ), boost::begin( my_vector ) + N ); - BOOST_CHECK_EQUAL( my_generic_replace( my_vector, 4, 2 ), 3u ); + BOOST_CHECK_EQUAL( my_generic_replace( my_vector, 4, 2 ), 3 ); BOOST_CHECK_EQUAL( my_generic_replace( my_view, 4, 2 ), N ); } diff --git a/test/array.cpp b/test/array.cpp index a83151c..b438dce 100755 --- a/test/array.cpp +++ b/test/array.cpp @@ -63,7 +63,7 @@ void check_array() BOOST_CHECK_EQUAL( empty( ca ),false ); const char A[] = "\0A"; - BOOST_CHECK_EQUAL( boost::size(A), 3u ); + BOOST_CHECK_EQUAL( boost::size(A), 3 ); } using boost::unit_test::test_suite; diff --git a/test/extension_mechanism.cpp b/test/extension_mechanism.cpp index 2fd7929..a206afb 100755 --- a/test/extension_mechanism.cpp +++ b/test/extension_mechanism.cpp @@ -44,7 +44,6 @@ namespace Foo typedef std::vector data_t; typedef data_t::iterator iterator; typedef data_t::const_iterator const_iterator; - typedef data_t::size_type size_type; data_t vec; From 6ac0cfe09c09ce5c6ec631129b96c6e668994725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 9 Nov 2007 15:15:28 +0000 Subject: [PATCH 30/57] improved reference [SVN r40968] --- doc/boost_range.html | 169 +++++++++++++++++++++++++++++-------------- 1 file changed, 114 insertions(+), 55 deletions(-) diff --git a/doc/boost_range.html b/doc/boost_range.html index d8d956d..65284fa 100644 --- a/doc/boost_range.html +++ b/doc/boost_range.html @@ -70,6 +70,10 @@ class=identifier>range_iterator; struct range_value; + template< class T > + struct range_reference; + template< class T > struct range_pointer; @@ -101,23 +105,23 @@ class=identifier>range_reverse_iterator; template< class T > typename range_iterator<T>::type - begin( T& c ); + begin( T& r ); template< class T > typename range_iterator<const T>::type - begin( const T& c ); + begin( const T& r ); template< class T > typename range_iterator<T>::type - end( T& c ); + end( T& r ); template< class T > typename range_iterator<const T>::type - end( const T& c ); + end( const T& r ); template< class T > bool - empty( const T& c ); + empty( const T& r ); // // Forward Range functions @@ -125,7 +129,7 @@ class=identifier>range_reverse_iterator; template< class T > typename range_difference<T>::type - distance( const T& c ); + distance( const T& r ); // // Bidirectional Range functions @@ -133,20 +137,20 @@ class=identifier>range_reverse_iterator; template< class T > typename range_reverse_iterator<T>::type - rbegin( T& c ); + rbegin( T& r ); template< class T > typename range_reverse_iterator<const T>::type - rbegin( const T& c ); + rbegin( const T& r ); template< class T > typename range_reverse_iterator<T>::type - rend( T& c ); + rend( T& r ); template< class T > typename range_reverse_iterator<const T>::type rend( const T& c ); +class=identifier>T& r ); // // Random Access Range functions @@ -154,7 +158,7 @@ class=identifier>T& template< class T > typename range_size<T>::type - size( const T& c ); + size( const T& r ); // // Special const Range functions @@ -176,6 +180,26 @@ class=identifier>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'
  • @@ -235,20 +259,13 @@ class=identifier>T& Complexity - - - range_value<X>::type - boost::iterator_value<range_iterator<X>::type>::type - - compile time - range_iterator<X>::type T::iterator
    P::first_type
    A*
    - Char* + compile time @@ -257,7 +274,37 @@ class=identifier>T
    & T::const_iterator
    P::first_type
    const A*
    - const Char* + + compile time + + + + range_value<X>::type + boost::iterator_value<range_iterator<X>::type>::type + + compile time + + + + range_reference<X>::type + boost::iterator_reference<range_iterator<X>::type>::type + + compile time + + + + + range_pointer<X>::type + boost::iterator_pointer<range_iterator<X>::type>::type + + compile time + + + + + range_category<X>::type + boost::iterator_category<range_iterator<X>::type>::type + compile time @@ -269,15 +316,7 @@ class=identifier>T
    & compile time - - - range_result_iterator<X>::type - range_const_iterator<X>::type if X is const -
    - range_iterator<X>::type otherwise - - compile time - + range_reverse_iterator<X>::type @@ -309,11 +348,10 @@ class=identifier>T
    & begin(x) - range_result_iterator<X>::type + range_iterator<X>::type p.first if p is of type std::pair<T>
    a if a is an array
    - s if s is a string literal
    range_begin(x) if that expression would invoke a function found by ADL
    t.begin() otherwise @@ -322,29 +360,24 @@ class=identifier>T
    & end(x) - range_result_iterator<X>::type + range_iterator<X>::type p.second if p is of type std::pair<T>
    - a + sz if a is an array of size sz
    - s + std::char_traits<X>::length( s ) if s is a Char* -
    - s + sz - 1 if s is a string literal of size sz + a + sz if a is an array of size sz +
    range_end(x) if that expression would invoke a function found by ADL
    t.end() otherwise - linear if X is Char* -
    - constant time otherwise + + constant time empty(x) bool - begin(x) == end( x )
    - linear if X is Char* -
    - constant time otherwise
    + boost::begin(x) == boost::end(x)
    + constant time
    @@ -372,49 +405,71 @@ class=identifier>T
    & rbegin(x) range_reverse_iterator<X>::type - range_reverse_iterator<X>::type( end(x) ) + range_reverse_iterator<X>::type( boost::end(x) )
    - same as end(x) + constant time rend(x) range_reverse_iterator<X>::type - range_reverse_iterator<X>::type( begin(x) ) - same as begin(x) + range_reverse_iterator<X>::type( boost::begin(x) ) + constant time const_begin(x) range_iterator<const X>::type - range_iterator<const X>::type( begin(x) ) + range_iterator<const X>::type( boost::begin(x) )
    - same as begin(x) + constant time const_end(x) range_iterator<const X>::type - range_iterator<const X>::type( end(x) ) - same as end(x) + range_iterator<const X>::type( boost::end(x) ) + constant time const_rbegin(x) range_reverse_iterator<const X>::type - range_reverse_iterator<const X>::type( rbegin(x) ) + range_reverse_iterator<const X>::type( boost::rbegin(x) )
    - same as rbegin(x) + constant time const_rend(x) range_reverse_iterator<const X>::type - range_reverse_iterator<const X>::type( rend(x) ) - same as rend(x) + range_reverse_iterator<const X>::type( boost::rend(x) ) + + constant time + + + + as_literal(x) + iterator_range<U> where U is + Char* if x is a pointer to a + string and U is + range_iterator<X>::type otherwise + + + + [a,a+sz-1) if a is an array of size sz
    + [s,s + std::char_traits<X>::length(s)) if s is a Char* +
    + [boost::begin(x),boost::end(x)) otherwise + + + + + linear time for pointers to a string, constant time + otherwise

    @@ -422,6 +477,10 @@ class=identifier>T
    & const_
    -named functions are useful when you want to document clearly that your code is read-only.

    +

    Notice that the above functions should always be called with + qualification (boost::) to prevent unintended + Argument Dependent Lookup (ADL). +


    Extending the library

    From a2f3a45214ca4ceb11a87e34709fad93d47d67c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 17 Nov 2007 20:22:05 +0000 Subject: [PATCH 31/57] minor update of comments [SVN r41175] --- include/boost/range/begin.hpp | 5 +++++ include/boost/range/concepts.hpp | 1 - include/boost/range/end.hpp | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/boost/range/begin.hpp b/include/boost/range/begin.hpp index e8251c9..9abf313 100755 --- a/include/boost/range/begin.hpp +++ b/include/boost/range/begin.hpp @@ -41,6 +41,11 @@ namespace range_detail inline BOOST_DEDUCED_TYPENAME range_iterator::type range_begin( C& c ) { + // + // If you get a compile-error here, it is most likely because + // you have not implemented range_begin() properly in + // the namespace of C + // return c.begin(); } diff --git a/include/boost/range/concepts.hpp b/include/boost/range/concepts.hpp index d9c122f..53a88dc 100755 --- a/include/boost/range/concepts.hpp +++ b/include/boost/range/concepts.hpp @@ -82,7 +82,6 @@ namespace boost { T a; range_iterator i; range_const_iterator ci; - bool b; }; //! Check if a type T models the ForwardRange range concept. diff --git a/include/boost/range/end.hpp b/include/boost/range/end.hpp index be2f495..b777a55 100755 --- a/include/boost/range/end.hpp +++ b/include/boost/range/end.hpp @@ -42,6 +42,11 @@ namespace range_detail inline BOOST_DEDUCED_TYPENAME range_iterator::type range_end( C& c ) { + // + // If you get a compile-error here, it is most likely because + // you have not implemented range_begin() properly in + // the namespace of C + // return c.end(); } From ba96d075b216f080095161bfb7a097c8480cbdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 17 Nov 2007 20:22:20 +0000 Subject: [PATCH 32/57] last updates [SVN r41176] --- doc/boost_range.html | 24 ++++++++++++++++- doc/headers.html | 23 +++++++---------- doc/utility_class.html | 58 ++++++++++++++++++++++-------------------- 3 files changed, 63 insertions(+), 42 deletions(-) diff --git a/doc/boost_range.html b/doc/boost_range.html index 65284fa..ace1901 100644 --- a/doc/boost_range.html +++ b/doc/boost_range.html @@ -157,7 +157,7 @@ class=identifier>T& template< class T > - typename range_size<T>::type + typename range_difference<T>::type size( const T& r ); // @@ -471,12 +471,34 @@ class=identifier>T& linear time for pointers to a string, constant time otherwise + + + as_array(x) + iterator_range<X> + + [boost::begin(x),boost::end(x)) + + + + + + constant time otherwise + +

    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 to 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). diff --git a/doc/headers.html b/doc/headers.html index 1539ae8..69987ce 100755 --- a/doc/headers.html +++ b/doc/headers.html @@ -50,7 +50,7 @@ >range_iterator Single Pass Range - + <boost/range/mutable_iterator.hpp> range_mutable_iterator @@ -69,20 +69,15 @@ Forward Range - <boost/range/size_type.hpp> - range_size - Forward Range - - <boost/range/pointer.hpp> range_pointer + >range_pointer - - + <boost/range/category.hpp> range_category + >range_category - @@ -112,7 +107,7 @@ empty Single Pass Range - + <boost/range/distance.hpp> distance Forward Range @@ -121,7 +116,7 @@ <boost/range/size.hpp> size Random Access Range - + <boost/range/rbegin.hpp> @@ -139,14 +134,14 @@ Bidirectional Range - + <boost/range/as_array.hpp> as_array - - + <boost/range/as_literal.hpp> as_literal @@ -178,7 +173,7 @@


    - (C) Copyright Thorsten Ottosen 2003-2004 + (C) Copyright Thorsten Ottosen 2003-2007


    diff --git a/doc/utility_class.html b/doc/utility_class.html index 16df096..f7b5535 100644 --- a/doc/utility_class.html +++ b/doc/utility_class.html @@ -79,9 +79,10 @@ corresponding const_iterator is.

    class iterator_range { public: // Forward Range types - typedef ForwardTraversalIterator iterator; - typedef ForwardTraversalIterator const_iterator; - + typedef ForwardTraversalIterator iterator; + typedef ForwardTraversalIterator const_iterator; + typedef iterator_difference<iterator>::type difference_type; +
    public: // construction, assignment template< class ForwardTraversalIterator2 > iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End ); @@ -99,23 +100,24 @@ corresponding const_iterator is.

    iterator_range& operator=( const ForwardRange& r ); public: // Forward Range functions - iterator begin() const; - iterator end() const; - size_type size() const; - bool empty() const; + iterator begin() const; + iterator end() const; + difference_type size() const; + bool empty() const; public: // convenience - operator unspecified_bool_type() const; - bool operator unspecified_bool_type() const; + bool equal( const iterator_range& ) ( const iterator_range& ) const; - referencefront() const; - reference back() const; + reference front() const; + reference back() const; + iterator_range& advance_begin( difference_type n ); + iterator_range& advance_end( difference_type n ); // for Random Access Range only: - value_type& operator[]( size_type at ) const; - value_typecial>& operator()( size_type at ) const; + reference operator[]( difference_type at ) const; + value_type operator()( difference_type at ) const; }; // stream output @@ -168,11 +170,11 @@ class=keyword>const; ForwardTraversalIterator End ); template< class ForwardRange > - iterator_range< typename iterator<ForwardRange>::type > + iterator_range< typename range_iterator<ForwardRange>::type > make_iterator_range( ForwardRange& r ); template< class ForwardRange > - iterator_range< typename const_iterator<ForwardRange>::type > + iterator_range< typename range_iterator<const ForwardRange>::type > make_iterator_range( const ForwardRange& r ); template< class Range > @@ -182,7 +184,7 @@ class=keyword>const; typename range_difference<Range>::type advance_end ); template< class Range > - iterator_range< typename range_const_iterator<Range>::type > + iterator_range< typename range_iterator<const Range>::type > make_iterator_range( const Range& r, typename range_difference<Range>::type advance_begin, typename range_difference<Range>::type advance_end ); @@ -286,12 +288,14 @@ class can propagate constness since it knows what a corresponding namespace boost { template< class ForwardRange > - class sub_range : public iterator_range< typename range_result_iterator<ForwardRange>::type > + class sub_range : public iterator_range< typename range_iterator<ForwardRange>::type > { public: - typedef typename range_result_iterator<ForwardRange>::type iterator; - typedef typename range_const_iterator<ForwardRange>::type const_iterator; + typedef typename range_iterator<ForwardRange>::type iterator; + typedef typename range_iterator<const ForwardRange>::type const_iterator; + typedef typename iterator_difference<iterator>::type difference_type; + public: // construction, assignment template< class ForwardTraversalIterator > sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End ); @@ -320,8 +324,8 @@ class can propagate constness since it knows what a corresponding value_type& back(); const value_type& back() const; // for Random Access Range only: - value_type& operator[]( size_type at ); - const value_type& operator[]( size_type at ) const; + value_type& operator[]( difference_type at ); + const value_type& operator[]( difference_type at ) const; public: // rest of interface inherited from iterator_range @@ -339,15 +343,15 @@ store the result from this algorithm. Here is an example of how we can do it with and without sub_range
    -    std::string str("hello");
    -    iterator_range<std::string::iterator> ir = find_first( str, "ll" );
    -    sub_range<std::string>               sub = find_first( str, "ll" );
    +    std::string str("hello");
    +    iterator_range<std::string::iterator> ir = find_first( str, as_literal("ll") );
    +    sub_range<std::string>               sub = find_first( str, as_literal("ll") );
     


    - (C) Copyright Thorsten Ottosen 2003-2004 + (C) Copyright Thorsten Ottosen 2003-2007


    From dd1459f221605e63adc2e7745f922cd36c264f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 17 Nov 2007 20:44:29 +0000 Subject: [PATCH 33/57] works after local test with vc8 [SVN r41177] --- include/boost/range/detail/microsoft.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/boost/range/detail/microsoft.hpp b/include/boost/range/detail/microsoft.hpp index 2c4b1ed..7b672c9 100644 --- a/include/boost/range/detail/microsoft.hpp +++ b/include/boost/range/detail/microsoft.hpp @@ -1,9 +1,6 @@ #ifndef BOOST_RANGE_DETAIL_MICROSOFT_HPP #define BOOST_RANGE_DETAIL_MICROSOFT_HPP - - - // Boost.Range MFC/ATL Extension // // Copyright Shunsuke Sogame 2005-2006. @@ -931,5 +928,4 @@ namespace boost { namespace range_detail_microsoft { - #endif From 637dc618d19cffe1347ce3031d2177196e485566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 17 Nov 2007 21:19:13 +0000 Subject: [PATCH 34/57] iostream macro patch [SVN r41180] --- include/boost/range/iterator_range.hpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index 9df24c0..4304ecc 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -29,11 +29,13 @@ #include #include #include -#ifndef BOOST_OLD_IOSTREAMS -# include -#else -# include -#endif +#ifndef _STLP_NO_IOSTREAMS +# ifndef BOOST_OLD_IOSTREAMS +# include +# else +# include +# endif +#endif // _STLP_NO_IOSTREAMS #include #if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || BOOST_WORKAROUND(BOOST_MSVC, == 1400) @@ -396,7 +398,8 @@ namespace boost // iterator range free-standing operators ---------------------------// -#ifndef BOOST_OLD_IOSTREAMS +#ifndef _STLP_NO_IOSTREAMS +# ifndef BOOST_OLD_IOSTREAMS //! iterator_range output operator /*! @@ -415,7 +418,7 @@ namespace boost return Os; } -#else +# else //! iterator_range output operator /*! @@ -431,7 +434,8 @@ namespace boost return Os; } -#endif +# endif +#endif // _STLP_NO_IOSTREAMS ///////////////////////////////////////////////////////////////////// // comparison operators From 2e0d7eab4abfe838a6995576e9b4b0fef0a551e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 17 Nov 2007 21:21:53 +0000 Subject: [PATCH 35/57] removed some warnings [SVN r41181] --- test/iterator_pair.cpp | 6 +++--- test/std_container.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/iterator_pair.cpp b/test/iterator_pair.cpp index d50a1f7..2546817 100755 --- a/test/iterator_pair.cpp +++ b/test/iterator_pair.cpp @@ -65,17 +65,17 @@ void check_iterator_pair() BOOST_CHECK( begin( pair ) == pair.first ); BOOST_CHECK( end( pair ) == pair.second ); BOOST_CHECK( empty( pair ) == (pair.first == pair.second) ); - BOOST_CHECK( size( pair ) == std::size_t( std::distance( pair.first, pair.second ) ) ); + BOOST_CHECK( size( pair ) == std::distance( pair.first, pair.second ) ); BOOST_CHECK( begin( const_pair ) == const_pair.first ); BOOST_CHECK( end( const_pair ) == const_pair.second ); BOOST_CHECK( empty( const_pair ) == (const_pair.first == const_pair.second) ); - BOOST_CHECK( size( const_pair ) == std::size_t( std::distance( const_pair.first, const_pair.second ) ) ); + BOOST_CHECK( size( const_pair ) == std::distance( const_pair.first, const_pair.second ) ); BOOST_CHECK( begin( constness_pair ) == constness_pair.first ); BOOST_CHECK( end( constness_pair ) == constness_pair.second ); BOOST_CHECK( empty( constness_pair ) == (constness_pair.first == const_pair.second) ); - BOOST_CHECK( size( constness_pair ) == std::size_t( std::distance( constness_pair.first, constness_pair.second ) ) ); + BOOST_CHECK( size( constness_pair ) == std::distance( constness_pair.first, constness_pair.second ) ); } diff --git a/test/std_container.cpp b/test/std_container.cpp index e26d2a3..e2ee692 100755 --- a/test/std_container.cpp +++ b/test/std_container.cpp @@ -48,12 +48,12 @@ void check_std_container() BOOST_CHECK( begin( vec ) == vec.begin() ); BOOST_CHECK( end( vec ) == vec.end() ); BOOST_CHECK( empty( vec ) == vec.empty() ); - BOOST_CHECK( size( vec ) == vec.size() ); + BOOST_CHECK( (std::size_t)size( vec ) == vec.size() ); BOOST_CHECK( begin( cvec ) == cvec.begin() ); BOOST_CHECK( end( cvec ) == cvec.end() ); BOOST_CHECK( empty( cvec ) == cvec.empty() ); - BOOST_CHECK( size( cvec ) == cvec.size() ); + BOOST_CHECK( (std::size_t)size( cvec ) == cvec.size() ); } From 0eb365edbe727d708488990370b33eff75723a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 17 Nov 2007 21:24:16 +0000 Subject: [PATCH 36/57] macro patch [SVN r41183] --- include/boost/range/config.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/range/config.hpp b/include/boost/range/config.hpp index 5f856bb..4e7fb24 100755 --- a/include/boost/range/config.hpp +++ b/include/boost/range/config.hpp @@ -37,8 +37,7 @@ #error "macro already defined!" #endif -//#if BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) || __MWERKS__ <= 0x3003 -#if _MSC_VER <= 1300 && !defined( __COMO__ ) && !defined( __GNUC__ ) && __MWERKS__ <= 0x3003 +#if BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) || BOOST_WORKAROUND( __MWERKS__, <= 0x3003 ) #define BOOST_RANGE_NO_ARRAY_SUPPORT 1 #endif From 8085605217683ee016cf7f760d46c61e24175649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Thu, 29 Nov 2007 09:19:24 +0000 Subject: [PATCH 37/57] fixed a serious oversigt [SVN r41457] --- include/boost/range/iterator_range.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index 4304ecc..31b8ea8 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -77,8 +77,8 @@ namespace boost { typedef BOOST_DEDUCED_TYPENAME boost::range_difference::type sz_type; - sz_type l_size = boost::size( l ), - r_size = boost::size( r ); + sz_type l_size = boost::distance( l ), + r_size = boost::distance( r ); if( l_size != r_size ) return false; From f65c137e736a3da22fa70b6a6f97a79e30d0029a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Mon, 3 Dec 2007 09:00:23 +0000 Subject: [PATCH 38/57] missing include [SVN r41636] --- include/boost/range/sub_range.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index 802454b..35dfb27 100755 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -11,6 +11,8 @@ #ifndef BOOST_RANGE_SUB_RANGE_HPP #define BOOST_RANGE_SUB_RANGE_HPP +#include + #if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || BOOST_WORKAROUND(BOOST_MSVC, == 1400) #pragma warning( disable : 4996 ) #endif From 14a9a1906b0126d828bf164753a70b0f9815bf0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Mon, 3 Dec 2007 09:08:02 +0000 Subject: [PATCH 39/57] Ticket #1477 [SVN r41638] --- include/boost/range/detail/sizer.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/boost/range/detail/sizer.hpp b/include/boost/range/detail/sizer.hpp index 5d75437..b4c1c91 100755 --- a/include/boost/range/detail/sizer.hpp +++ b/include/boost/range/detail/sizer.hpp @@ -25,12 +25,10 @@ namespace boost ////////////////////////////////////////////////////////////////////// template< typename T, std::size_t sz > - char& - sizer( const T BOOST_RANGE_ARRAY_REF()[sz] )[sz]; + char (& sizer( const T BOOST_RANGE_ARRAY_REF()[sz] ) )[sz]; template< typename T, std::size_t sz > - char& - sizer( T BOOST_RANGE_ARRAY_REF()[sz] )[sz]; + char (& sizer( T BOOST_RANGE_ARRAY_REF()[sz] ) )[sz]; } // namespace 'boost' From d31787daae612b09b1ea7cf24b7c264f1bdcab91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sat, 12 Jan 2008 12:38:57 +0000 Subject: [PATCH 40/57] doc fixes [SVN r42693] --- doc/boost_range.html | 2 +- doc/history_ack.html | 8 ++++---- doc/intro.html | 3 +-- doc/portability.html | 2 +- doc/utility_class.html | 9 +++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/boost_range.html b/doc/boost_range.html index ace1901..ed84e1a 100644 --- a/doc/boost_range.html +++ b/doc/boost_range.html @@ -493,7 +493,7 @@ class=identifier>T
    &

    as_literal() can be used internally in string - algorithm librararies to such that arrays of characters are + algorithm librararies such that arrays of characters are handled correctly.

    diff --git a/doc/history_ack.html b/doc/history_ack.html index 40ee5dc..289bfa8 100755 --- a/doc/history_ack.html +++ b/doc/history_ack.html @@ -18,10 +18,10 @@

    History and Acknowledgement

    - The library have been 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. + 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.

    diff --git a/doc/intro.html b/doc/intro.html index 8478d3e..4ed653b 100755 --- a/doc/intro.html +++ b/doc/intro.html @@ -63,8 +63,7 @@ free-standing functions so syntactic and/or semantic differences can be removed.

    -

    - Below are given a small example (the complete example can be found Below is given a small example (the complete example can be found here):

     
    diff --git a/doc/portability.html b/doc/portability.html
    index 20b1355..506d5b2 100755
    --- a/doc/portability.html
    +++ b/doc/portability.html
    @@ -35,7 +35,7 @@ href="http://boost.sourceforge.net/regression-logs/developer/range.html">here
         

    Notice also that some compilers cannot do function template ordering properly. - In that case one must rely of range_iterator and a single function definition instead of overloaded versions for const and non-const arguments. diff --git a/doc/utility_class.html b/doc/utility_class.html index f7b5535..c4afe54 100644 --- a/doc/utility_class.html +++ b/doc/utility_class.html @@ -33,11 +33,12 @@ - The iterator_range class is templated on an - Forward + The iterator_range class is templated on a Forward Traversal Iterator and should be used whenever fairly general code is needed. - The sub_range class is templated on an Forward - Range and it is less general, but a bit easier to use since its template + The sub_range class is templated on a Forward Range and it is less general, + but a bit easier to use since its template argument is easier to specify. The biggest difference is, however, that a sub_range can propagate constness because it knows what a corresponding const_iterator is.

    From 507d1e8075cde410e0339346a887fa56c217bcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Sun, 13 Jan 2008 11:37:41 +0000 Subject: [PATCH 41/57] fixed #if to #ifdef [SVN r42715] --- include/boost/range/as_literal.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/range/as_literal.hpp b/include/boost/range/as_literal.hpp index 72f0eb5..b0d7593 100755 --- a/include/boost/range/as_literal.hpp +++ b/include/boost/range/as_literal.hpp @@ -15,7 +15,7 @@ # pragma once #endif -#if BOOST_NO_FUNCTION_TEMPLATE_ORDERING +#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING #include #else @@ -116,14 +116,14 @@ namespace boost template< class Char, std::size_t sz > - inline iterator_range as_literal( const Char (&arr)[sz] ) + inline iterator_range as_literal( const Char (&arr)[sz] ) { #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x590)) && __BORLANDC__ >= 0x590 return boost::make_iterator_range( arr, arr + sz - 1 ); #else return boost::make_iterator_range( arr, arr + sz - 1 ); #endif - } + } } #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING From 73db2a05b60c0fe3b91b93219964b089e8994665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Wed, 6 Feb 2008 23:12:21 +0000 Subject: [PATCH 42/57] cleanup to pass inspection tool [SVN r43135] --- doc/Jamfile.v2 | 10 ++++++++++ doc/boost_range.html | 8 +++++++- doc/example.cpp | 10 ++++++++++ doc/examples.html | 9 ++++++++- doc/faq.html | 11 +++++++++-- doc/headers.html | 9 ++++++++- doc/history_ack.html | 9 ++++++++- doc/intro.html | 9 ++++++++- doc/portability.html | 11 +++++++++-- doc/range.html | 36 +++++++++--------------------------- doc/style.css | 11 +++++++++++ doc/style.html | 8 +++++++- doc/utility_class.html | 15 +++++++++++---- test/TODO | 1 - test/compat1.cpp | 0 15 files changed, 115 insertions(+), 42 deletions(-) delete mode 100644 test/TODO delete mode 100755 test/compat1.cpp diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 0fafdd7..bfe0908 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -1,3 +1,13 @@ +#// Boost.Range library +#// +#// Copyright Thorsten Ottosen 2003-2008. Use, modification and +#// distribution is subject to 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) +#// +#// For more information, see http://www.boost.org/libs/range/ +#// + use-project boost : $(BOOST_ROOT) ; diff --git a/doc/boost_range.html b/doc/boost_range.html index ed84e1a..465bd18 100644 --- a/doc/boost_range.html +++ b/doc/boost_range.html @@ -745,7 +745,13 @@ class=identifier>T
    &

    - (C) Copyright Thorsten Ottosen 2003-2007 + © 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)



    diff --git a/doc/example.cpp b/doc/example.cpp index afe448f..d3dec7c 100644 --- a/doc/example.cpp +++ b/doc/example.cpp @@ -1,3 +1,13 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2008. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + #include #include // for std::iterator_traits, std::distance() diff --git a/doc/examples.html b/doc/examples.html index 0ea235d..0d24509 100755 --- a/doc/examples.html +++ b/doc/examples.html @@ -41,9 +41,16 @@
  • array.cpp +

    - (C) Copyright Thorsten Ottosen 2003-2004 + © 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)


    diff --git a/doc/faq.html b/doc/faq.html index 34304ef..244df80 100755 --- a/doc/faq.html +++ b/doc/faq.html @@ -114,9 +114,16 @@ Cool indeed! -
    +

    - (C) Copyright Thorsten Ottosen 2003-2004 + © 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)


    diff --git a/doc/headers.html b/doc/headers.html index 69987ce..7628591 100755 --- a/doc/headers.html +++ b/doc/headers.html @@ -173,7 +173,14 @@

    - (C) Copyright Thorsten Ottosen 2003-2007 + © 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)


    diff --git a/doc/history_ack.html b/doc/history_ack.html index 289bfa8..3191dd0 100755 --- a/doc/history_ack.html +++ b/doc/history_ack.html @@ -61,7 +61,14 @@ C++ standard:

    - (C) Copyright Thorsten Ottosen 2003-2006 + © 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)


    diff --git a/doc/intro.html b/doc/intro.html index 4ed653b..9f41c72 100755 --- a/doc/intro.html +++ b/doc/intro.html @@ -135,7 +135,14 @@ Notice that we have to

    - (C) Copyright Thorsten Ottosen 2003-2007 + © 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)


    diff --git a/doc/portability.html b/doc/portability.html index 506d5b2..9e63978 100755 --- a/doc/portability.html +++ b/doc/portability.html @@ -73,11 +73,18 @@ href="http://boost.sourceforge.net/regression-logs/developer/range.html">here

    -
    +

    - (C) Copyright Thorsten Ottosen 2003-2004 + © 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) +

    > +


    diff --git a/doc/range.html b/doc/range.html index dfe9345..b140888 100755 --- a/doc/range.html +++ b/doc/range.html @@ -352,34 +352,16 @@ href="../../iterator/doc/new-iter-concepts.html#random-access-traversal-iterator

    Boost Concept Check library


    +

    + © Copyright Thorsten Ottosen 2008. +

    - - - - - - - - -
    Copyright © 2000Jeremy Siek -
    Copyright © 2004-2007Thorsten Ottosen. -
    - +

    + 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) +




    diff --git a/doc/style.css b/doc/style.css index 1890b52..ce44c30 100755 --- a/doc/style.css +++ b/doc/style.css @@ -1,3 +1,14 @@ +/* +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2008. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/range/ +// +*/ pre{ BORDER-RIGHT: gray 1pt solid; PADDING-RIGHT: 2pt; diff --git a/doc/style.html b/doc/style.html index 9a5617e..cd82c94 100755 --- a/doc/style.html +++ b/doc/style.html @@ -104,9 +104,15 @@

    - (C) Copyright Thorsten Ottosen 2003-2004 + © 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) +




    diff --git a/doc/utility_class.html b/doc/utility_class.html index c4afe54..ea51503 100644 --- a/doc/utility_class.html +++ b/doc/utility_class.html @@ -350,10 +350,17 @@ store the result
  • -
    -

    - (C) Copyright Thorsten Ottosen 2003-2007 -

    +
    +

    + © 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) +



    diff --git a/test/TODO b/test/TODO deleted file mode 100644 index 8b13789..0000000 --- a/test/TODO +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/compat1.cpp b/test/compat1.cpp deleted file mode 100755 index e69de29..0000000 From 428e72ed225724c4fdfca9ef5867f95279ac8415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Thu, 7 Feb 2008 14:41:04 +0000 Subject: [PATCH 43/57] iterator_range disables msvc warning 4996 [range] sub_range assignment issue [SVN r43155] --- include/boost/range/iterator_range.hpp | 13 +++++++++---- include/boost/range/sub_range.hpp | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index 31b8ea8..7dcf033 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -11,6 +11,11 @@ #ifndef BOOST_RANGE_ITERATOR_RANGE_HPP #define BOOST_RANGE_ITERATOR_RANGE_HPP +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) + #pragma warning( push ) + #pragma warning( disable : 4996 ) +#endif + // From boost/dynamic_bitset.hpp; thanks to Matthias Troyer for Cray X1 patch. #include // Define __STL_CONFIG_H, if appropriate. #ifndef BOOST_OLD_IOSTREAMS @@ -38,10 +43,6 @@ #endif // _STLP_NO_IOSTREAMS #include -#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || BOOST_WORKAROUND(BOOST_MSVC, == 1400) - #pragma warning( disable : 4996 ) -#endif - /*! \file Defines the \c iterator_class and related functions. \c iterator_range is a simple wrapper of iterator pair idiom. It provides @@ -639,5 +640,9 @@ namespace boost #undef BOOST_OLD_IOSTREAMS +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) + #pragma warning( pop ) +#endif + #endif diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index 35dfb27..d28da93 100755 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -11,12 +11,12 @@ #ifndef BOOST_RANGE_SUB_RANGE_HPP #define BOOST_RANGE_SUB_RANGE_HPP -#include - -#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || BOOST_WORKAROUND(BOOST_MSVC, == 1400) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) + #pragma warning( push ) #pragma warning( disable : 4996 ) #endif +#include #include #include #include @@ -46,7 +46,7 @@ namespace boost sub_range() : base() { } -#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || BOOST_WORKAROUND(BOOST_MSVC, == 1400) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) ) sub_range( const sub_range& r ) : base( static_cast( r ) ) { } @@ -163,5 +163,9 @@ namespace boost } // namespace 'boost' +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) + #pragma warning( pop ) +#endif + #endif From 8b712359a2a074139a6f9f53aaaf6529e56c706a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Thu, 7 Feb 2008 14:46:19 +0000 Subject: [PATCH 44/57] test [SVN r43156] --- test/partial_workaround.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/partial_workaround.cpp b/test/partial_workaround.cpp index 8ac6f66..76d902f 100755 --- a/test/partial_workaround.cpp +++ b/test/partial_workaround.cpp @@ -10,6 +10,8 @@ #include #include +#include +#include #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) # pragma warn -8091 // supress warning in Boost.Test @@ -30,7 +32,6 @@ #include #include -#include #include #include @@ -91,6 +92,11 @@ void check_partial_workaround() void check_partial_workaround() { + // + // test if warnings are generated + // + std::size_t s = boost::range_detail::array_size( "foo" ); + BOOST_CHECK_EQUAL( s, 4u ); } #endif From e115ac1006200bdce2a066c767b97bc3108279e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 8 Feb 2008 09:58:35 +0000 Subject: [PATCH 45/57] silence of warnings for unused arguments [SVN r43171] --- include/boost/range/detail/implementation_help.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/boost/range/detail/implementation_help.hpp b/include/boost/range/detail/implementation_help.hpp index da086f0..ca12fa4 100755 --- a/include/boost/range/detail/implementation_help.hpp +++ b/include/boost/range/detail/implementation_help.hpp @@ -25,6 +25,8 @@ namespace boost { namespace range_detail { + template + inline void boost_range_silence_warning( const T& ) { } ///////////////////////////////////////////////////////////////////// // end() help @@ -82,12 +84,14 @@ namespace boost template< class T, std::size_t sz > inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz] ) { + boost_range_silence_warning( boost_range_array ); return sz; } template< class T, std::size_t sz > inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz] ) { + boost_range_silence_warning( boost_range_array ); return sz; } From 94b45ef51eee837d7c5e2b819c39e8d057b7e650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 8 Feb 2008 15:25:01 +0000 Subject: [PATCH 46/57] missing ) fixed [SVN r43175] --- include/boost/range/iterator_range.hpp | 4 ++-- include/boost/range/sub_range.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index 7dcf033..21e503b 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -11,7 +11,7 @@ #ifndef BOOST_RANGE_ITERATOR_RANGE_HPP #define BOOST_RANGE_ITERATOR_RANGE_HPP -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) #pragma warning( push ) #pragma warning( disable : 4996 ) #endif @@ -640,7 +640,7 @@ namespace boost #undef BOOST_OLD_IOSTREAMS -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) #pragma warning( pop ) #endif diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index d28da93..d033b14 100755 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -11,7 +11,7 @@ #ifndef BOOST_RANGE_SUB_RANGE_HPP #define BOOST_RANGE_SUB_RANGE_HPP -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) #pragma warning( push ) #pragma warning( disable : 4996 ) #endif @@ -163,7 +163,7 @@ namespace boost } // namespace 'boost' -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) #pragma warning( pop ) #endif From 405ebd8cca4c28fef1cbd7510dcb1b7aec402198 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 11 Feb 2008 03:48:41 +0000 Subject: [PATCH 47/57] include config.hpp and workaround.hpp before uses of BOOST_WORKAROUND and BOOST_MSVC [SVN r43220] --- include/boost/range/iterator_range.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index 21e503b..3853ea6 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -11,13 +11,15 @@ #ifndef BOOST_RANGE_ITERATOR_RANGE_HPP #define BOOST_RANGE_ITERATOR_RANGE_HPP +#include // Define __STL_CONFIG_H, if appropriate. +#include + #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) #pragma warning( push ) #pragma warning( disable : 4996 ) #endif // From boost/dynamic_bitset.hpp; thanks to Matthias Troyer for Cray X1 patch. -#include // Define __STL_CONFIG_H, if appropriate. #ifndef BOOST_OLD_IOSTREAMS # if defined(__STL_CONFIG_H) && \ !defined (__STL_USE_NEW_IOSTREAMS) && !defined(__crayx1) \ @@ -26,7 +28,6 @@ # endif #endif // #ifndef BOOST_OLD_IOSTREAMS -#include #include #include #include From 7c0d73b8cfb6f310defe11364e2f2e731c78c057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 19 Feb 2008 15:10:05 +0000 Subject: [PATCH 48/57] fixed problem with operator()() when the value_type was abstract. [SVN r43322] --- include/boost/range/iterator_range.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index 3853ea6..6a85a45 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -28,11 +28,13 @@ # endif #endif // #ifndef BOOST_OLD_IOSTREAMS +#include +#include +#include #include #include #include -#include -#include +#include #include #include #ifndef _STLP_NO_IOSTREAMS @@ -165,6 +167,12 @@ namespace boost //! iterator type typedef IteratorT iterator; + private: // for return value of operator()() + typedef BOOST_DEDUCED_TYPENAME + boost::mpl::if_< boost::is_abstract, + reference, value_type >::type abstract_value_type; + + public: iterator_range() : m_Begin( iterator() ), m_End( iterator() ) #ifndef NDEBUG , singular( true ) @@ -352,8 +360,8 @@ namespace boost // When storing transform iterators, operator[]() // fails because it returns by reference. Therefore // operator()() is provided for these cases. - // - value_type operator()( difference_type at ) const + // + abstract_value_type operator()( difference_type at ) const { BOOST_ASSERT( at >= 0 && at < size() ); return m_Begin[at]; From f117011b60400b225abd2e018cbabd3d8811abfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Mon, 5 May 2008 06:41:54 +0000 Subject: [PATCH 49/57] fix for as_literal() [SVN r45123] --- include/boost/range/as_literal.hpp | 17 ++++------------- include/boost/range/detail/as_literal.hpp | 4 ++-- 2 files changed, 6 insertions(+), 15 deletions(-) mode change 100755 => 100644 include/boost/range/as_literal.hpp mode change 100755 => 100644 include/boost/range/detail/as_literal.hpp diff --git a/include/boost/range/as_literal.hpp b/include/boost/range/as_literal.hpp old mode 100755 new mode 100644 index b0d7593..97eff15 --- a/include/boost/range/as_literal.hpp +++ b/include/boost/range/as_literal.hpp @@ -8,8 +8,8 @@ // For more information, see http://www.boost.org/libs/range/ // -#ifndef BOOST_RANGE_DETAIL_AS_LITERAL_HPP -#define BOOST_RANGE_DETAIL_AS_LITERAL_HPP +#ifndef BOOST_RANGE_AS_LITERAL_HPP +#define BOOST_RANGE_AS_LITERAL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once @@ -107,22 +107,13 @@ namespace boost template< class Char, std::size_t sz > inline iterator_range as_literal( Char (&arr)[sz] ) { -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x590)) && __BORLANDC__ >= 0x590 - return boost::make_iterator_range( arr, arr + sz - 1 ); -#else - return boost::make_iterator_range( arr, arr + sz - 1 ); -#endif + return range_detail::make_range( arr, range_detail::is_char_ptr(arr) ); } - template< class Char, std::size_t sz > inline iterator_range as_literal( const Char (&arr)[sz] ) { -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x590)) && __BORLANDC__ >= 0x590 - return boost::make_iterator_range( arr, arr + sz - 1 ); -#else - return boost::make_iterator_range( arr, arr + sz - 1 ); -#endif + return range_detail::make_range( arr, range_detail::is_char_ptr(arr) ); } } diff --git a/include/boost/range/detail/as_literal.hpp b/include/boost/range/detail/as_literal.hpp old mode 100755 new mode 100644 index b4fd925..0bd9a15 --- a/include/boost/range/detail/as_literal.hpp +++ b/include/boost/range/detail/as_literal.hpp @@ -8,8 +8,8 @@ // For more information, see http://www.boost.org/libs/range/ // -#ifndef BOOST_RANGE_AS_LITERAL_HPP -#define BOOST_RANGE_AS_LITERAL_HPP +#ifndef BOOST_RANGE_DETAIL_AS_LITERAL_HPP +#define BOOST_RANGE_DETAIL_AS_LITERAL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once From 36a99eb0a0c0351d1b897523f66a5d5610dc4d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Mon, 5 May 2008 06:42:30 +0000 Subject: [PATCH 50/57] test of updated as_literal() [SVN r45124] --- test/string.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) mode change 100755 => 100644 test/string.cpp diff --git a/test/string.cpp b/test/string.cpp old mode 100755 new mode 100644 index 9a2e5a8..127f70a --- a/test/string.cpp +++ b/test/string.cpp @@ -137,14 +137,7 @@ void check_char() BOOST_CHECK_EQUAL( str_end( char_s ), str_end1 ); BOOST_CHECK_EQUAL( str_empty( char_s ), (char_s == 0 || char_s[0] == char()) ); BOOST_CHECK_EQUAL( sz, std::char_traits::length( char_s ) ); -/* - BOOST_CHECK_EQUAL( str_begin( char_s2 ), char_s2 ); - std::size_t sz2 = size( char_s2 ); - const char* str_end12 = str_begin( char_s2 ) + sz; - BOOST_CHECK_EQUAL( str_end( char_s2 ), str_end12 ); - BOOST_CHECK_EQUAL( empty( char_s2 ), (char_s2 == 0 || char_s2[0] == char()) ); - BOOST_CHECK_EQUAL( sz2, std::char_traits::length( char_s2 ) ); -*/ + BOOST_CHECK_EQUAL( str_begin( my_string ), my_string ); range_iterator::type str_end2 = str_begin( my_string ) + str_size(my_string); range_iterator::type str_end3 = str_end(my_string); @@ -165,6 +158,20 @@ void check_char() BOOST_CHECK( find_const( as_array( my_string ), to_search ) != str_end(my_string) ); BOOST_CHECK( find_const( as_array( my_const_string ), to_search ) != str_end(my_string) ); + + // + // Test that as_literal() always scan for null terminator + // + char an_array[] = "foo\0bar"; + BOOST_CHECK_EQUAL( str_begin( an_array ), an_array ); + BOOST_CHECK_EQUAL( str_end( an_array ), an_array + 3 ); + BOOST_CHECK_EQUAL( str_size( an_array ), 3 ); + + const char a_const_array[] = "foobar\0doh"; + BOOST_CHECK_EQUAL( str_begin( a_const_array ), a_const_array ); + BOOST_CHECK_EQUAL( str_end( a_const_array ), a_const_array + 6 ); + BOOST_CHECK_EQUAL( str_size( a_const_array ), 6 ); + } @@ -172,9 +179,6 @@ void check_char() void check_string() { check_char(); -// check_char(); -// check_char(); -// check_char(); #ifndef BOOST_NO_STD_WSTRING typedef wchar_t* wchar_iterator_t; @@ -197,13 +201,7 @@ void check_string() BOOST_CHECK_EQUAL( str_end(char_ws), (str_begin( char_ws ) + sz) ); BOOST_CHECK_EQUAL( str_empty( char_ws ), (char_ws == 0 || char_ws[0] == wchar_t()) ); BOOST_CHECK_EQUAL( sz, std::char_traits::length( char_ws ) ); - /* - std::size_t sz2 = size( char_ws2 ); - BOOST_CHECK_EQUAL( str_begin( char_ws2 ), char_ws2 ); - BOOST_CHECK_EQUAL( str_end( char_ws2 ), (begin( char_ws2 ) + sz2) ); - BOOST_CHECK_EQUAL( empty( char_ws2 ), (char_ws2 == 0 || char_ws2[0] == wchar_t()) ); - BOOST_CHECK_EQUAL( sz2, std::char_traits::length( char_ws2 ) ); - */ + wchar_t to_search = L'n'; BOOST_CHECK( find( char_ws, to_search ) != str_end(char_ws) ); From 95d424012b165811f7c6817e6f40e039a4c941d6 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 11 May 2008 13:49:20 +0000 Subject: [PATCH 51/57] Quote href values - our tools don't support unquoted values. [SVN r45283] --- doc/intro.html | 2 +- doc/style.html | 2 +- doc/utility_class.html | 6 +++--- index.html | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) mode change 100755 => 100644 doc/intro.html mode change 100755 => 100644 doc/style.html mode change 100755 => 100644 index.html diff --git a/doc/intro.html b/doc/intro.html old mode 100755 new mode 100644 index 9f41c72..82f10dc --- a/doc/intro.html +++ b/doc/intro.html @@ -24,7 +24,7 @@ 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. + href="range.html">Ranges as much as possible.

    diff --git a/doc/style.html b/doc/style.html old mode 100755 new mode 100644 index cd82c94..4240a8c --- a/doc/style.html +++ b/doc/style.html @@ -53,7 +53,7 @@ Bidirectional Range

  • Random Access Range - Notice how we have used the categories from the new + Notice how we have used the categories from the new style iterators.

    diff --git a/doc/utility_class.html b/doc/utility_class.html index ea51503..e100859 100644 --- a/doc/utility_class.html +++ b/doc/utility_class.html @@ -27,9 +27,9 @@

    @@ -329,7 +329,7 @@ class can propagate constness since it knows what a corresponding const value_type& operator[]( difference_type at ) const; public: - // rest of interface inherited from iterator_range + // rest of interface inherited from iterator_range }; } // namespace 'boost' diff --git a/index.html b/index.html old mode 100755 new mode 100644 index 5313690..56ba4eb --- a/index.html +++ b/index.html @@ -22,7 +22,7 @@

    Use, modification and distribution is subject to the Boost Software License, Version 1.0 - (see + (see http://www.boost.org/LICENSE_1_0.txt).

    From b948d9af17c4aadb4cc0b057ea85ee86f0915e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Thu, 12 Jun 2008 10:00:54 +0000 Subject: [PATCH 52/57] fixes for problems from Trac [SVN r46345] --- include/boost/range/iterator_range.hpp | 12 +++++++----- include/boost/range/sub_range.hpp | 14 +++++++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) mode change 100755 => 100644 include/boost/range/iterator_range.hpp mode change 100755 => 100644 include/boost/range/sub_range.hpp diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp old mode 100755 new mode 100644 index 6a85a45..d118224 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -185,7 +185,7 @@ namespace boost m_Begin(Begin), m_End(End) #ifndef NDEBUG , singular(false) - #endif + #endif {} //! Constructor from a Range @@ -210,7 +210,7 @@ namespace boost template< class Range > iterator_range( const Range& r, iterator_range_detail::const_range_tag ) : m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) - #ifndef NDEBUG + #ifndef NDEBUG , singular(false) #endif {} @@ -219,7 +219,7 @@ namespace boost template< class Range > iterator_range( Range& r, iterator_range_detail::range_tag ) : m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) - #ifndef NDEBUG + #ifndef NDEBUG , singular(false) #endif {} @@ -390,13 +390,15 @@ namespace boost bool singular; #endif - #ifndef NDEBUG public: bool is_singular() const { + #ifndef NDEBUG return singular; + #else + return false; + #endif } - #endif protected: // diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp old mode 100755 new mode 100644 index d033b14..dc66692 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include namespace boost { @@ -41,6 +43,12 @@ namespace boost typedef BOOST_DEDUCED_TYPENAME range_difference::type difference_type; typedef BOOST_DEDUCED_TYPENAME range_size::type size_type; typedef BOOST_DEDUCED_TYPENAME base::reference reference; + + public: // for return value of front/back + typedef BOOST_DEDUCED_TYPENAME + boost::mpl::if_< boost::is_reference, + const BOOST_DEDUCED_TYPENAME boost::remove_reference::type&, + reference >::type const_reference; public: sub_range() : base() @@ -112,7 +120,7 @@ namespace boost return base::front(); } - const value_type& front() const + const_reference front() const { return base::front(); } @@ -122,7 +130,7 @@ namespace boost return base::back(); } - const value_type& back() const + const_reference back() const { return base::back(); } @@ -132,7 +140,7 @@ namespace boost return base::operator[](sz); } - const value_type& operator[]( difference_type sz ) const + const_reference operator[]( difference_type sz ) const { return base::operator[](sz); } From dbef3564c43f4b789f26b8c8db832f0b32a5100e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Thu, 12 Jun 2008 10:54:44 +0000 Subject: [PATCH 53/57] fixes from Trac [SVN r46346] --- include/boost/range/as_literal.hpp | 7 ++++++- include/boost/range/begin.hpp | 8 ++++---- include/boost/range/end.hpp | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-) mode change 100755 => 100644 include/boost/range/begin.hpp mode change 100755 => 100644 include/boost/range/end.hpp diff --git a/include/boost/range/as_literal.hpp b/include/boost/range/as_literal.hpp index 97eff15..38cc9cf 100644 --- a/include/boost/range/as_literal.hpp +++ b/include/boost/range/as_literal.hpp @@ -25,7 +25,9 @@ #include #include +#ifndef BOOST_NO_CWCHAR #include +#endif namespace boost { @@ -36,10 +38,12 @@ namespace boost return strlen( s ); } +#ifndef BOOST_NO_INTRINSIC_WCHAR_T inline std::size_t length( const wchar_t* s ) { return wcslen( s ); } +#endif // // Remark: the compiler cannot choose between T* and T[sz] @@ -57,7 +61,7 @@ namespace boost return true; } - +#ifndef BOOST_NO_INTRINSIC_WCHAR_T inline bool is_char_ptr( wchar_t* ) { return true; @@ -67,6 +71,7 @@ namespace boost { return true; } +#endif template< class T > inline long is_char_ptr( T /* r */ ) diff --git a/include/boost/range/begin.hpp b/include/boost/range/begin.hpp old mode 100755 new mode 100644 index 9abf313..a4a5e10 --- a/include/boost/range/begin.hpp +++ b/include/boost/range/begin.hpp @@ -73,15 +73,15 @@ namespace range_detail // May this be discarded? Or is it needed for bad compilers? // template< typename T, std::size_t sz > - inline const T* range_begin( const T (&array)[sz] ) + inline const T* range_begin( const T (&a)[sz] ) { - return array; + return a; } template< typename T, std::size_t sz > - inline T* range_begin( T (&array)[sz] ) + inline T* range_begin( T (&a)[sz] ) { - return array; + return a; } diff --git a/include/boost/range/end.hpp b/include/boost/range/end.hpp old mode 100755 new mode 100644 index b777a55..3063c02 --- a/include/boost/range/end.hpp +++ b/include/boost/range/end.hpp @@ -71,15 +71,15 @@ namespace range_detail ////////////////////////////////////////////////////////////////////// template< typename T, std::size_t sz > - inline const T* range_end( const T (&array)[sz] ) + inline const T* range_end( const T (&a)[sz] ) { - return range_detail::array_end( array ); + return range_detail::array_end( a ); } template< typename T, std::size_t sz > - inline T* range_end( T (&array)[sz] ) + inline T* range_end( T (&a)[sz] ) { - return range_detail::array_end( array ); + return range_detail::array_end( a ); } #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \ From 15a697f86b3458fe47cb201362209f450de2486b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Thu, 12 Jun 2008 12:00:57 +0000 Subject: [PATCH 54/57] new jamfile to see warnings better [SVN r46348] --- test/Jamfile.v2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index b6942ca..c82a6c9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -12,9 +12,9 @@ rule range-test ( name : includes * ) { return [ run $(name).cpp /boost/test//boost_unit_test_framework/static + : : - : - : $(includes) + : gcc:"-Wall -Wunused " ] ; } From d20121bf12bc0c425a28d5b3d221ecc830577b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 24 Jun 2008 15:39:28 +0000 Subject: [PATCH 55/57] html fix [SVN r46650] --- doc/boost_range.html | 110 ++++++++++++++++++++--------------------- doc/examples.html | 8 +-- doc/faq.html | 4 +- doc/headers.html | 2 +- doc/intro.html | 2 +- doc/portability.html | 5 +- doc/range.html | 14 +++--- doc/utility_class.html | 27 +++++----- index.html | 2 +- 9 files changed, 87 insertions(+), 87 deletions(-) mode change 100755 => 100644 doc/examples.html mode change 100755 => 100644 doc/faq.html mode change 100755 => 100644 doc/headers.html mode change 100755 => 100644 doc/portability.html mode change 100755 => 100644 doc/range.html diff --git a/doc/boost_range.html b/doc/boost_range.html index 465bd18..b9fd0ca 100644 --- a/doc/boost_range.html +++ b/doc/boost_range.html @@ -152,7 +152,7 @@ class=identifier>range_reverse_iterator; rend( const T& r ); - // + // // Random Access Range functions // @@ -235,7 +235,7 @@ class=identifier>T& A[sz] a denotes an array of type A of size sz - + Char* s @@ -259,9 +259,9 @@ class=identifier>T& Complexity - - - range_iterator<X>::type + + + range_iterator<X>::type T::iterator
    P::first_type
    A*
    @@ -269,8 +269,8 @@ class=identifier>T
    & compile time - - range_iterator<const X>::type + + range_iterator<const X>::type T::const_iterator
    P::first_type
    const A*
    @@ -278,54 +278,53 @@ class=identifier>T
    & compile time - - range_value<X>::type + + range_value<X>::type boost::iterator_value<range_iterator<X>::type>::type compile time - - range_reference<X>::type + + range_reference<X>::type boost::iterator_reference<range_iterator<X>::type>::type compile time - - range_pointer<X>::type + + range_pointer<X>::type boost::iterator_pointer<range_iterator<X>::type>::type compile time - - range_category<X>::type + + range_category<X>::type boost::iterator_category<range_iterator<X>::type>::type compile time - - range_difference<X>::type + + range_difference<X>::type boost::iterator_difference<range_iterator<X>::type>::type compile time - - - range_reverse_iterator<X>::type + + range_reverse_iterator<X>::type boost::reverse_iterator<range_iterator<X>::type>
    compile time - - range_reverse_iterator<const X>::type + + range_reverse_iterator<const X>::type boost::reverse_iterator<range_iterator<const X>::type>
    compile time @@ -346,11 +345,11 @@ class=identifier>T
    & - - begin(x) + + begin(x) range_iterator<X>::type - p.first if p is of type std::pair<T>
    + p.first if p is of type std::pair<T>
    a if a is an array
    range_begin(x) if that expression would invoke a function found by ADL
    t.begin() otherwise @@ -358,11 +357,11 @@ class=identifier>T
    & constant time - - end(x) + + end(x) range_iterator<X>::type - p.second if p is of type std::pair<T>
    + p.second if p is of type std::pair<T>
    a + sz if a is an array of size sz
    @@ -373,16 +372,16 @@ class=identifier>T
    & - - empty(x) + + empty(x) bool boost::begin(x) == boost::end(x)
    constant time
    - - distance(x) + + distance(x) range_difference<X>::type @@ -394,16 +393,16 @@ class=identifier>T
    & - - size(x) + + size(x) range_difference<X>::type boost::end(x) - boost::begin(x) constant time - - rbegin(x) + + rbegin(x) range_reverse_iterator<X>::type range_reverse_iterator<X>::type( boost::end(x) )
    @@ -411,15 +410,15 @@ class=identifier>T
    & - - rend(x) + + rend(x) range_reverse_iterator<X>::type range_reverse_iterator<X>::type( boost::begin(x) ) constant time - - const_begin(x) + + const_begin(x) range_iterator<const X>::type range_iterator<const X>::type( boost::begin(x) )
    @@ -427,15 +426,15 @@ class=identifier>T
    & - - const_end(x) + + const_end(x) range_iterator<const X>::type range_iterator<const X>::type( boost::end(x) ) constant time - - const_rbegin(x) + + const_rbegin(x) range_reverse_iterator<const X>::type range_reverse_iterator<const X>::type( boost::rbegin(x) )
    @@ -443,16 +442,16 @@ class=identifier>T
    & - - const_rend(x) + + const_rend(x) range_reverse_iterator<const X>::type range_reverse_iterator<const X>::type( boost::rend(x) ) constant time - - as_literal(x) + + as_literal(x) iterator_range<U> where U is Char* if x is a pointer to a string and U is @@ -460,20 +459,21 @@ class=identifier>T& - [a,a+sz-1) if a is an array of size sz
    - [s,s + std::char_traits<X>::length(s)) if s is a Char* + + [s,s + std::char_traits<X>::length(s)) if s is a Char* or an array of Char
    [boost::begin(x),boost::end(x)) otherwise - linear time for pointers to a string, constant time - otherwise + linear time for pointers to a string or arrays of + Char, constant time otherwise - - as_array(x) + + as_array(x) iterator_range<X> [boost::begin(x),boost::end(x)) @@ -561,7 +561,7 @@ class=identifier>T
    & Related concept - + iterator Single Pass Range diff --git a/doc/examples.html b/doc/examples.html old mode 100755 new mode 100644 index 0d24509..d1f9887 --- a/doc/examples.html +++ b/doc/examples.html @@ -23,16 +23,16 @@
    • 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. - +
    • iterator_range.cpp
    • sub_range.cpp
    • iterator_pair.cpp diff --git a/doc/faq.html b/doc/faq.html old mode 100755 new mode 100644 index 244df80..fcacf98 --- a/doc/faq.html +++ b/doc/faq.html @@ -22,7 +22,7 @@
    • Why is there no difference between 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> @@ -33,7 +33,7 @@ is somewhat more convenient than a pair and that a sub_range does propagate const-ness.

      - +
    • Why is there not supplied more types or more functions?

      diff --git a/doc/headers.html b/doc/headers.html old mode 100755 new mode 100644 index 7628591..c896bff --- a/doc/headers.html +++ b/doc/headers.html @@ -167,7 +167,7 @@ -

      diff --git a/doc/intro.html b/doc/intro.html index 82f10dc..89d3504 100644 --- a/doc/intro.html +++ b/doc/intro.html @@ -108,7 +108,7 @@ class=identifier>ForwardReadableRange >:: my_vector.assign( values, boost::end( values ) ); - typedef std::vector<int>::iterator iterator; + 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"; diff --git a/doc/portability.html b/doc/portability.html old mode 100755 new mode 100644 index 9e63978..bb73e78 --- a/doc/portability.html +++ b/doc/portability.html @@ -29,9 +29,8 @@ href="http://boost.sourceforge.net/regression-logs/developer/range.html">here - - Visual C++ 6/7.0 has a limited support for arrays: as long as the arrays are - of built-in type it should work. +

      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. diff --git a/doc/range.html b/doc/range.html old mode 100755 new mode 100644 index b140888..8646141 --- a/doc/range.html +++ b/doc/range.html @@ -1,3 +1,4 @@ +


      - +

      Single Pass Range

      Notation

      @@ -227,7 +228,7 @@ otherwise
      -

      Forward Range

      +

      Forward Range

      Notation

      @@ -255,7 +256,7 @@ Range
      -

      Bidirectional Range

      +

      Bidirectional Range

      Notation

      @@ -283,7 +284,8 @@ s-lib-bidirectional-traversal-iterators">Bidirectional Traversal Iterator.
      -

      Random Access Range

      Description

      +

      Random Access Range

      +

      Description

      A range X where boost::range_iterator<X>::type is a model of Boost Concept Check library to insure that the type of a template parameter diff --git a/doc/utility_class.html b/doc/utility_class.html index e100859..956bf99 100644 --- a/doc/utility_class.html +++ b/doc/utility_class.html @@ -31,7 +31,6 @@

    • Class sub_range - The iterator_range class is templated on a Forward @@ -84,7 +83,7 @@ corresponding const_iterator is.

      typedef ForwardTraversalIterator const_iterator; typedef iterator_difference<iterator>::type difference_type; - public: // construction, assignment + public: // construction, assignment template< class ForwardTraversalIterator2 > iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End ); @@ -110,7 +109,7 @@ corresponding const_iterator is.

      operator
      unspecified_bool_type() const; bool equal( const iterator_range& ) ( const iterator_range& ) const; reference front() const; reference back() const; @@ -119,7 +118,7 @@ class=keyword>const; // for Random Access Range only: reference operator[]( difference_type at ) const; value_type operator()( difference_type at ) const; - }; + }; // stream output template< class ForwardTraversalIterator, class T, class Traits > @@ -164,7 +163,7 @@ class=keyword>const; bool operator<( const ForwardRange& l, const iterator_range<ForwardTraversalIterator>& r ); - // external construction + // external construction template< class ForwardTraversalIterator > iterator_range< ForwardTraversalIterator > make_iterator_range( ForwardTraversalIterator Begin, @@ -190,7 +189,7 @@ class=keyword>const; typename range_difference<Range>::type advance_begin, typename range_difference<Range>::type advance_end ); - // convenience + // convenience template< class Sequence, class ForwardRange > Sequence copy_range(

      -bool equal( iterator_range& r ) const; +bool equal( iterator_range& r ) const;

      - Returns begin() == r.begin() && end() == r.end(); + Returns begin() == r.begin() && end() == r.end();

      @@ -236,21 +235,21 @@ non-const iterators from the same container.

      -bool operator==( const ForwardRange1& l, const ForwardRange2& r ); +bool operator==( const ForwardRange1& l, const ForwardRange2& r );

      Returns size(l) != size(r) ? false : std::equal( begin(l), end(l), begin(r) );

      -bool operator!=( const ForwardRange1& l, const ForwardRange2& r ); +bool operator!=( const ForwardRange1& l, const ForwardRange2& r );
      Returns !( l == r );
      -bool operator<( const ForwardRange1& l, const ForwardRange2& r ); +bool operator<( const ForwardRange1& l, const ForwardRange2& r );
      Returns std::lexicographical_compare( begin(l), end(l), begin(r), end(r) );

      -iterator_range make_iterator_range( Range& r, 
      +iterator_range make_iterator_range( Range& r, 
                                           typename range_difference<Range>::type advance_begin, 
                                           typename range_difference<Range>::type advance_end );
       
      @@ -266,7 +265,7 @@ return make_iterator_range( new_begin, new_end );

      -Sequence copy_range( const ForwardRange& r ); +Sequence copy_range( const ForwardRange& r );

      Returns Sequence( begin(r), end(r) );
      @@ -292,7 +291,7 @@ class can propagate constness since it knows what a corresponding
      class sub_range : public iterator_range< typename range_iterator<ForwardRange>::type > { public: - typedef typename range_iterator<ForwardRange>::
      type iterator; + typedef typename range_iterator<ForwardRange>::type iterator; typedef typename range_iterator<const ForwardRange>::type const_iterator; typedef typename iterator_difference<iterator>::type difference_type; diff --git a/index.html b/index.html index 56ba4eb..e846421 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,7 @@

        -
      • Introduction +
      • Introduction
      • Range concepts:
          From 8724a83c49e856edd0d96eac560a682b62750ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Wed, 16 Jul 2008 19:59:34 +0000 Subject: [PATCH 56/57] doc updates [SVN r47482] --- doc/upgrading.html | 78 ++++++++++++++++++++++++++++++++++++++++++++++ index.html | 2 ++ 2 files changed, 80 insertions(+) create mode 100644 doc/upgrading.html diff --git a/doc/upgrading.html b/doc/upgrading.html new file mode 100644 index 0000000..fdab5ab --- /dev/null +++ b/doc/upgrading.html @@ -0,0 +1,78 @@ + + + + + + Boost.Range Upgrading + + + + +
    • + + + + +

      Boost.Range

      + +

      Upgrading from Boost v. 1.34.*

      +

      + Boost v. 1.35 introduced some larger refactorings of the library: +

      +
        +
      • Direct support for character arrays was abandoned in favor of + uniform treatment of all arrays. Instead string algorithms can use + the new function as_literal().
      • +
      • boost::size() now requires a Random Access Range. The old behavior is provided as boost::distance()
      • +
      • range_size<T>::type has been completely removed + in favor of range_difference<T>::type +
      • + boost_range_begin() and boost_range_end() + have been renamed range_begin() and range_begin(), respectively.
      • + + +
      • range_result_iterator<T>::type and + range_reverse_result_iterator<T>::type are have + been renamed + range_iterator<T>::type and + range_reverse_iterator<T>::type. +
      • +
      • The procedure that makes a custom type work with the library + has been greatly simplified. See extending the library + for details.
      • +
      + + +
      +

      + © 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) +

      + +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + + + + + diff --git a/index.html b/index.html index e846421..3e5f4bb 100644 --- a/index.html +++ b/index.html @@ -55,6 +55,8 @@
    • MFC/ATL mapping (courtesy of Shunsuke Sogame)
    • Portability +
    • Upgrading from Boost v. + 1.34.*
    • FAQ
    • History and acknowledgment From 2dab8cfbc9fcd88bf77fa118b4f604eb3c9df7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 22 Jul 2008 09:15:00 +0000 Subject: [PATCH 57/57] update in response to inspection report [SVN r47678] --- doc/upgrading.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/upgrading.html b/doc/upgrading.html index fdab5ab..2d76111 100644 --- a/doc/upgrading.html +++ b/doc/upgrading.html @@ -26,8 +26,9 @@ the new function as_literal().
    • boost::size() now requires a Random Access Range. The old behavior is provided as boost::distance()
    • + href="boost_range.html#size">boost::size() now requires a Random + Access Range. The old behavior is provided as boost::distance()
    • range_size<T>::type has been completely removed in favor of range_difference<T>::type