From a33d5c22c593af87a481a13390f28c5caa70a571 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 25 Nov 2007 18:38:02 +0000 Subject: [PATCH] Full merge from trunk at revision 41356 of entire boost-root tree. [SVN r41370] --- doc/Jamfile.v2 | 22 + doc/boost_range.html | 1266 +++++++++++++++++----------------- doc/boost_range.qbk | 1234 +++++++++++++++++++++++++++++++++ doc/example.cpp | 7 - doc/examples.html | 6 +- doc/faq.html | 2 +- doc/headers.html | 59 +- doc/history_ack.html | 2 +- doc/intro.html | 30 +- doc/mfc_atl.html | 581 ++++++++++++++++ doc/mfc_atl.rst | 232 +++++++ doc/portability.html | 4 +- doc/range.html | 211 +----- doc/style.css | 7 - doc/style.html | 2 +- doc/utility_class.html | 73 +- index.html | 10 +- test/TODO | 1 + test/algorithm_example.cpp | 13 +- test/array.cpp | 10 +- test/atl.cpp | 623 +++++++++++++++++ test/compat1.cpp | 0 test/extension_mechanism.cpp | 15 +- test/iterator_pair.cpp | 19 +- test/iterator_range.cpp | 26 +- test/mfc.cpp | 787 +++++++++++++++++++-- test/partial_workaround.cpp | 7 +- test/reversible_range.cpp | 31 +- test/std_container.cpp | 12 +- test/string.cpp | 146 ++-- test/sub_range.cpp | 33 +- 31 files changed, 4352 insertions(+), 1119 deletions(-) create mode 100644 doc/Jamfile.v2 create mode 100644 doc/boost_range.qbk create mode 100644 doc/mfc_atl.html create mode 100644 doc/mfc_atl.rst create mode 100644 test/TODO create mode 100644 test/atl.cpp create mode 100755 test/compat1.cpp diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 new file mode 100644 index 0000000..0fafdd7 --- /dev/null +++ b/doc/Jamfile.v2 @@ -0,0 +1,22 @@ + +use-project boost : $(BOOST_ROOT) ; + + +import boostbook : boostbook ; +import quickbook ; + +xml boost_range : boost_range.qbk ; + +boostbook standalone + : + boost_range + : + 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 16ef3f3..ace1901 100644 --- a/doc/boost_range.html +++ b/doc/boost_range.html @@ -1,86 +1,87 @@ - - 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_reference;
+
+    template< class T >
+    struct range_pointer;
     
+    template< class T >
+    struct range_category;
+
     //
     // Forward Range metafunctions
     //
@@ -89,10 +90,6 @@ class=identifier>range_const_iterator;
     struct range_difference;
     
-    template< class T >
-    struct range_size;
-    
     //
     // Bidirectional Range metafunctions
     //
@@ -101,56 +98,38 @@ class=identifier>range_size;
     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<T>::type
-    begin( T& c );
+    begin( T& r );
     
     template< class T >
-    typename range_const_iterator<T>::type
-    begin( const T& c );
+    typename range_iterator<const T>::type
+    begin( const T& r );
         
     template< class T >
     typename range_iterator<T>::type
-    end( T& c );
+    end( T& r );
                       
     template< class T >
-    typename range_const_iterator<T>::type
-    end( const T& c );
+    typename range_iterator<const T>::type
+    end( const T& r );
     
     template< class T >
     bool
-    empty( const T& c );
+    empty( const T& r );
                
     //
     // Forward Range functions
     //
     
     template< class T >
-    typename range_size<T>::type
-    size( const T& c );
+    typename range_difference<T>::type
+    distance( const T& r );
                             
     //
     // Bidirectional Range functions
@@ -158,546 +137,585 @@ class=identifier>range_reverse_result_iterator;
                      
     template< class T >
     typename range_reverse_iterator<T>::type
-    rbegin( T& c );
+    rbegin( T& r );
     
     template< class T >
-    typename range_const_reverse_iterator<T>::type
-    rbegin( const T& c );
+    typename range_reverse_iterator<const T>::type
+    rbegin( const T& r );
         
     template< class T >
     typename range_reverse_iterator<T>::type
-    rend( T& c );
+    rend( T& r );
                       
     template< class T >
-    typename range_const_reverse_iterator<T>::type
+    typename range_reverse_iterator<const T>::type
     rend( const T& c );
