1 // (C) Copyright Jeremy Siek 2002.
\r
2 // Distributed under the Boost Software License, Version 1.0. (See
\r
3 // accompanying file LICENSE_1_0.txt or copy at
\r
4 // http://www.boost.org/LICENSE_1_0.txt)
\r
6 #ifndef BOOST_ITERATOR_CATEGORIES_HPP
\r
7 # define BOOST_ITERATOR_CATEGORIES_HPP
\r
9 # include <boost/config.hpp>
\r
10 # include <boost/detail/iterator.hpp>
\r
11 # include <boost/iterator/detail/config_def.hpp>
\r
13 # include <boost/detail/workaround.hpp>
\r
15 # include <boost/mpl/eval_if.hpp>
\r
16 # include <boost/mpl/identity.hpp>
\r
17 # include <boost/mpl/placeholders.hpp>
\r
18 # include <boost/mpl/aux_/lambda_support.hpp>
\r
20 # include <boost/type_traits/is_convertible.hpp>
\r
22 # include <boost/static_assert.hpp>
\r
27 // Traversal Categories
\r
30 struct no_traversal_tag {};
\r
32 struct incrementable_traversal_tag
\r
35 // incrementable_traversal_tag() {}
\r
36 // incrementable_traversal_tag(std::output_iterator_tag const&) {};
\r
39 struct single_pass_traversal_tag
\r
40 : incrementable_traversal_tag
\r
42 // single_pass_traversal_tag() {}
\r
43 // single_pass_traversal_tag(std::input_iterator_tag const&) {};
\r
46 struct forward_traversal_tag
\r
47 : single_pass_traversal_tag
\r
49 // forward_traversal_tag() {}
\r
50 // forward_traversal_tag(std::forward_iterator_tag const&) {};
\r
53 struct bidirectional_traversal_tag
\r
54 : forward_traversal_tag
\r
56 // bidirectional_traversal_tag() {};
\r
57 // bidirectional_traversal_tag(std::bidirectional_iterator_tag const&) {};
\r
60 struct random_access_traversal_tag
\r
61 : bidirectional_traversal_tag
\r
63 // random_access_traversal_tag() {};
\r
64 // random_access_traversal_tag(std::random_access_iterator_tag const&) {};
\r
70 // Convert a "strictly old-style" iterator category to a traversal
\r
71 // tag. This is broken out into a separate metafunction to reduce
\r
72 // the cost of instantiating iterator_category_to_traversal, below,
\r
73 // for new-style types.
\r
75 template <class Cat>
\r
76 struct old_category_to_traversal
\r
78 is_convertible<Cat,std::random_access_iterator_tag>
\r
79 , mpl::identity<random_access_traversal_tag>
\r
81 is_convertible<Cat,std::bidirectional_iterator_tag>
\r
82 , mpl::identity<bidirectional_traversal_tag>
\r
84 is_convertible<Cat,std::forward_iterator_tag>
\r
85 , mpl::identity<forward_traversal_tag>
\r
87 is_convertible<Cat,std::input_iterator_tag>
\r
88 , mpl::identity<single_pass_traversal_tag>
\r
90 is_convertible<Cat,std::output_iterator_tag>
\r
91 , mpl::identity<incrementable_traversal_tag>
\r
100 # if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
\r
102 struct old_category_to_traversal<int>
\r
108 template <class Traversal>
\r
109 struct pure_traversal_tag
\r
111 is_convertible<Traversal,random_access_traversal_tag>
\r
112 , mpl::identity<random_access_traversal_tag>
\r
114 is_convertible<Traversal,bidirectional_traversal_tag>
\r
115 , mpl::identity<bidirectional_traversal_tag>
\r
117 is_convertible<Traversal,forward_traversal_tag>
\r
118 , mpl::identity<forward_traversal_tag>
\r
120 is_convertible<Traversal,single_pass_traversal_tag>
\r
121 , mpl::identity<single_pass_traversal_tag>
\r
123 is_convertible<Traversal,incrementable_traversal_tag>
\r
124 , mpl::identity<incrementable_traversal_tag>
\r
134 # if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
\r
136 struct pure_traversal_tag<int>
\r
142 } // namespace detail
\r
146 // Convert an iterator category into a traversal tag
\r
148 template <class Cat>
\r
149 struct iterator_category_to_traversal
\r
150 : mpl::eval_if< // if already convertible to a traversal tag, we're done.
\r
151 is_convertible<Cat,incrementable_traversal_tag>
\r
152 , mpl::identity<Cat>
\r
153 , boost::detail::old_category_to_traversal<Cat>
\r
157 // Trait to get an iterator's traversal category
\r
158 template <class Iterator = mpl::_1>
\r
159 struct iterator_traversal
\r
160 : iterator_category_to_traversal<
\r
161 typename boost::detail::iterator_traits<Iterator>::iterator_category
\r
165 # ifdef BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT
\r
166 // Hack because BOOST_MPL_AUX_LAMBDA_SUPPORT doesn't seem to work
\r
167 // out well. Instantiating the nested apply template also
\r
168 // requires instantiating iterator_traits on the
\r
169 // placeholder. Instead we just specialize it as a metafunction
\r
172 struct iterator_traversal<mpl::_1>
\r
175 struct apply : iterator_traversal<T>
\r
179 struct iterator_traversal<mpl::_>
\r
180 : iterator_traversal<mpl::_1>
\r
184 } // namespace boost
\r
186 #include <boost/iterator/detail/config_undef.hpp>
\r
188 #endif // BOOST_ITERATOR_CATEGORIES_HPP
\r