fix doc example typo
[boost.git] / boost / range / concepts.hpp
blob53a88dc3d95d7d584b8c85208ab86cd94575bdb2
1 // Boost.Range library concept checks
2 //
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)
7 //
8 // For more information, see http://www.boost.org/libs/range/
9 //
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/begin.hpp>
17 #include <boost/range/end.hpp>
19 /*!
20 * \file
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
29 * concept.
31 * \code
32 * function_requires<ForwardRangeConcept<T> >();
33 * \endcode
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.
39 * \code
40 * function_requires<ForwardRangeConcept<T> >();
41 * function_requires<
42 * ReadableIteratorConcept<
43 * typename range_iterator<T>::type
44 * >
45 * >();
46 * \endcode
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.
56 namespace boost {
58 //! Check if a type T models the SinglePassRange range concept.
59 template<typename T>
60 struct SinglePassRangeConcept
62 typedef typename range_iterator<T const>::type range_const_iterator;
63 typedef typename range_iterator<T>::type range_iterator;
65 void constraints()
67 function_requires<
68 boost_concepts::SinglePassIteratorConcept<
69 range_iterator
71 >();
72 i = boost::begin(a);
73 i = boost::end(a);
74 const_constraints(a);
77 void const_constraints(const T& a)
79 ci = boost::begin(a);
80 ci = boost::end(a);
82 T a;
83 range_iterator i;
84 range_const_iterator ci;
87 //! Check if a type T models the ForwardRange range concept.
88 template<typename T>
89 struct ForwardRangeConcept
91 void constraints()
93 function_requires<
94 SinglePassRangeConcept<T>
95 >();
96 function_requires<
97 boost_concepts::ForwardTraversalConcept<
98 typename range_iterator<T>::type
100 >();
104 //! Check if a type T models the BidirectionalRange range concept.
105 template<typename T>
106 struct BidirectionalRangeConcept
108 void constraints()
110 function_requires<
111 ForwardRangeConcept<T>
112 >();
113 function_requires<
114 boost_concepts::BidirectionalTraversalConcept<
115 typename range_iterator<T>::type
117 >();
121 //! Check if a type T models the RandomAccessRange range concept.
122 template<typename T>
123 struct RandomAccessRangeConcept
125 void constraints()
127 function_requires<
128 BidirectionalRangeConcept<T>
129 >();
130 function_requires<
131 boost_concepts::RandomAccessTraversalConcept<
132 typename range_iterator<T>::type
134 >();
138 } // namespace boost
140 #endif // BOOST_RANGE_CONCEPTS_HPP