+class=identifier>T& r );
     
+    //
+    // Random Access Range functions
+    //
+    
+    template< class T >
+    typename range_difference<T>::type
+    size( const T& r );
+    
     //
     // Special const Range functions
     // 
     
     template< class T >
-    typename range_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 );
 
+    //
+    // String utilities
+    //
+    
+    template< class T >
+    iterator_range<...see below...> 
+    as_literal( T& r );
+
+    template< class T >
+    iterator_range<...see below...> 
+    as_literal( const T& r );
+
+    template< class T >
+    iterator_range< typename range_iterator<T>::type > 
+    as_array( T& r );
+
+    template< class T >
+    iterator_range< typename range_iterator<const T>::type > 
+    as_array( const T& r );
+
 } // namespace 'boost' 
 
 
-

- -

Semantics

-

notation

-

- - - - - - - - - - - - - - - - -
- Type - - Object - - Describes -
X - x - any type
T - t - denotes behavior of the primary templates
P - p - denotes std::pair<iterator,iterator>
A[sz] - a - denotes an array of type A of size sz -
Char* - s - denotes either char* or wchar_t*
-

-

- Please notice in tables below that when four lines appear in a cell, the first - line will describe the primary template, the second line pairs of iterators, - the third line arrays and the last line null-terminated strings. -

-

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

-

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

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

-

-

- 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_iterator<X>::typeT::iterator
+ P::first_type
+ A*
+ +
compile time
range_iterator<const X>::typeT::const_iterator
+ P::first_type
+ const A*
+ +
compile time
range_value<X>::typeboost::iterator_value<range_iterator<X>::type>::type + compile time
range_reference<X>::typeboost::iterator_reference<range_iterator<X>::type>::type + compile time
range_pointer<X>::typeboost::iterator_pointer<range_iterator<X>::type>::type + compile time
range_category<X>::typeboost::iterator_category<range_iterator<X>::type>::type + compile time
range_difference<X>::type + boost::iterator_difference<range_iterator<X>::type>::typecompile time
range_reverse_iterator<X>::typeboost::reverse_iterator<range_iterator<X>::type>
+
compile time
range_reverse_iterator<const X>::typeboost::reverse_iterator<range_iterator<const X>::type> +
+
compile time
+

+

Functions

+

+ + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ Expression + Return type + Returns + Complexity
begin(x)range_iterator<X>::type + 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 -
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_iterator<X>::type + p.second if p is of type std::pair<T>
+ 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 + +
+ constant time
empty(x)boolboost::begin(x) == boost::end(x)
+
constant time
+
distance(x)range_difference<X>::type + + std::distance(boost::begin(x),boost::end(x)) + + -
- - - - - - - - - - - - - - - -
- 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

+ + + size(x) + range_difference<X>::type + boost::end(x) - boost::begin(x) + + constant time + + + + rbegin(x) + range_reverse_iterator<X>::type + range_reverse_iterator<X>::type( boost::end(x) ) +
+ constant time + + + + + rend(x) + range_reverse_iterator<X>::type + range_reverse_iterator<X>::type( boost::begin(x) ) + constant time + + + + const_begin(x) + range_iterator<const X>::type + range_iterator<const X>::type( boost::begin(x) ) +
+ constant time + + + + + const_end(x) + range_iterator<const X>::type + 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( boost::rbegin(x) ) +
+ constant time + + + + + const_rend(x) + range_reverse_iterator<const X>::type + 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 -

- 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: -

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

+
+ +

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
+

+

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

+

+ 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
range_begin(x)Single Pass Range
range_end(x) + Single Pass Range
+

+

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

+ +

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

+

+ + + + + + + + + + + + + +
+ Metafunction + Related concept
boost::range_mutable_iteratorSingle Pass Range
boost::range_const_iteratorSingle Pass Range
+

+

+ A complete example is given here: +

