| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | #ifndef BOOST_ITERATOR_CONCEPTS_HPP
 | 
					
						
							|  |  |  | #define BOOST_ITERATOR_CONCEPTS_HPP
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/concept_check.hpp>
 | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  | #include <boost/iterator_categories.hpp>
 | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  | #include <boost/type_traits/conversion_traits.hpp>
 | 
					
						
							|  |  |  | #include <boost/static_assert.hpp>
 | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace boost_concepts { | 
					
						
							|  |  |  |   // Used a different namespace here (instead of "boost") so that the
 | 
					
						
							|  |  |  |   // concept descriptions do not take for granted the names in
 | 
					
						
							|  |  |  |   // namespace boost.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //===========================================================================
 | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |   // Iterator Access Concepts
 | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   template <typename Iterator> | 
					
						
							|  |  |  |   class ReadableIteratorConcept { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |     typedef typename std::iterator_traits<Iterator>::value_type value_type; | 
					
						
							|  |  |  |     typedef typename std::iterator_traits<Iterator>::reference reference; | 
					
						
							|  |  |  |     typedef typename boost::return_category<Iterator>::type return_category; | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void constraints() { | 
					
						
							|  |  |  |       boost::function_requires< boost::SGIAssignableConcept<Iterator> >(); | 
					
						
							|  |  |  |       boost::function_requires< boost::EqualityComparableConcept<Iterator> >(); | 
					
						
							|  |  |  |       boost::function_requires<  | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |         boost::DefaultConstructibleConcept<Iterator> >(); | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       BOOST_STATIC_ASSERT((boost::is_convertible<return_category*, | 
					
						
							|  |  |  |                            boost::readable_iterator_tag*>::value)); | 
					
						
							|  |  |  |                            | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  |       reference r = *i; // or perhaps read(x)
 | 
					
						
							|  |  |  |       value_type v(r); | 
					
						
							|  |  |  |       boost::ignore_unused_variable_warning(v); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Iterator i; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   template <typename Iterator, typename ValueType> | 
					
						
							|  |  |  |   class WritableIteratorConcept { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |     typedef typename boost::return_category<Iterator>::type return_category; | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void constraints() { | 
					
						
							|  |  |  |       boost::function_requires< boost::SGIAssignableConcept<Iterator> >(); | 
					
						
							|  |  |  |       boost::function_requires< boost::EqualityComparableConcept<Iterator> >(); | 
					
						
							|  |  |  |       boost::function_requires<  | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |         boost::DefaultConstructibleConcept<Iterator> >(); | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       BOOST_STATIC_ASSERT((boost::is_convertible<return_category*, | 
					
						
							|  |  |  |                            boost::writable_iterator_tag*>::value)); | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |       *i = v; // a good alternative could be something like write(x, v)
 | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     ValueType v; | 
					
						
							|  |  |  |     Iterator i; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   template <typename Iterator> | 
					
						
							|  |  |  |   class ConstantLvalueIteratorConcept { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |     typedef typename std::iterator_traits<Iterator>::value_type value_type; | 
					
						
							|  |  |  |     typedef typename std::iterator_traits<Iterator>::reference reference; | 
					
						
							|  |  |  |     typedef typename boost::return_category<Iterator>::type return_category; | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void constraints() { | 
					
						
							|  |  |  |       boost::function_requires< ReadableIteratorConcept<Iterator> >(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |       BOOST_STATIC_ASSERT((boost::is_convertible<return_category*,  | 
					
						
							|  |  |  |                            boost::constant_lvalue_iterator_tag*>::value)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       BOOST_STATIC_ASSERT((boost::is_same<reference,  | 
					
						
							|  |  |  |                            const value_type&>::value)); | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       reference v = *i; | 
					
						
							|  |  |  |       boost::ignore_unused_variable_warning(v); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Iterator i; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   template <typename Iterator> | 
					
						
							|  |  |  |   class MutableLvalueIteratorConcept { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |     typedef typename std::iterator_traits<Iterator>::value_type value_type; | 
					
						
							|  |  |  |     typedef typename std::iterator_traits<Iterator>::reference reference; | 
					
						
							|  |  |  |     typedef typename boost::return_category<Iterator>::type return_category; | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void constraints() { | 
					
						
							|  |  |  |       boost::function_requires< ReadableIteratorConcept<Iterator> >(); | 
					
						
							|  |  |  |       boost::function_requires<  | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |         WritableIteratorConcept<Iterator, value_type> >(); | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       BOOST_STATIC_ASSERT((boost::is_convertible<return_category*,  | 
					
						
							|  |  |  |                            boost::mutable_lvalue_iterator_tag*>::value)); | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |       BOOST_STATIC_ASSERT((boost::is_same<reference, value_type&>::value)); | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       reference v = *i; | 
					
						
							|  |  |  |       boost::ignore_unused_variable_warning(v); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Iterator i; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   //===========================================================================
 | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |   // Iterator Traversal Concepts
 | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   template <typename Iterator> | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |   class ForwardIteratorConcept { | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  |   public: | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |     typedef typename boost::traversal_category<Iterator>::type traversal_category; | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void constraints() { | 
					
						
							|  |  |  |       boost::function_requires< boost::SGIAssignableConcept<Iterator> >(); | 
					
						
							|  |  |  |       boost::function_requires< boost::EqualityComparableConcept<Iterator> >(); | 
					
						
							|  |  |  |       boost::function_requires<  | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |         boost::DefaultConstructibleConcept<Iterator> >(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*,  | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |                            boost::forward_traversal_tag*>::value)); | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  |       ++i; | 
					
						
							|  |  |  |       (void)i++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Iterator i; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   template <typename Iterator> | 
					
						
							|  |  |  |   class BidirectionalIteratorConcept { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |     typedef typename boost::traversal_category<Iterator>::type traversal_category; | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void constraints() { | 
					
						
							|  |  |  |       boost::function_requires< ForwardIteratorConcept<Iterator> >(); | 
					
						
							|  |  |  |        | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |       BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*,  | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |                            boost::bidirectional_traversal_tag*>::value)); | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       --i; | 
					
						
							|  |  |  |       (void)i--; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Iterator i; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   template <typename Iterator> | 
					
						
							|  |  |  |   class RandomAccessIteratorConcept { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |     typedef typename boost::traversal_category<Iterator>::type traversal_category; | 
					
						
							|  |  |  |     typedef typename std::iterator_traits<Iterator>::difference_type | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  |       difference_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void constraints() { | 
					
						
							|  |  |  |       boost::function_requires< BidirectionalIteratorConcept<Iterator> >(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |       BOOST_STATIC_ASSERT((boost::is_convertible<traversal_category*,  | 
					
						
							| 
									
										
										
										
											2001-06-03 21:06:49 +00:00
										 |  |  |                            boost::random_access_traversal_tag*>::value)); | 
					
						
							| 
									
										
										
										
											2001-03-18 18:37:49 +00:00
										 |  |  |        | 
					
						
							| 
									
										
										
										
											2001-02-05 05:39:43 +00:00
										 |  |  |       i += n; | 
					
						
							|  |  |  |       i = i + n; | 
					
						
							|  |  |  |       i = n + i; | 
					
						
							|  |  |  |       i -= n; | 
					
						
							|  |  |  |       i = i - n; | 
					
						
							|  |  |  |       n = i - j; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     difference_type n; | 
					
						
							|  |  |  |     Iterator i, j; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace boost_concepts
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // BOOST_ITERATOR_CONCEPTS_HPP
 |