| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  | //  Test boost/iterator_adaptors.hpp
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //  (C) Copyright Jeremy Siek 1999. Permission to copy, use, modify,
 | 
					
						
							|  |  |  | //  sell and distribute this software is granted provided this
 | 
					
						
							|  |  |  | //  copyright notice appears in all copies. This software is provided
 | 
					
						
							|  |  |  | //  "as is" without express or implied warranty, and with no claim as
 | 
					
						
							|  |  |  | //  to its suitability for any purpose.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  See http://www.boost.org for most recent version including documentation.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Revision History
 | 
					
						
							| 
									
										
										
										
											2001-03-08 20:50:14 +00:00
										 |  |  | //  08 Mar 01 Moved indirect and transform tests to separate files.
 | 
					
						
							|  |  |  | //            (Jeremy Siek)
 | 
					
						
							| 
									
										
										
										
											2001-02-19 22:34:31 +00:00
										 |  |  | //  19 Feb 01 Take adavantage of improved iterator_traits to do more tests
 | 
					
						
							|  |  |  | //            on MSVC. Hack around an MSVC-with-STLport internal compiler
 | 
					
						
							|  |  |  | //            error. (David Abrahams)
 | 
					
						
							| 
									
										
										
										
											2001-02-11 19:25:49 +00:00
										 |  |  | //  11 Feb 01 Added test of operator-> for forward and input iterators.
 | 
					
						
							|  |  |  | //            (Jeremy Siek)
 | 
					
						
							| 
									
										
										
										
											2001-02-11 16:16:53 +00:00
										 |  |  | //  11 Feb 01 Borland fixes (David Abrahams)
 | 
					
						
							| 
									
										
										
										
											2001-02-11 03:07:55 +00:00
										 |  |  | //  10 Feb 01 Use new adaptors interface. (David Abrahams)
 | 
					
						
							| 
									
										
										
										
											2001-02-10 20:11:42 +00:00
										 |  |  | //  10 Feb 01 Use new filter_ interface. (David Abrahams)
 | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  | //  09 Feb 01 Use new reverse_ and indirect_ interfaces. Replace
 | 
					
						
							|  |  |  | //            BOOST_NO_STD_ITERATOR_TRAITS with
 | 
					
						
							|  |  |  | //            BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION to prove we've
 | 
					
						
							|  |  |  | //            normalized to core compiler capabilities (David Abrahams)
 | 
					
						
							| 
									
										
										
										
											2001-02-09 03:32:59 +00:00
										 |  |  | //  08 Feb 01 Use Jeremy's new make_reverse_iterator form; add more
 | 
					
						
							|  |  |  | //            comprehensive testing. Force-decay array function arguments to
 | 
					
						
							|  |  |  | //            pointers.
 | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  | //  07 Feb 01 Added tests for the make_xxx_iterator() helper functions.
 | 
					
						
							|  |  |  | //            (Jeremy Siek)
 | 
					
						
							| 
									
										
										
										
											2001-02-07 06:36:12 +00:00
										 |  |  | //  07 Feb 01 Replaced use of xxx_pair_generator with xxx_generator where
 | 
					
						
							|  |  |  | //            possible (which was all but the projection iterator).
 | 
					
						
							|  |  |  | //            (Jeremy Siek)
 | 
					
						
							| 
									
										
										
										
											2001-02-07 05:37:08 +00:00
										 |  |  | //  06 Feb 01 Removed now-defaulted template arguments where possible
 | 
					
						
							|  |  |  | //            Updated names to correspond to new generator naming convention.
 | 
					
						
							|  |  |  | //            Added a trivial test for make_transform_iterator().
 | 
					
						
							|  |  |  | //            Gave traits for const iterators a mutable value_type, per std.
 | 
					
						
							|  |  |  | //            Resurrected my original tests for indirect iterators.
 | 
					
						
							|  |  |  | //            (David Abrahams)
 | 
					
						
							| 
									
										
										
										
											2001-02-04 20:11:30 +00:00
										 |  |  | //  04 Feb 01 Fix for compilers without standard iterator_traits
 | 
					
						
							|  |  |  | //            (David Abrahams)
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  | //  13 Jun 00 Added const version of the iterator tests (Jeremy Siek)
 | 
					
						
							|  |  |  | //  12 Dec 99 Initial version with iterator operators (Jeremy Siek)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-09 20:28:48 +00:00
										 |  |  | #include <boost/config.hpp>
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  | #include <iostream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							|  |  |  | #include <functional>
 | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-04 20:11:30 +00:00
										 |  |  | #include <boost/iterator_adaptors.hpp>
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  | #include <boost/pending/iterator_tests.hpp>
 | 
					
						
							|  |  |  | #include <boost/pending/integer_range.hpp>
 | 
					
						
							| 
									
										
										
										
											2001-02-13 02:03:13 +00:00
										 |  |  | #include <boost/concept_archetype.hpp>
 | 
					
						
							| 
									
										
										
										
											2001-02-07 05:37:08 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <deque>
 | 
					
						
							|  |  |  | #include <set>
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct my_iterator_tag : public std::random_access_iterator_tag { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using boost::dummyT; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  | struct mult_functor { | 
					
						
							|  |  |  |   typedef int result_type; | 
					
						
							|  |  |  |   typedef int argument_type; | 
					
						
							|  |  |  |   // Functors used with transform_iterator must be
 | 
					
						
							|  |  |  |   // DefaultConstructible, as the transform_iterator must be
 | 
					
						
							|  |  |  |   // DefaultConstructible to satisfy the requirements for
 | 
					
						
							|  |  |  |   // TrivialIterator.
 | 
					
						
							|  |  |  |   mult_functor() { } | 
					
						
							|  |  |  |   mult_functor(int aa) : a(aa) { } | 
					
						
							|  |  |  |   int operator()(int b) const { return a * b; } | 
					
						
							|  |  |  |   int a; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-24 20:45:26 +00:00
										 |  |  | template <class Pair> | 
					
						
							|  |  |  | struct select1st_  | 
					
						
							| 
									
										
										
										
											2000-11-24 20:48:02 +00:00
										 |  |  |   : public std::unary_function<Pair, typename Pair::first_type> | 
					
						
							| 
									
										
										
										
											2000-11-24 20:45:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   const typename Pair::first_type& operator()(const Pair& x) const { | 
					
						
							|  |  |  |     return x.first; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   typename Pair::first_type& operator()(Pair& x) const { | 
					
						
							|  |  |  |     return x.first; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 19:10:03 +00:00
										 |  |  | struct one_or_four { | 
					
						
							|  |  |  |   bool operator()(dummyT x) const { | 
					
						
							|  |  |  |     return x.foo() == 1 || x.foo() == 4; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  | typedef std::deque<int> storage; | 
					
						
							| 
									
										
										
										
											2001-02-07 05:37:08 +00:00
										 |  |  | typedef std::deque<int*> pointer_deque; | 
					
						
							|  |  |  | typedef std::set<storage::iterator> iterator_set; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  | int | 
					
						
							|  |  |  | main() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),  | 
					
						
							| 
									
										
										
										
											2000-11-24 20:45:26 +00:00
										 |  |  |                      dummyT(3), dummyT(4), dummyT(5) }; | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |   const int N = sizeof(array)/sizeof(dummyT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // sanity check, if this doesn't pass the test is buggy
 | 
					
						
							|  |  |  |   boost::random_access_iterator_test(array,N,array); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-07 02:44:18 +00:00
										 |  |  |   // Check that the policy concept checks and the default policy
 | 
					
						
							|  |  |  |   // implementation match up.
 | 
					
						
							|  |  |  |   boost::function_requires<  | 
					
						
							|  |  |  |      boost::RandomAccessIteratorPoliciesConcept< | 
					
						
							|  |  |  |        boost::default_iterator_policies, int*, | 
					
						
							|  |  |  |        boost::iterator<std::random_access_iterator_tag, int, std::ptrdiff_t, | 
					
						
							|  |  |  |                       int*, int&> | 
					
						
							|  |  |  |       > >(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-07 06:36:12 +00:00
										 |  |  |   // Test the iterator_adaptor
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  |     boost::iterator_adaptor<dummyT*, boost::default_iterator_policies, dummyT> i(array); | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |     boost::random_access_iterator_test(i, N, array); | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  |     boost::iterator_adaptor<const dummyT*, boost::default_iterator_policies, const dummyT> j(array); | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |     boost::random_access_iterator_test(j, N, array); | 
					
						
							| 
									
										
										
										
											2001-02-07 05:37:08 +00:00
										 |  |  |     boost::const_nonconst_iterator_test(i, ++j); | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-02-11 03:07:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-07 05:37:08 +00:00
										 |  |  |   // Test projection_iterator_pair_generator
 | 
					
						
							| 
									
										
										
										
											2000-11-24 20:45:26 +00:00
										 |  |  |   {     | 
					
						
							|  |  |  |     typedef std::pair<dummyT,dummyT> Pair; | 
					
						
							|  |  |  |     Pair pair_array[N]; | 
					
						
							|  |  |  |     for (int k = 0; k < N; ++k) | 
					
						
							|  |  |  |       pair_array[k].first = array[k]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-07 05:37:08 +00:00
										 |  |  |     typedef boost::projection_iterator_pair_generator<select1st_<Pair>, | 
					
						
							|  |  |  |       Pair*, const Pair* | 
					
						
							| 
									
										
										
										
											2000-11-24 20:45:26 +00:00
										 |  |  |       > Projection; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2001-02-11 03:07:55 +00:00
										 |  |  |     Projection::iterator i(pair_array); | 
					
						
							| 
									
										
										
										
											2000-11-24 20:45:26 +00:00
										 |  |  |     boost::random_access_iterator_test(i, N, array); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  |     boost::random_access_iterator_test(boost::make_projection_iterator(pair_array, select1st_<Pair>()), N, array);     | 
					
						
							| 
									
										
										
										
											2001-02-09 04:40:42 +00:00
										 |  |  |     boost::random_access_iterator_test(boost::make_projection_iterator< select1st_<Pair> >(pair_array), N, array);     | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-17 01:50:40 +00:00
										 |  |  |     Projection::const_iterator j(pair_array); | 
					
						
							| 
									
										
										
										
											2000-11-24 20:48:02 +00:00
										 |  |  |     boost::random_access_iterator_test(j, N, array); | 
					
						
							| 
									
										
										
										
											2000-11-24 20:45:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  |     boost::random_access_iterator_test(boost::make_const_projection_iterator(pair_array, select1st_<Pair>()), N, array); | 
					
						
							| 
									
										
										
										
											2001-02-10 20:11:42 +00:00
										 |  |  |     boost::random_access_iterator_test(boost::make_const_projection_iterator<select1st_<Pair> >(pair_array), N, array); | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-24 20:45:26 +00:00
										 |  |  |     boost::const_nonconst_iterator_test(i, ++j); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-02-11 16:16:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-07 06:36:12 +00:00
										 |  |  |   // Test reverse_iterator_generator
 | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |     dummyT reversed[N]; | 
					
						
							|  |  |  |     std::copy(array, array + N, reversed); | 
					
						
							|  |  |  |     std::reverse(reversed, reversed + N); | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  |     typedef boost::reverse_iterator_generator<dummyT* | 
					
						
							|  |  |  | #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 | 
					
						
							|  |  |  |         , dummyT | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-02-07 06:36:12 +00:00
										 |  |  |       >::type reverse_iterator; | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2001-02-17 01:50:40 +00:00
										 |  |  |     reverse_iterator i(reversed + N); | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |     boost::random_access_iterator_test(i, N, array); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  | #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  |     boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-11 16:16:53 +00:00
										 |  |  |     typedef boost::reverse_iterator_generator<const dummyT* | 
					
						
							|  |  |  | #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 | 
					
						
							|  |  |  |         , const dummyT | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |       >::type const_reverse_iterator; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2001-02-17 01:50:40 +00:00
										 |  |  |     const_reverse_iterator j(reversed + N); | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |     boost::random_access_iterator_test(j, N, array); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  |     const dummyT* const_reversed = reversed; | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  |      | 
					
						
							|  |  |  | #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  |     boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |     boost::const_nonconst_iterator_test(i, ++j);     | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-19 22:34:31 +00:00
										 |  |  |   // Test reverse_iterator_generator again, with traits fully deducible on all platforms
 | 
					
						
							| 
									
										
										
										
											2001-02-09 03:32:59 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |     std::deque<dummyT> reversed_container; | 
					
						
							| 
									
										
										
										
											2001-02-19 22:34:31 +00:00
										 |  |  |     std::reverse_copy(array, array + N, std::back_inserter(reversed_container)); | 
					
						
							| 
									
										
										
										
											2001-02-09 03:32:59 +00:00
										 |  |  |     const std::deque<dummyT>::iterator reversed = reversed_container.begin(); | 
					
						
							| 
									
										
										
										
											2001-02-19 22:34:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-19 20:37:24 +00:00
										 |  |  |     typedef boost::reverse_iterator_generator< | 
					
						
							|  |  |  |         std::deque<dummyT>::iterator>::type reverse_iterator; | 
					
						
							|  |  |  |     typedef boost::reverse_iterator_generator< | 
					
						
							|  |  |  |         std::deque<dummyT>::const_iterator, const dummyT>::type const_reverse_iterator; | 
					
						
							| 
									
										
										
										
											2001-02-09 03:32:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-19 22:34:31 +00:00
										 |  |  |     // MSVC/STLport gives an INTERNAL COMPILER ERROR when any computation
 | 
					
						
							|  |  |  |     // (e.g. "reversed + N") is used in the constructor below.
 | 
					
						
							|  |  |  |     const std::deque<dummyT>::iterator finish = reversed_container.end(); | 
					
						
							|  |  |  |     reverse_iterator i(finish); | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2001-02-09 03:32:59 +00:00
										 |  |  |     boost::random_access_iterator_test(i, N, array); | 
					
						
							|  |  |  |     boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-19 22:34:31 +00:00
										 |  |  |     const_reverse_iterator j = reverse_iterator(finish); | 
					
						
							| 
									
										
										
										
											2001-02-09 03:32:59 +00:00
										 |  |  |     boost::random_access_iterator_test(j, N, array); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const std::deque<dummyT>::const_iterator const_reversed = reversed; | 
					
						
							|  |  |  |     boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array); | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2001-02-19 22:34:31 +00:00
										 |  |  |     // Many compilers' builtin deque iterators don't interoperate well, though
 | 
					
						
							|  |  |  |     // STLport fixes that problem.
 | 
					
						
							|  |  |  | #if defined(__SGI_STL_PORT) || !defined(__GNUC__) && !defined(__BORLANDC__) && !defined(BOOST_MSVC)
 | 
					
						
							| 
									
										
										
										
											2001-02-10 00:38:08 +00:00
										 |  |  |     boost::const_nonconst_iterator_test(i, ++j); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-02-09 03:32:59 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |   // Test integer_range's iterators
 | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     int int_array[] = { 0, 1, 2, 3, 4, 5 }; | 
					
						
							|  |  |  |     boost::integer_range<int> r(0, 5); | 
					
						
							|  |  |  |     boost::random_access_iterator_test(r.begin(), r.size(), int_array); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 19:10:03 +00:00
										 |  |  |   // Test filter iterator
 | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  |     // Using typedefs for filter_gen::type confused Borland terribly.
 | 
					
						
							| 
									
										
										
										
											2001-02-11 16:16:53 +00:00
										 |  |  |     typedef boost::detail::non_bidirectional_category<dummyT*>::type category; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  |     typedef boost::filter_iterator_generator<one_or_four, dummyT* | 
					
						
							| 
									
										
										
										
											2001-02-10 20:11:42 +00:00
										 |  |  | #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 | 
					
						
							|  |  |  |         , dummyT | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  |         >::type filter_iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(__BORLANDC__)
 | 
					
						
							|  |  |  |     // Borland is choking on accessing the policies_type explicitly
 | 
					
						
							|  |  |  |     // from the filter_iter. 
 | 
					
						
							|  |  |  |     boost::forward_iterator_test(make_filter_iterator(array, array+N,  | 
					
						
							|  |  |  | 						      one_or_four()), | 
					
						
							|  |  |  | 				 dummyT(1), dummyT(4)); | 
					
						
							| 
									
										
										
										
											2001-03-04 16:07:11 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2001-02-20 16:01:00 +00:00
										 |  |  |     filter_iter i(array, filter_iter::policies_type(one_or_four(), array + N)); | 
					
						
							| 
									
										
										
										
											2001-02-04 20:11:30 +00:00
										 |  |  |     boost::forward_iterator_test(i, dummyT(1), dummyT(4)); | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-02-08 03:08:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  | #if !defined(__BORLANDC__)
 | 
					
						
							|  |  |  |     // 
 | 
					
						
							| 
									
										
										
										
											2001-02-10 23:16:05 +00:00
										 |  |  |     enum { is_forward = boost::is_same< | 
					
						
							| 
									
										
										
										
											2001-02-20 16:01:00 +00:00
										 |  |  |            filter_iter::iterator_category, | 
					
						
							| 
									
										
										
										
											2001-02-10 23:16:05 +00:00
										 |  |  |            std::forward_iterator_tag>::value }; | 
					
						
							|  |  |  |     BOOST_STATIC_ASSERT(is_forward); | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-02-09 05:26:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-10 20:11:42 +00:00
										 |  |  |     // On compilers not supporting partial specialization, we can do more type
 | 
					
						
							|  |  |  |     // deduction with deque iterators than with pointers... unless the library
 | 
					
						
							|  |  |  |     // is broken ;-(
 | 
					
						
							|  |  |  | #if !defined(BOOST_MSVC) || defined(__SGI_STL_PORT)
 | 
					
						
							|  |  |  |     std::deque<dummyT> array2; | 
					
						
							|  |  |  |     std::copy(array+0, array+N, std::back_inserter(array2)); | 
					
						
							|  |  |  |     boost::forward_iterator_test( | 
					
						
							|  |  |  |         boost::make_filter_iterator(array2.begin(), array2.end(), one_or_four()), | 
					
						
							|  |  |  |         dummyT(1), dummyT(4)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     boost::forward_iterator_test( | 
					
						
							|  |  |  |         boost::make_filter_iterator<one_or_four>(array2.begin(), array2.end()), | 
					
						
							|  |  |  |         dummyT(1), dummyT(4)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-02-09 05:26:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-10 20:11:42 +00:00
										 |  |  | #if !defined(BOOST_MSVC) // This just freaks MSVC out completely
 | 
					
						
							|  |  |  |     boost::forward_iterator_test( | 
					
						
							|  |  |  |         boost::make_filter_iterator<one_or_four>( | 
					
						
							|  |  |  |             boost::make_reverse_iterator(array2.end()), | 
					
						
							|  |  |  |             boost::make_reverse_iterator(array2.begin()) | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |         dummyT(4), dummyT(1)); | 
					
						
							| 
									
										
										
										
											2001-02-08 04:46:41 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-02-09 05:26:48 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2001-02-10 20:11:42 +00:00
										 |  |  | #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 | 
					
						
							|  |  |  |     boost::forward_iterator_test( | 
					
						
							|  |  |  |         boost::make_filter_iterator(array+0, array+N, one_or_four()), | 
					
						
							|  |  |  |         dummyT(1), dummyT(4)); | 
					
						
							| 
									
										
										
										
											2001-02-09 05:26:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-10 20:11:42 +00:00
										 |  |  |     boost::forward_iterator_test( | 
					
						
							|  |  |  |         boost::make_filter_iterator<one_or_four>(array, array + N), | 
					
						
							|  |  |  |         dummyT(1), dummyT(4)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-01-23 19:10:03 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-02-11 19:25:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // check operator-> with a forward iterator
 | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2001-02-13 02:03:13 +00:00
										 |  |  |     boost::forward_iterator_archetype<dummyT> forward_iter; | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  | #if defined(__BORLANDC__)
 | 
					
						
							| 
									
										
										
										
											2001-02-13 02:03:13 +00:00
										 |  |  |     typedef boost::iterator_adaptor<boost::forward_iterator_archetype<dummyT>, | 
					
						
							|  |  |  |       boost::default_iterator_policies, | 
					
						
							|  |  |  |       dummyT, const dummyT&, const dummyT*,  | 
					
						
							|  |  |  |       std::forward_iterator_tag, std::ptrdiff_t> adaptor_type; | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  |     typedef boost::iterator_adaptor<boost::forward_iterator_archetype<dummyT>, | 
					
						
							|  |  |  |       boost::default_iterator_policies, | 
					
						
							|  |  |  |       boost::iterator_traits_generator | 
					
						
							|  |  |  |         ::value_type<dummyT> | 
					
						
							|  |  |  |         ::reference<const dummyT&> | 
					
						
							|  |  |  |         ::pointer<const dummyT*>  | 
					
						
							|  |  |  |         ::iterator_category<std::forward_iterator_tag> | 
					
						
							|  |  |  |         ::difference_type<std::ptrdiff_t> > adaptor_type; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-02-13 02:03:13 +00:00
										 |  |  |     adaptor_type i(forward_iter); | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  |     int zero = 0; | 
					
						
							|  |  |  |     if (zero) // don't do this, just make sure it compiles
 | 
					
						
							| 
									
										
										
										
											2001-02-13 02:03:13 +00:00
										 |  |  |       assert((*i).m_x == i->foo());       | 
					
						
							| 
									
										
										
										
											2001-02-11 19:25:49 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   // check operator-> with an input iterator
 | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2001-02-13 02:03:13 +00:00
										 |  |  |     boost::input_iterator_archetype<dummyT> input_iter; | 
					
						
							|  |  |  |     typedef boost::iterator_adaptor<boost::input_iterator_archetype<dummyT>, | 
					
						
							|  |  |  |       boost::default_iterator_policies, | 
					
						
							|  |  |  |       dummyT, const dummyT&, const dummyT*,  | 
					
						
							|  |  |  |       std::input_iterator_tag, std::ptrdiff_t> adaptor_type; | 
					
						
							| 
									
										
										
										
											2001-02-11 19:25:49 +00:00
										 |  |  |     adaptor_type i(input_iter); | 
					
						
							| 
									
										
										
										
											2001-03-08 20:49:05 +00:00
										 |  |  |     int zero = 0; | 
					
						
							|  |  |  |     if (zero) // don't do this, just make sure it compiles
 | 
					
						
							| 
									
										
										
										
											2001-02-11 19:25:49 +00:00
										 |  |  |       assert((*i).m_x == i->foo());       | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2000-11-07 23:05:04 +00:00
										 |  |  |   std::cout << "test successful " << std::endl; | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } |