#ifndef BOOST_ITERATOR_CONCEPTS_HPP #define BOOST_ITERATOR_CONCEPTS_HPP #include #include #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. //=========================================================================== // Iterator Access Concepts template class ReadableIteratorConcept { public: typedef typename std::iterator_traits::value_type value_type; typedef typename std::iterator_traits::reference reference; typedef typename boost::return_category::type return_category; void constraints() { boost::function_requires< boost::SGIAssignableConcept >(); boost::function_requires< boost::EqualityComparableConcept >(); boost::function_requires< boost::DefaultConstructibleConcept >(); BOOST_STATIC_ASSERT((boost::is_convertible::value)); 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::return_category::type return_category; void constraints() { boost::function_requires< boost::SGIAssignableConcept >(); boost::function_requires< boost::EqualityComparableConcept >(); boost::function_requires< boost::DefaultConstructibleConcept >(); BOOST_STATIC_ASSERT((boost::is_convertible::value)); *i = v; // a good alternative could be something like write(x, v) } ValueType v; Iterator i; }; template class ConstantLvalueIteratorConcept { public: typedef typename std::iterator_traits::value_type value_type; typedef typename std::iterator_traits::reference reference; typedef typename boost::return_category::type return_category; void constraints() { boost::function_requires< ReadableIteratorConcept >(); BOOST_STATIC_ASSERT((boost::is_convertible::value)); BOOST_STATIC_ASSERT((boost::is_same::value)); reference v = *i; boost::ignore_unused_variable_warning(v); } Iterator i; }; template class MutableLvalueIteratorConcept { public: typedef typename std::iterator_traits::value_type value_type; typedef typename std::iterator_traits::reference reference; typedef typename boost::return_category::type return_category; void constraints() { boost::function_requires< ReadableIteratorConcept >(); boost::function_requires< WritableIteratorConcept >(); BOOST_STATIC_ASSERT((boost::is_convertible::value)); BOOST_STATIC_ASSERT((boost::is_same::value)); reference v = *i; boost::ignore_unused_variable_warning(v); } Iterator i; }; //=========================================================================== // Iterator Traversal Concepts template class ForwardIteratorConcept { public: typedef typename boost::traversal_category::type traversal_category; void constraints() { boost::function_requires< boost::SGIAssignableConcept >(); boost::function_requires< boost::EqualityComparableConcept >(); boost::function_requires< boost::DefaultConstructibleConcept >(); BOOST_STATIC_ASSERT((boost::is_convertible::value)); ++i; (void)i++; } Iterator i; }; template class BidirectionalIteratorConcept { public: typedef typename boost::traversal_category::type traversal_category; void constraints() { boost::function_requires< ForwardIteratorConcept >(); BOOST_STATIC_ASSERT((boost::is_convertible::value)); --i; (void)i--; } Iterator i; }; template class RandomAccessIteratorConcept { public: typedef typename boost::traversal_category::type traversal_category; typedef typename std::iterator_traits::difference_type difference_type; void constraints() { boost::function_requires< BidirectionalIteratorConcept >(); BOOST_STATIC_ASSERT((boost::is_convertible::value)); 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