| 
									
										
										
										
											2004-07-26 00:32:12 +00:00
										 |  |  | // Copyright David Abrahams 2003.
 | 
					
						
							|  |  |  | // 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)
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  | #include <boost/iterator/iterator_adaptor.hpp>
 | 
					
						
							| 
									
										
										
										
											2003-11-22 01:18:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  | #include "static_assert_same.hpp"
 | 
					
						
							| 
									
										
										
										
											2003-11-22 01:18:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  | #include <iterator>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:17:36 +03:00
										 |  |  | #include <type_traits>
 | 
					
						
							| 
									
										
										
										
											2014-07-19 21:39:49 +04:00
										 |  |  | #include <boost/iterator/minimum_category.hpp>
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  | struct input_output_iterator_tag : | 
					
						
							|  |  |  |     public std::input_iterator_tag | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Using inheritance for only input_iterator_tag helps to avoid
 | 
					
						
							|  |  |  |     // ambiguities when a stdlib implementation dispatches on a
 | 
					
						
							|  |  |  |     // function which is overloaded on both input_iterator_tag and
 | 
					
						
							|  |  |  |     // output_iterator_tag, as STLPort does, in its __valid_range
 | 
					
						
							|  |  |  |     // function.  I claim it's better to avoid the ambiguity in these
 | 
					
						
							|  |  |  |     // cases.
 | 
					
						
							|  |  |  |     operator std::output_iterator_tag() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return std::output_iterator_tag(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  | struct X { int a; }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct Xiter : boost::iterator_adaptor<Xiter,X*> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Xiter(); | 
					
						
							|  |  |  |     Xiter(X* p) : boost::iterator_adaptor<Xiter, X*>(p) {} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void take_xptr(X*) {} | 
					
						
							|  |  |  | void operator_arrow_test() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // check that the operator-> result is a pointer for lvalue iterators
 | 
					
						
							|  |  |  |     X x; | 
					
						
							|  |  |  |     take_xptr(Xiter(&x).operator->()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <class T, class U, class Min> | 
					
						
							|  |  |  | struct static_assert_min_cat | 
					
						
							|  |  |  |   : static_assert_same< | 
					
						
							| 
									
										
										
										
											2014-07-19 21:39:49 +04:00
										 |  |  |        typename boost::iterators::minimum_category<T,U>::type, Min | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     > | 
					
						
							|  |  |  | {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void category_test() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-03 00:22:45 +04:00
										 |  |  |     using namespace boost::iterators; | 
					
						
							|  |  |  |     using namespace boost::iterators::detail; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:17:36 +03:00
										 |  |  |     static_assert( | 
					
						
							|  |  |  |         !std::is_convertible<std::input_iterator_tag, input_output_iterator_tag>::value, | 
					
						
							|  |  |  |         "std::input_iterator_tag is not expected to be convertible to input_output_iterator_tag."); | 
					
						
							| 
									
										
										
										
											2014-07-03 00:22:45 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:17:36 +03:00
										 |  |  |     static_assert( | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  |         !std::is_convertible<std::output_iterator_tag, input_output_iterator_tag>::value, | 
					
						
							| 
									
										
										
										
											2025-01-26 15:17:36 +03:00
										 |  |  |         "std::output_iterator_tag is not expected to be convertible to input_output_iterator_tag."); | 
					
						
							| 
									
										
										
										
											2014-07-03 00:22:45 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:17:36 +03:00
										 |  |  |     static_assert( | 
					
						
							|  |  |  |         std::is_convertible<input_output_iterator_tag, std::input_iterator_tag>::value, | 
					
						
							|  |  |  |         "input_output_iterator_tag is expected to be convertible to std::input_iterator_tag."); | 
					
						
							| 
									
										
										
										
											2014-07-03 00:22:45 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:17:36 +03:00
										 |  |  |     static_assert( | 
					
						
							|  |  |  |         std::is_convertible<input_output_iterator_tag, std::output_iterator_tag>::value, | 
					
						
							|  |  |  |         "input_output_iterator_tag is expected to be convertible to std::output_iterator_tag."); | 
					
						
							| 
									
										
										
										
											2003-11-22 01:18:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if 0 // This seems wrong; we're not advertising
 | 
					
						
							|  |  |  |       // input_output_iterator_tag are we?
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:17:36 +03:00
										 |  |  |     static_assert( | 
					
						
							| 
									
										
										
										
											2003-11-22 01:18:37 +00:00
										 |  |  |         boost::is_convertible< | 
					
						
							|  |  |  |             std::forward_iterator_tag | 
					
						
							| 
									
										
										
										
											2025-01-26 15:17:36 +03:00
										 |  |  |           , input_output_iterator_tag | 
					
						
							|  |  |  |         >::value, | 
					
						
							|  |  |  |         ""); | 
					
						
							| 
									
										
										
										
											2014-07-03 00:22:45 +04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     int test = static_assert_min_cat< | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  |         std::input_iterator_tag, input_output_iterator_tag, std::input_iterator_tag | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     >::value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test = static_assert_min_cat< | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  |         input_output_iterator_tag, std::input_iterator_tag, std::input_iterator_tag | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     >::value; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-22 01:18:37 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     test = static_assert_min_cat< | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  |         input_output_iterator_tag, std::forward_iterator_tag, input_output_iterator_tag | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     >::value; | 
					
						
							| 
									
										
										
										
											2014-07-03 00:22:45 +04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     test = static_assert_min_cat< | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  |         std::input_iterator_tag, std::forward_iterator_tag, std::input_iterator_tag | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     >::value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test = static_assert_min_cat< | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  |         std::input_iterator_tag, std::random_access_iterator_tag, std::input_iterator_tag | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     >::value; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-22 01:18:37 +00:00
										 |  |  | #if 0  // This would be wrong: a random access iterator is not
 | 
					
						
							|  |  |  |        // neccessarily writable, as is an output iterator.
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     test = static_assert_min_cat< | 
					
						
							| 
									
										
										
										
											2025-01-29 02:34:45 +03:00
										 |  |  |         std::output_iterator_tag, std::random_access_iterator_tag, std::output_iterator_tag | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     >::value; | 
					
						
							| 
									
										
										
										
											2014-07-03 00:22:45 +04:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-07 14:26:16 +00:00
										 |  |  |     (void)test; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     category_test(); | 
					
						
							|  |  |  |     operator_arrow_test(); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } |