Bolt  1.3
C++ template library with support for OpenCL
iterator_categories.h
1 /***************************************************************************
2 * © 2012,2014 Advanced Micro Devices, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 
16 ***************************************************************************/
17 
18 // (C) Copyright Jeremy Siek 2002.
19 // Distributed under the Boost Software License, Version 1.0. (See
20 // accompanying file BOOST_LICENSE_1_0.txt or copy at
21 // http://www.boost.org/LICENSE_1_0.txt)
22 
23 #ifndef BOLT_ITERATOR_CATEGORIES_H
24 # define BOLT_ITERATOR_CATEGORIES_H
25 
26 
27 #include <type_traits>
28 #include <bolt/cl/detail/type_traits.h>
30 
31 namespace bolt {
32 namespace cl {
33 //
34 // Traversal Categories
35 //
36 
37 struct no_traversal_tag {};
38 
41 {
42 // incrementable_traversal_tag() {}
43 // incrementable_traversal_tag(std::output_iterator_tag const&) {};
44 };
45 
48 {
49 // single_pass_traversal_tag() {}
50 // single_pass_traversal_tag(std::input_iterator_tag const&) {};
51 };
52 
55 {
56 // forward_traversal_tag() {}
57 // forward_traversal_tag(std::forward_iterator_tag const&) {};
58 };
59 
62 {
63 // bidirectional_traversal_tag() {};
64 // bidirectional_traversal_tag(std::bidirectional_iterator_tag const&) {};
65 };
66 
69 {
70 // random_access_traversal_tag() {};
71 // random_access_traversal_tag(std::random_access_iterator_tag const&) {};
72 };
73 
74 namespace detail
75 {
76  //
77  // Convert a "strictly old-style" iterator category to a traversal
78  // tag. This is broken out into a separate metafunction to reduce
79  // the cost of instantiating iterator_category_to_traversal, below,
80  // for new-style types.
81  //
82  template <class Cat>
84  : bolt::cl::detail::eval_if<
85  std::is_convertible<Cat,std::random_access_iterator_tag>
86  , bolt::cl::detail::identity_<random_access_traversal_tag>
87  , bolt::cl::detail::eval_if<
88  std::is_convertible<Cat,std::bidirectional_iterator_tag>
89  , bolt::cl::detail::identity_<bidirectional_traversal_tag>
90  , bolt::cl::detail::eval_if<
91  std::is_convertible<Cat,std::forward_iterator_tag>
92  , bolt::cl::detail::identity_<forward_traversal_tag>
93  , bolt::cl::detail::eval_if<
94  std::is_convertible<Cat,std::input_iterator_tag>
95  , bolt::cl::detail::identity_<single_pass_traversal_tag>
96  , bolt::cl::detail::eval_if<
97  std::is_convertible<Cat,std::output_iterator_tag>
98  , bolt::cl::detail::identity_<incrementable_traversal_tag>
99  , void
100  >
101  >
102  >
103  >
104  >
105  {};
106 
107 
108 } // namespace detail
109 
110 
111 //
112 // Convert an iterator category into a traversal tag
113 //
114 template <class Cat>
116  : bolt::cl::detail::eval_if< // if already convertible to a traversal tag, we're done.
117  std::is_convertible<Cat,incrementable_traversal_tag>
118  , bolt::cl::detail::identity_<Cat>
119  , bolt::cl::detail::old_category_to_traversal<Cat>
120  >
121 {};
122 
123 // Trait to get an iterator's traversal category
124 template <class Iterator >
127  typename bolt::cl::iterator_traits<Iterator>::iterator_category
128  >
129 {};
130 
131 } } // namespace bolt::cl
132 
133 
134 #endif // BOLT_ITERATOR_CATEGORIES_H