Bolt  1.1
C++ template library with support for OpenCL
iterator_traits.h
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright 2012 - 2013 Advanced Micro Devices, Inc.
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 #pragma once
19 #if !defined( BOLT_CL_ITERATOR_TRAITS_H )
20 #define BOLT_CL_ITERATOR_TRAITS_H
21 
27 // #include <iterator>
28 
29 namespace bolt {
30 namespace cl {
31 
33  {
34  operator std::input_iterator_tag ( ) const
35  {
36  }
37  };
38 
40  {
41  operator std::output_iterator_tag ( ) const
42  {
43  }
44  };
45 
47  {
48  operator std::forward_iterator_tag ( ) const
49  {
50  }
51  };
52 
54  {
55  operator std::bidirectional_iterator_tag ( ) const
56  {
57  }
58  };
59 
61  {
62  operator std::random_access_iterator_tag ( ) const
63  {
64  }
65 
66  random_access_iterator_tag& operator=( const std::random_access_iterator_tag& )
67  {
68  return *this;
69  }
70  };
71 
72  struct fancy_iterator_tag: public std::random_access_iterator_tag
73  {
74  };
75 
76  template< typename iterator >
78  {
79  typedef typename iterator::iterator_category iterator_category;
80  typedef typename iterator::value_type value_type;
81  typedef typename iterator::difference_type difference_type;
82  typedef typename iterator::pointer pointer;
83  typedef typename iterator::reference reference;
84  };
85 
86  template< class T >
87  struct iterator_traits< T* >
88  {
89  typedef typename std::random_access_iterator_tag iterator_category;
90  typedef T value_type;
91  // difference_type set to int for OpenCL backend
92  typedef int difference_type;
93  typedef T* pointer;
94  typedef T& reference;
95  };
96 
97  template< class T >
98  struct iterator_traits< const T* >
99  {
100  typedef typename std::random_access_iterator_tag iterator_category;
101  typedef T value_type;
102  // difference_type set to int for OpenCL backend
103  typedef int difference_type;
104  typedef const T* pointer;
105  typedef const T& reference;
106  };
107 
108 /*
109  template< typename newTag, typename InputIterator >
110  InputIterator retag( InputIterator )
111  {
112  switch( iterator_traits< InputIterator >::iterator_category( ) )
113  {
114  case std::input_iterator_tag :
115  return input_iterator_tag( );
116  case std::output_iterator_tag :
117  return output_iterator_tag( );
118  case std::forward_iterator_tag :
119  return forward_iterator_tag( );
120  case std::bidirectional_iterator_tag :
121  return bidirectional_iterator_tag( );
122  case std::random_access_iterator_tag :
123  return random_access_iterator_tag( );
124  }
125 
126  return iter;
127  }
128 */
129 }
130 };
131 
132 #endif