+
+
 #include <boost/range.hpp>
 #include <iterator>         // for std::iterator_traits, std::distance()
 
 namespace Foo
 {
-	//
-	// Our sample UDT. A 'Pair'
-	// will work as a range when the stored
-	// elements are iterators.
-	//
-	template< class T >
-	struct Pair
-	{
-		T first, last;	
-	};
+    //
+    // 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_mutable_iterator< Foo::Pair<T> >
+    {
+        typedef T type;
+    };
 
-	template< class T >
-	struct range_const_iterator< Foo::Pair<T> >
-	{
-		//
-		// Remark: this is defined similar to 'range_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;
-	};
+    template< class T >
+    struct range_const_iterator< Foo::Pair<T> >
+    {
+        //
+        // Remark: this is defined similar to 'range_mutable_iterator'
+        //         because the 'Pair' type does not distinguish
+        //         between an iterator and a const_iterator.
+        //
+        typedef T type;
+    };
 
 } // namespace 'boost'
 
 namespace Foo
 {
-	//
-	// The required functions. These should be defined in
-	// the same namespace as 'Pair', in this case 
-	// in namespace 'Foo'.
-	//
-	
-	template< class T >
-	inline T 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 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 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 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 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 T range_end( const Pair<T>& x )
+    { 
+        return x.last;
+    }
 
 } // namespace 'Foo'
 
@@ -705,41 +723,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_difference< Foo::Pair<iter> >::type s = boost::size( pair );
+    s      = boost::size( cpair );
+    boost::range_reverse_iterator< const Foo::Pair<iter> >::type
+    ri     = boost::rbegin( cpair ),
+    re     = boost::rend( cpair );
+}    
 
- -
-

- (C) Copyright Thorsten Ottosen 2003-2004. Use, modification and distribution is subject to the Boost Software License, Version 1.0. -

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

+ (C) Copyright Thorsten Ottosen 2003-2007 +

