sl@0: // Boost.Range library concept checks sl@0: // sl@0: // Copyright Daniel Walker 2006. Use, modification and distribution sl@0: // are subject to the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: // sl@0: // For more information, see http://www.boost.org/libs/range/ sl@0: // sl@0: sl@0: #ifndef BOOST_RANGE_CONCEPTS_HPP sl@0: #define BOOST_RANGE_CONCEPTS_HPP sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: /*! sl@0: * \file sl@0: * \brief Concept checks for the Boost Range library. sl@0: * sl@0: * The structures in this file may be used in conjunction with the sl@0: * Boost Concept Check library to insure that the type of a function sl@0: * parameter is compatible with a range concept. If not, a meaningful sl@0: * compile time error is generated. Checks are provided for the range sl@0: * concepts related to iterator traversal categories. For example, the sl@0: * following line checks that the type T models the ForwardRange sl@0: * concept. sl@0: * sl@0: * \code sl@0: * function_requires >(); sl@0: * \endcode sl@0: * sl@0: * An additional concept check is required for the value access sl@0: * property of the range. For example to check for a sl@0: * ForwardReadableRange, the following code is required. sl@0: * sl@0: * \code sl@0: * function_requires >(); sl@0: * function_requires< sl@0: * ReadableIteratorConcept< sl@0: * typename range_iterator::type sl@0: * > sl@0: * >(); sl@0: * \endcode sl@0: * sl@0: * \see http://www.boost.org/libs/range/doc/range.html for details sl@0: * about range concepts. sl@0: * \see http://www.boost.org/libs/iterator/doc/iterator_concepts.html sl@0: * for details about iterator concepts. sl@0: * \see http://www.boost.org/libs/concept_check/concept_check.htm for sl@0: * details about concept checks. sl@0: */ sl@0: sl@0: namespace boost { sl@0: sl@0: //! Check if a type T models the SinglePassRange range concept. sl@0: template sl@0: struct SinglePassRangeConcept { sl@0: typedef typename range_value::type range_value; sl@0: typedef typename range_iterator::type range_iterator; sl@0: typedef typename range_const_iterator::type range_const_iterator; sl@0: void constraints() sl@0: { sl@0: function_requires< sl@0: boost_concepts::SinglePassIteratorConcept< sl@0: range_iterator sl@0: > sl@0: >(); sl@0: i = boost::begin(a); sl@0: i = boost::end(a); sl@0: b = boost::empty(a); sl@0: const_constraints(a); sl@0: } sl@0: void const_constraints(const T& a) sl@0: { sl@0: ci = boost::begin(a); sl@0: ci = boost::end(a); sl@0: } sl@0: T a; sl@0: range_iterator i; sl@0: range_const_iterator ci; sl@0: bool b; sl@0: }; sl@0: sl@0: //! Check if a type T models the ForwardRange range concept. sl@0: template sl@0: struct ForwardRangeConcept { sl@0: typedef typename range_difference::type range_difference; sl@0: typedef typename range_size::type range_size; sl@0: void constraints() sl@0: { sl@0: function_requires< sl@0: SinglePassRangeConcept sl@0: >(); sl@0: function_requires< sl@0: boost_concepts::ForwardTraversalConcept< sl@0: typename range_iterator::type sl@0: > sl@0: >(); sl@0: s = boost::size(a); sl@0: } sl@0: T a; sl@0: range_size s; sl@0: }; sl@0: sl@0: //! Check if a type T models the BidirectionalRange range concept. sl@0: template sl@0: struct BidirectionalRangeConcept { sl@0: typedef typename range_reverse_iterator::type range_reverse_iterator; sl@0: typedef typename range_const_reverse_iterator::type range_const_reverse_iterator; sl@0: void constraints() sl@0: { sl@0: function_requires< sl@0: ForwardRangeConcept sl@0: >(); sl@0: function_requires< sl@0: boost_concepts::BidirectionalTraversalConcept< sl@0: typename range_iterator::type sl@0: > sl@0: >(); sl@0: i = boost::rbegin(a); sl@0: i = boost::rend(a); sl@0: const_constraints(a); sl@0: } sl@0: void const_constraints(const T& a) sl@0: { sl@0: ci = boost::rbegin(a); sl@0: ci = boost::rend(a); sl@0: } sl@0: T a; sl@0: range_reverse_iterator i; sl@0: range_const_reverse_iterator ci; sl@0: }; sl@0: sl@0: //! Check if a type T models the RandomAccessRange range concept. sl@0: template sl@0: struct RandomAccessRangeConcept { sl@0: void constraints() sl@0: { sl@0: function_requires< sl@0: BidirectionalRangeConcept sl@0: >(); sl@0: function_requires< sl@0: boost_concepts::RandomAccessTraversalConcept< sl@0: typename range_iterator::type sl@0: > sl@0: >(); sl@0: } sl@0: }; sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_RANGE_CONCEPTS_HPP