First public contribution.
1 // Boost.Range library concept checks
3 // Copyright Daniel Walker 2006. Use, modification and distribution
4 // are subject to the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/range/
11 #ifndef BOOST_RANGE_CONCEPTS_HPP
12 #define BOOST_RANGE_CONCEPTS_HPP
14 #include <boost/concept_check.hpp>
15 #include <boost/iterator/iterator_concepts.hpp>
16 #include <boost/range/functions.hpp>
17 #include <boost/range/metafunctions.hpp>
21 * \brief Concept checks for the Boost Range library.
23 * The structures in this file may be used in conjunction with the
24 * Boost Concept Check library to insure that the type of a function
25 * parameter is compatible with a range concept. If not, a meaningful
26 * compile time error is generated. Checks are provided for the range
27 * concepts related to iterator traversal categories. For example, the
28 * following line checks that the type T models the ForwardRange
32 * function_requires<ForwardRangeConcept<T> >();
35 * An additional concept check is required for the value access
36 * property of the range. For example to check for a
37 * ForwardReadableRange, the following code is required.
40 * function_requires<ForwardRangeConcept<T> >();
42 * ReadableIteratorConcept<
43 * typename range_iterator<T>::type
48 * \see http://www.boost.org/libs/range/doc/range.html for details
49 * about range concepts.
50 * \see http://www.boost.org/libs/iterator/doc/iterator_concepts.html
51 * for details about iterator concepts.
52 * \see http://www.boost.org/libs/concept_check/concept_check.htm for
53 * details about concept checks.
58 //! Check if a type T models the SinglePassRange range concept.
60 struct SinglePassRangeConcept {
61 typedef typename range_value<T>::type range_value;
62 typedef typename range_iterator<T>::type range_iterator;
63 typedef typename range_const_iterator<T>::type range_const_iterator;
67 boost_concepts::SinglePassIteratorConcept<
76 void const_constraints(const T& a)
83 range_const_iterator ci;
87 //! Check if a type T models the ForwardRange range concept.
89 struct ForwardRangeConcept {
90 typedef typename range_difference<T>::type range_difference;
91 typedef typename range_size<T>::type range_size;
95 SinglePassRangeConcept<T>
98 boost_concepts::ForwardTraversalConcept<
99 typename range_iterator<T>::type
108 //! Check if a type T models the BidirectionalRange range concept.
110 struct BidirectionalRangeConcept {
111 typedef typename range_reverse_iterator<T>::type range_reverse_iterator;
112 typedef typename range_const_reverse_iterator<T>::type range_const_reverse_iterator;
116 ForwardRangeConcept<T>
119 boost_concepts::BidirectionalTraversalConcept<
120 typename range_iterator<T>::type
123 i = boost::rbegin(a);
125 const_constraints(a);
127 void const_constraints(const T& a)
129 ci = boost::rbegin(a);
133 range_reverse_iterator i;
134 range_const_reverse_iterator ci;
137 //! Check if a type T models the RandomAccessRange range concept.
139 struct RandomAccessRangeConcept {
143 BidirectionalRangeConcept<T>
146 boost_concepts::RandomAccessTraversalConcept<
147 typename range_iterator<T>::type
155 #endif // BOOST_RANGE_CONCEPTS_HPP