+
+
+
+
+
+
+
+
+
+
+
+
+ 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 diff --git a/doc/example.cpp b/doc/example.cpp index a45bbcc..afe448f 100644 --- a/doc/example.cpp +++ b/doc/example.cpp @@ -1,10 +1,3 @@ -/* -// Copyright Thorsten Ottosen 2003-2005. 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) -*/ - #include #include // for std::iterator_traits, std::distance() diff --git a/doc/examples.html b/doc/examples.html index b0e4973..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 @@ -47,7 +43,7 @@

    - (C) Copyright Thorsten Ottosen 2003-2004. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + (C) Copyright Thorsten Ottosen 2003-2004


    diff --git a/doc/faq.html b/doc/faq.html index 614725a..34304ef 100755 --- a/doc/faq.html +++ b/doc/faq.html @@ -116,7 +116,7 @@ Cool indeed!

    - (C) Copyright Thorsten Ottosen 2003-2004. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + (C) Copyright Thorsten Ottosen 2003-2004


    diff --git a/doc/headers.html b/doc/headers.html index 4d320a1..69987ce 100755 --- a/doc/headers.html +++ b/doc/headers.html @@ -50,6 +50,12 @@ >range_iterator Single Pass Range + + <boost/range/mutable_iterator.hpp> + range_mutable_iterator + Single Pass Range + <boost/range/const_iterator.hpp> Forward Range - <boost/range/size_type.hpp> - 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> @@ -109,10 +107,16 @@ 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 +134,21 @@ Bidirectional Range + + <boost/range/as_array.hpp> + + as_array + + - + + + <boost/range/as_literal.hpp> + + as_literal + + - + + <boost/range/iterator_range.hpp>

    - (C) Copyright Thorsten Ottosen 2003-2004. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + (C) Copyright Thorsten Ottosen 2003-2007


    diff --git a/doc/history_ack.html b/doc/history_ack.html index ec3d887..40ee5dc 100755 --- a/doc/history_ack.html +++ b/doc/history_ack.html @@ -61,7 +61,7 @@ C++ standard:

    - (C) Copyright Thorsten Ottosen 2003-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + (C) Copyright Thorsten Ottosen 2003-2006


    diff --git a/doc/intro.html b/doc/intro.html index a2a6701..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. @@ -60,22 +58,14 @@ free-standing functions so syntactic and/or semantic differences can be removed. 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
  • -
  • - 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 +79,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 +90,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 +136,7 @@ Notice that we have to
     
         

    - (C) Copyright Thorsten Ottosen 2003-2004. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + (C) Copyright Thorsten Ottosen 2003-2007


    diff --git a/doc/mfc_atl.html b/doc/mfc_atl.html new file mode 100644 index 0000000..a022fe3 --- /dev/null +++ b/doc/mfc_atl.html @@ -0,0 +1,581 @@ + + + + + + +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..67498fb --- /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: ../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 2461222..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. @@ -75,7 +75,7 @@ href="http://boost.sourceforge.net/regression-logs/developer/range.html">here

    - (C) Copyright Thorsten Ottosen 2003-2004. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + (C) Copyright Thorsten Ottosen 2003-2004


    diff --git a/doc/range.html b/doc/range.html index 0fe4c88..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,8 +376,8 @@ href="../../iterator/doc/new-iter-concepts.html#random-access-traversal-iterator Jeremy Siek - Copyright © 2004 - Thorsten Ottosen. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + Copyright © 2004-2007 + Thorsten Ottosen.
    diff --git a/doc/style.css b/doc/style.css index 227040a..1890b52 100755 --- a/doc/style.css +++ b/doc/style.css @@ -1,10 +1,3 @@ -/* -#// Copyright Thorsten Ottosen 2003-2005. 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) -*/ - pre{ BORDER-RIGHT: gray 1pt solid; PADDING-RIGHT: 2pt; diff --git a/doc/style.html b/doc/style.html index 76a63f1..9a5617e 100755 --- a/doc/style.html +++ b/doc/style.html @@ -104,7 +104,7 @@

    - (C) Copyright Thorsten Ottosen 2003-2004. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + (C) Copyright Thorsten Ottosen 2003-2004


    diff --git a/doc/utility_class.html b/doc/utility_class.html index 6dfa78b..f7b5535 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,12 +79,10 @@ 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; - + 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 ); @@ -105,22 +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; - value_type& front() const; - value_type& 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; + reference operator[]( difference_type at ) const; + value_type operator()( difference_type at ) const; }; // stream output @@ -173,11 +170,11 @@ class=keyword>const; ForwardTraversalIterator End ); template< class ForwardRange > - iterator_range< typename iterator_of<ForwardRange>::type > + iterator_range< typename range_iterator<ForwardRange>::type > make_iterator_range( ForwardRange& r ); template< class ForwardRange > - iterator_range< typename const_iterator_of<ForwardRange>::type > + iterator_range< typename range_iterator<const ForwardRange>::type > make_iterator_range( const ForwardRange& r ); template< class Range > @@ -187,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 ); @@ -291,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 ); @@ -305,7 +304,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 ); @@ -325,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 @@ -344,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. Use, modification and distribution is subject to the Boost Software License, Version 1.0. + (C) Copyright Thorsten Ottosen 2003-2007


    diff --git a/index.html b/index.html index 05a90d3..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 @@ -51,17 +51,15 @@

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

    - (C) Copyright Thorsten Ottosen 2003-2004 -



    diff --git a/test/TODO b/test/TODO new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/TODO @@ -0,0 +1 @@ + diff --git a/test/algorithm_example.cpp b/test/algorithm_example.cpp index cd6e0e0..85e2b22 100755 --- a/test/algorithm_example.cpp +++ b/test/algorithm_example.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -36,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 ); @@ -46,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 ); @@ -63,19 +64,15 @@ 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 ); - char str_val[] = "a string"; - char* str = str_val; - - 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 ); - BOOST_CHECK_EQUAL( my_generic_replace( str, 'a', 'b' ), 0u ); } diff --git a/test/array.cpp b/test/array.cpp index d2f00b0..b438dce 100755 --- a/test/array.cpp +++ b/test/array.cpp @@ -42,16 +42,16 @@ void check_array() BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, const int* >::value )); BOOST_STATIC_ASSERT(( is_same< range_difference::type, std::ptrdiff_t >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, int* >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const int* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, int* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const int* >::value )); BOOST_STATIC_ASSERT(( is_same< range_value::type, const int >::value )); BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const int* >::value )); BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, const int* >::value )); BOOST_STATIC_ASSERT(( is_same< range_difference::type, std::ptrdiff_t >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const int* >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const int* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const int* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const int* >::value )); #endif BOOST_CHECK_EQUAL( begin( my_array ), my_array ); @@ -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), 3 ); } using boost::unit_test::test_suite; 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/compat1.cpp b/test/compat1.cpp new file mode 100755 index 0000000..e69de29 diff --git a/test/extension_mechanism.cpp b/test/extension_mechanism.cpp index d355e4e..a206afb 100755 --- a/test/extension_mechanism.cpp +++ b/test/extension_mechanism.cpp @@ -25,7 +25,7 @@ // Generic range algorithm // template< class Rng > -typename boost::range_result_iterator::type foo_algo( Rng& r ) +typename boost::range_iterator::type foo_algo( Rng& r ) { // // This will only compile for Rng = UDT if the qualified calls @@ -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; @@ -57,32 +56,28 @@ 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(); } - inline X::size_type boost_range_size( const X& x ) - { - return x.vec.size(); - } } void check_extension() diff --git a/test/iterator_pair.cpp b/test/iterator_pair.cpp index 74358ef..2546817 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 @@ -46,33 +47,35 @@ void check_iterator_pair() BOOST_STATIC_ASSERT(( is_same< range_difference::type, detail::iterator_traits::difference_type >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, pair_t::first_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const_pair_t::first_type >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, pair_t::first_type >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const_pair_t::first_type >::value )); BOOST_STATIC_ASSERT(( is_same< range_value::type, detail::iterator_traits::value_type>::value )); BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const_pair_tt::first_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, const_pair_tt::first_type >::value )); + // + // This behavior is not supported with v2. + //BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, const_pair_tt::first_type >::value )); BOOST_STATIC_ASSERT(( is_same< range_difference::type, detail::iterator_traits::difference_type >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const_pair_tt::first_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const_pair_tt::first_type >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const_pair_tt::first_type >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const_pair_tt::first_type >::value )); 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/iterator_range.cpp b/test/iterator_range.cpp index 7e036ab..db531d3 100755 --- a/test/iterator_range.cpp +++ b/test/iterator_range.cpp @@ -8,6 +8,7 @@ // For more information, see http://www.boost.org/libs/range/ // +//#include #include @@ -16,9 +17,9 @@ # pragma warn -8057 // unused argument argc/argv in Boost.Test #endif - #include #include +#include #include #include #include @@ -65,6 +66,12 @@ void check_iterator_range() BOOST_CHECK_EQUAL( distance( r.begin(), r.end() ), distance( begin( r2 ), end( r2 ) ) ); cout << r << r2; + + +#ifndef BOOST_NO_STD_WSTRING + wcout << make_iterator_range( wstring( L"a wide string" ) ) + << make_iterator_range( L"another wide string" ); +#endif string res = copy_range( r ); BOOST_CHECK( equal( res.begin(), res.end(), r.begin() ) ); @@ -73,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 ) ); @@ -88,9 +95,10 @@ 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 == "ello worl" ); + BOOST_CHECK( rrr == as_literal("ello worl") ); rrr = make_iterator_range( rrr, -1, 1 ); BOOST_CHECK( rrr == str ); @@ -121,7 +129,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) template< class Container > int test_iter_range( Container& a_cont ) { - typedef BOOST_DEDUCED_TYPENAME range_result_iterator::type citer_type; + typedef BOOST_DEDUCED_TYPENAME range_iterator::type citer_type; typedef iterator_range riter_type; riter_type a_riter( make_iterator_range( a_cont ) ); a_riter.front(); diff --git a/test/mfc.cpp b/test/mfc.cpp index c429993..7a13e8e 100755 --- a/test/mfc.cpp +++ b/test/mfc.cpp @@ -1,86 +1,743 @@ -// 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; } - - - - - - diff --git a/test/partial_workaround.cpp b/test/partial_workaround.cpp index ba014ae..8ac6f66 100755 --- a/test/partial_workaround.cpp +++ b/test/partial_workaround.cpp @@ -17,18 +17,15 @@ #endif #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +//#define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 1 #include #include #include #include #include -#include -#include -#include -#include -#include +#include #include #include diff --git a/test/reversible_range.cpp b/test/reversible_range.cpp index 26d953a..9dfe8d0 100755 --- a/test/reversible_range.cpp +++ b/test/reversible_range.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -31,7 +32,7 @@ using namespace std; void check_iterator() { - typedef vector vec_t; + typedef vector vec_t; typedef vec_t::iterator iterator; typedef pair pair_t; typedef range_reverse_iterator::type rev_iterator; @@ -40,15 +41,8 @@ void check_iterator() vec_t vec; pair_t p = make_pair( vec.begin(), vec.end() ); rev_pair_t rp = make_pair( rbegin( p ), rend( p ) ); - char* str = "mutable"; - const char* cstr = "not mutable"; - char a[] = "mutable"; - const char ca[] = "not mutable"; - wchar_t* wstr = L"mutable"; - const wchar_t* cwstr= L"not mutable"; - wchar_t wa[] = L"mutable"; - const wchar_t cwa[]= L"not mutable"; - + int a[] = {1,2,3,4,5,6,7,8,9,10}; + const int ca[] = {1,2,3,4,5,6,7,8,9,10,11,12}; BOOST_CHECK( rbegin( vec ) == range_reverse_iterator::type( vec.end() ) ); BOOST_CHECK( rend( vec ) == range_reverse_iterator::type( vec.begin() ) ); BOOST_CHECK( std::distance( rbegin( vec ), rend( vec ) ) == std::distance( begin( vec ), end( vec ) ) ); @@ -58,33 +52,16 @@ void check_iterator() BOOST_CHECK( std::distance( rbegin( p ), rend( p ) ) == std::distance( begin( rp ), end( rp ) ) ); BOOST_CHECK( std::distance( begin( p ), end( p ) ) == std::distance( rbegin( rp ), rend( rp ) ) ); - BOOST_CHECK_EQUAL( &*begin( str ), &*( rend( str ) - 1 ) ); - BOOST_CHECK_EQUAL( &*( end( str ) - 1 ), &*rbegin( str ) ); - BOOST_CHECK_EQUAL( &*begin( cstr ), &*( rend( cstr ) - 1 ) ); - BOOST_CHECK_EQUAL( &*( end( cstr ) - 1 ), &*rbegin( cstr ) ); BOOST_CHECK_EQUAL( &*begin( a ), &*( rend( a ) - 1 ) ); BOOST_CHECK_EQUAL( &*( end( a ) - 1 ), &*rbegin( a ) ); BOOST_CHECK_EQUAL( &*begin( ca ), &*( rend( ca ) - 1 ) ); BOOST_CHECK_EQUAL( &*( end( ca ) - 1 ), &*rbegin( ca ) ); - - BOOST_CHECK_EQUAL( &*begin( wstr ), &*( rend( wstr ) - 1 ) ); - BOOST_CHECK_EQUAL( &*( end( wstr ) - 1 ), &*rbegin( wstr ) ); - BOOST_CHECK_EQUAL( &*begin( cwstr ), &*( rend( cwstr ) - 1 ) ); - BOOST_CHECK_EQUAL( &*( end( cwstr ) - 1 ), &*rbegin( cwstr ) ); - - BOOST_CHECK_EQUAL( &*begin( wa ), &*( rend( wa ) - 1 ) ); - BOOST_CHECK_EQUAL( &*( end( wa ) - 1 ), &*rbegin( wa ) ); - BOOST_CHECK_EQUAL( &*begin( cwa ), &*( rend( cwa ) - 1 ) ); - BOOST_CHECK_EQUAL( &*( end( cwa ) - 1 ), &*rbegin( cwa ) ); - } -#include using boost::unit_test::test_suite; - test_suite* init_unit_test_suite( int argc, char* argv[] ) { test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); diff --git a/test/std_container.cpp b/test/std_container.cpp index a61e8d1..e2ee692 100755 --- a/test/std_container.cpp +++ b/test/std_container.cpp @@ -35,27 +35,25 @@ void check_std_container() BOOST_STATIC_ASSERT(( is_same< range_value::type, vec_t::value_type >::value )); BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::iterator >::value )); - BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, vec_t::const_iterator >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::const_iterator >::value )); BOOST_STATIC_ASSERT(( is_same< range_difference::type, vec_t::difference_type >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, vec_t::size_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, vec_t::iterator >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, vec_t::const_iterator >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::iterator >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::const_iterator >::value )); BOOST_STATIC_ASSERT(( is_same< range_value::type, vec_t::value_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::iterator >::value )); - BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, vec_t::const_iterator >::value )); BOOST_STATIC_ASSERT(( is_same< range_difference::type, vec_t::difference_type >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, vec_t::size_type >::value )); 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() ); } diff --git a/test/string.cpp b/test/string.cpp index 36f103b..9a2e5a8 100755 --- a/test/string.cpp +++ b/test/string.cpp @@ -17,7 +17,10 @@ # pragma warn -8057 // unused argument argc/argv in Boost.Test #endif -#include +#include +#include +#include +#include #include #include #include @@ -26,36 +29,66 @@ #include #include +template< class T > +inline BOOST_DEDUCED_TYPENAME boost::range_iterator::type +str_begin( T& 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( boost::as_literal(r) ); +} + +template< class T > +inline BOOST_DEDUCED_TYPENAME boost::range_size::type +str_size( const T& r ) +{ + return boost::size( boost::as_literal(r) ); +} + +template< class T > +inline bool +str_empty( T& r ) +{ + return boost::empty( boost::as_literal(r) ); +} + template< typename Container, typename T > BOOST_DEDUCED_TYPENAME boost::range_iterator::type find( Container& c, T value ) { - return std::find( boost::begin( c ), boost::end( c ), value ); + return std::find( str_begin(c), str_end(c), + value ); } template< typename Container, typename T > -BOOST_DEDUCED_TYPENAME boost::range_const_iterator::type +BOOST_DEDUCED_TYPENAME boost::range_iterator::type find( const Container& c, T value ) { - return std::find( boost::begin( c ), boost::end( c ), value ); + return std::find( str_begin(c), str_end(c), + value ); } template< typename Container, typename T > BOOST_DEDUCED_TYPENAME boost::range_iterator::type find_mutable( Container& c, T value ) -{ - boost::size( c ); - boost::end( c ); - return std::find( boost::begin( c ), boost::end( c ), value ); +{ + str_size( c ); + return std::find( str_begin(c), str_end(c), + value ); } template< typename Container, typename T > -BOOST_DEDUCED_TYPENAME boost::range_const_iterator::type +BOOST_DEDUCED_TYPENAME boost::range_iterator::type find_const( const Container& c, T value ) { - boost::size( c ); - boost::end( c ); - return std::find( boost::begin( c ), boost::end( c ), value ); + str_size( c ); + return std::find( str_begin(c), str_end(c), + value ); } @@ -72,62 +105,66 @@ void check_char() { typedef char* char_iterator_t; typedef char char_array_t[10]; - const char* char_s = "a string"; - char my_string[] = "another string"; - const unsigned my_string_length = 14; - char* char_s2 = "a string"; + const char* char_s = "a string"; + char my_string[] = "another string"; + const char my_const_string[] = "another string"; + const unsigned my_string_length = 14; + char* char_s2 = "a string"; BOOST_STATIC_ASSERT(( is_same< range_value::type, detail::iterator_traits::value_type>::value )); BOOST_STATIC_ASSERT(( is_same< range_iterator::type, char_iterator_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, const char* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_difference::type, ::std::ptrdiff_t >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, char_iterator_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const char* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, char_iterator_t >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const char* >::value )); BOOST_STATIC_ASSERT(( is_same< range_value::type, char>::value )); BOOST_STATIC_ASSERT(( is_same< range_iterator::type, char* >::value )); - BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, const char* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const char* >::value )); BOOST_STATIC_ASSERT(( is_same< range_difference::type, ::std::ptrdiff_t >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, char* >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const char* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, char* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const char* >::value )); - BOOST_CHECK_EQUAL( begin( char_s ), char_s ); - std::size_t sz = size( char_s ); - const char* end1 = begin( char_s ) + sz; - BOOST_CHECK_EQUAL( end( char_s ), end1 ); - BOOST_CHECK_EQUAL( empty( char_s ), (char_s == 0 || char_s[0] == char()) ); + BOOST_CHECK_EQUAL( str_begin( char_s ), char_s ); + std::size_t sz = str_size(char_s); + const char* str_end1 = str_begin( char_s ) + sz; + 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( begin( char_s2 ), char_s2 ); + BOOST_CHECK_EQUAL( str_begin( char_s2 ), char_s2 ); std::size_t sz2 = size( char_s2 ); - const char* end12 = begin( char_s2 ) + sz; - BOOST_CHECK_EQUAL( end( char_s2 ), end12 ); + 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( begin( my_string ), my_string ); - range_iterator::type end2 = begin( my_string ) + size( my_string ); - range_iterator::type end3 = end( my_string ); - BOOST_CHECK_EQUAL( end3, end2 ); - BOOST_CHECK_EQUAL( empty( my_string ), (my_string == 0 || my_string[0] == char()) ); - BOOST_CHECK_EQUAL( size( my_string ), my_string_length ); - BOOST_CHECK_EQUAL( size( my_string ), std::char_traits::length( my_string ) ); + 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); + BOOST_CHECK_EQUAL( str_end3, str_end2 ); + BOOST_CHECK_EQUAL( str_empty( my_string ), (my_string == 0 || my_string[0] == char()) ); + BOOST_CHECK_EQUAL( str_size( my_string ), my_string_length ); + BOOST_CHECK_EQUAL( str_size( my_string ), std::char_traits::length( my_string ) ); char to_search = 'n'; - BOOST_CHECK( find_mutable( char_s, to_search ) != end( char_s ) ); - BOOST_CHECK( find_const( char_s, to_search ) != end( char_s ) ); + BOOST_CHECK( find_mutable( char_s, to_search ) != str_end( char_s ) ); + BOOST_CHECK( find_const( char_s, to_search ) != str_end(char_s) ); - BOOST_CHECK( find_mutable( my_string, to_search ) != end( my_string ) ); - BOOST_CHECK( find_const( my_string, to_search ) != end( my_string ) ); + BOOST_CHECK( find_mutable( my_string, to_search ) != str_end(my_string) ); + BOOST_CHECK( find_const( my_string, to_search ) != str_end(my_string) ); - BOOST_CHECK( find_mutable( char_s2, to_search ) != end( char_s2 ) ); - BOOST_CHECK( find_const( char_s2, to_search ) != end( char_s2 ) ); + BOOST_CHECK( find_mutable( char_s2, to_search ) != str_end(char_s) ); + BOOST_CHECK( find_const( char_s2, to_search ) != str_end(char_s2) ); + + 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) ); } @@ -148,31 +185,31 @@ void check_string() BOOST_STATIC_ASSERT(( is_same< range_value::type, detail::iterator_traits::value_type>::value )); BOOST_STATIC_ASSERT(( is_same< range_iterator::type, wchar_iterator_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, const wchar_t* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const wchar_t* >::value )); BOOST_STATIC_ASSERT(( is_same< range_difference::type, detail::iterator_traits::difference_type >::value )); BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, wchar_iterator_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_result_iterator::type, const wchar_t* >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, wchar_iterator_t >::value )); + BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const wchar_t* >::value )); - std::size_t sz = size( char_ws ); - BOOST_CHECK_EQUAL( begin( char_ws ), char_ws ); - BOOST_CHECK_EQUAL( end( char_ws ), (begin( char_ws ) + sz) ); - BOOST_CHECK_EQUAL( empty( char_ws ), (char_ws == 0 || char_ws[0] == wchar_t()) ); + std::size_t sz = str_size( char_ws ); + BOOST_CHECK_EQUAL( str_begin( char_ws ), char_ws ); + 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( begin( char_ws2 ), char_ws2 ); - BOOST_CHECK_EQUAL( end( char_ws2 ), (begin( char_ws2 ) + sz2) ); + 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 ) != end( char_ws ) ); + BOOST_CHECK( find( char_ws, to_search ) != str_end(char_ws) ); #if BOOST_WORKAROUND(_MSC_VER, BOOST_TESTED_AT(1300)) - BOOST_CHECK( find( my_wstring, to_search ) != end( my_wstring ) ); + BOOST_CHECK( find( my_wstring, to_search ) != str_end(my_wstring) ); #endif #endif @@ -181,7 +218,6 @@ void check_string() } - #include using boost::unit_test::test_suite; diff --git a/test/sub_range.cpp b/test/sub_range.cpp index f590b53..7d5bf05 100755 --- a/test/sub_range.cpp +++ b/test/sub_range.cpp @@ -17,6 +17,7 @@ #endif #include +#include #include #include #include @@ -91,16 +92,31 @@ void check_sub_range() r.size(); s.size(); + // + // As of range v2 not legal anymore. + // + //irange singular_irange; + //BOOST_CHECK( singular_irange.empty() ); + //BOOST_CHECK( singular_irange.size() == 0 ); + // + //srange singular_srange; + //BOOST_CHECK( singular_srange.empty() ); + //BOOST_CHECK( singular_srange.size() == 0 ); + // + //BOOST_CHECK( empty( singular_irange ) ); + //BOOST_CHECK( empty( singular_srange ) ); + // + srange rr = make_iterator_range( str ); 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 ); @@ -111,15 +127,16 @@ 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 == "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