#ifndef BOOST_ITERATOR_CONCEPTS_HPP #define BOOST_ITERATOR_CONCEPTS_HPP #include #include 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. //=========================================================================== template class ReadableIteratorConcept { public: typedef typename boost::iterator_traits::value_type value_type; typedef typename boost::iterator_traits::reference reference; typedef typename boost::iterator_traits::return_category return_category; void constraints() { boost::function_requires< boost::SGIAssignableConcept >(); boost::function_requires< boost::EqualityComparableConcept >(); boost::function_requires< boost::DefaultConstructibleConcept >(); boost::function_requires< boost::ConvertibleConcept >(); reference r = *i; // or perhaps read(x) value_type v(r); boost::ignore_unused_variable_warning(v); } Iterator i; }; template class WritableIteratorConcept { public: typedef typename boost::iterator_traits::return_category return_category; void constraints() { boost::function_requires< boost::SGIAssignableConcept >(); boost::function_requires< boost::EqualityComparableConcept >(); boost::function_requires< boost::DefaultConstructibleConcept >(); boost::function_requires< boost::ConvertibleConcept >(); *i = v; // an alternative could be something like write(x, v) } ValueType v; Iterator i; }; template class ConstantLvalueIteratorConcept { public: typedef typename boost::iterator_traits::value_type value_type; typedef typename boost::iterator_traits::reference reference; typedef typename boost::iterator_traits::return_category return_category; void constraints() { boost::function_requires< ReadableIteratorConcept >(); boost::function_requires< boost::ConvertibleConcept >(); typedef typename boost::require_same::type req; reference v = *i; boost::ignore_unused_variable_warning(v); } Iterator i; }; template class MutableLvalueIteratorConcept { public: typedef typename boost::iterator_traits::value_type value_type; typedef typename boost::iterator_traits::reference reference; typedef typename boost::iterator_traits::return_category return_category; void constraints() { boost::function_requires< ReadableIteratorConcept >(); boost::function_requires< WritableIteratorConcept >(); boost::function_requires< boost::ConvertibleConcept >(); typedef typename boost::require_same::type req; reference v = *i; boost::ignore_unused_variable_warning(v); } Iterator i; }; //=========================================================================== template class SinglePassIteratorConcept { public: typedef typename boost::iterator_traits::motion_category motion_category; typedef typename boost::iterator_traits::difference_type difference_type; void constraints() { boost::function_requires< boost::SGIAssignableConcept >(); boost::function_requires< boost::EqualityComparableConcept >(); boost::function_requires< boost::DefaultConstructibleConcept >(); boost::function_requires< boost::ConvertibleConcept >(); // difference_type must be a signed integral type ++i; (void)i++; } Iterator i; }; template class ForwardIteratorConcept { public: typedef typename boost::iterator_traits::motion_category motion_category; void constraints() { boost::function_requires< SinglePassIteratorConcept >(); boost::function_requires< boost::ConvertibleConcept >(); } }; template class BidirectionalIteratorConcept { public: typedef typename boost::iterator_traits::motion_category motion_category; void constraints() { boost::function_requires< ForwardIteratorConcept >(); boost::function_requires< boost::ConvertibleConcept >(); --i; (void)i--; } Iterator i; }; template class RandomAccessIteratorConcept { public: typedef typename boost::iterator_traits::motion_category motion_category; typedef typename boost::iterator_traits::difference_type difference_type; void constraints() { boost::function_requires< BidirectionalIteratorConcept >(); boost::function_requires< boost::ConvertibleConcept >(); i += n; i = i + n; i = n + i; i -= n; i = i - n; n = i - j; } difference_type n; Iterator i, j; }; //=========================================================================== template class ReadableRandomAccessIteratorConcept { public: typedef typename boost::iterator_traits::value_type value_type; typedef typename boost::iterator_traits::reference reference; typedef typename boost::iterator_traits::difference_type difference_type; void constraints() { boost::function_requires< RandomAccessIteratorConcept >(); boost::function_requires< ReadableIteratorConcept >(); reference r = i[n]; value_type v(r); boost::ignore_unused_variable_warning(v); } difference_type n; Iterator i; }; template class WritableRandomAccessIteratorConcept { public: typedef typename boost::iterator_traits::value_type value_type; typedef typename boost::iterator_traits::difference_type difference_type; void constraints() { boost::function_requires< RandomAccessIteratorConcept >(); boost::function_requires< WritableIteratorConcept >(); i[n] = v; boost::ignore_unused_variable_warning(v); } difference_type n; value_type v; Iterator i; }; template class ConstantLvalueRandomAccessIteratorConcept { public: typedef typename boost::iterator_traits::value_type value_type; typedef typename boost::iterator_traits::reference reference; typedef typename boost::iterator_traits::difference_type difference_type; void constraints() { boost::function_requires< RandomAccessIteratorConcept >(); boost::function_requires< ReadableIteratorConcept >(); typedef typename boost::require_same::type req; reference v = i[n]; boost::ignore_unused_variable_warning(v); } difference_type n; value_type v; Iterator i; }; template class MutableLvalueRandomAccessIteratorConcept { public: typedef typename boost::iterator_traits::value_type value_type; typedef typename boost::iterator_traits::reference reference; typedef typename boost::iterator_traits::difference_type difference_type; void constraints() { boost::function_requires< RandomAccessIteratorConcept >(); boost::function_requires< WritableIteratorConcept >(); boost::function_requires< ReadableIteratorConcept >(); typedef typename boost::require_same::type req; reference v = i[n]; boost::ignore_unused_variable_warning(v); } difference_type n; value_type v; Iterator i; }; } // namespace boost_concepts #endif // BOOST_ITERATOR_CONCEPTS_HPP