thrust
is_contiguous_iterator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2018 NVIDIA Corporation
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 
23 #pragma once
24 
25 #include <thrust/detail/config.h>
26 #include <thrust/detail/type_traits.h>
27 #include <thrust/detail/type_traits/pointer_traits.h>
28 
29 #include <iterator>
30 
31 #if defined(_MSC_VER) && _MSC_VER < 1916 // MSVC 2017 version 15.9
32  #include <vector>
33  #include <string>
34  #include <array>
35 
36  #if THRUST_CPP_DIALECT >= 2017
37  #include <string_view>
38  #endif
39 #endif
40 
41 THRUST_BEGIN_NS
42 
43 namespace detail
44 {
45 
46 template <typename Iterator>
47 struct is_contiguous_iterator_impl;
48 
49 } // namespace detail
50 
55 template <typename Iterator>
56 #if THRUST_CPP_DIALECT >= 2011
57 using is_contiguous_iterator =
58 #else
60 #endif
61  detail::is_contiguous_iterator_impl<Iterator>
62 #if THRUST_CPP_DIALECT < 2011
63 {}
64 #endif
65 ;
66 
67 #if THRUST_CPP_DIALECT >= 2014
68 template <typename Iterator>
73 constexpr bool is_contiguous_iterator_v = is_contiguous_iterator<Iterator>::value;
74 #endif
75 
80 template <typename Iterator>
81 struct proclaim_contiguous_iterator : false_type {};
82 
86 #define THRUST_PROCLAIM_CONTIGUOUS_ITERATOR(Iterator) \
87  THRUST_BEGIN_NS \
88  template <> \
89  struct proclaim_contiguous_iterator<Iterator> : ::thrust::true_type {}; \
90  THRUST_END_NS \
91 
92 
94 
95 namespace detail
96 {
97 
98 template <typename Iterator>
99 struct is_libcxx_wrap_iter : false_type {};
100 
101 #if defined(_LIBCPP_VERSION)
102 template <typename Iterator>
103 struct is_libcxx_wrap_iter<
104  _VSTD::__wrap_iter<Iterator>
105 > : true_type {};
106 #endif
107 
108 template <typename Iterator>
109 struct is_libstdcxx_normal_iterator : false_type {};
110 
111 #if defined(__GLIBCXX__)
112 template <typename Iterator, typename Container>
113 struct is_libstdcxx_normal_iterator<
114  ::__gnu_cxx::__normal_iterator<Iterator, Container>
115 > : true_type {};
116 #endif
117 
118 #if _MSC_VER >= 1916 // MSVC 2017 version 15.9.
119 template <typename Iterator>
120 struct is_msvc_contiguous_iterator
121  : is_pointer<::std::_Unwrapped_t<Iterator> > {};
122 #elif _MSC_VER >= 1700 // MSVC 2012.
123 template <typename Iterator>
124 struct is_msvc_contiguous_iterator : false_type {};
125 
126 template <typename Vector>
127 struct is_msvc_contiguous_iterator<
128  ::std::_Vector_const_iterator<Vector>
129 > : true_type {};
130 
131 template <typename Vector>
132 struct is_msvc_contiguous_iterator<
133  ::std::_Vector_iterator<Vector>
134 > : true_type {};
135 
136 template <typename String>
137 struct is_msvc_contiguous_iterator<
138  ::std::_String_const_iterator<String>
139 > : true_type {};
140 
141 template <typename String>
142 struct is_msvc_contiguous_iterator<
143  ::std::_String_iterator<String>
144 > : true_type {};
145 
146 template <typename T, std::size_t N>
147 struct is_msvc_contiguous_iterator<
148  ::std::_Array_const_iterator<T, N>
149 > : true_type {};
150 
151 template <typename T, std::size_t N>
152 struct is_msvc_contiguous_iterator<
153  ::std::_Array_iterator<T, N>
154 > : true_type {};
155 
156 #if THRUST_CPP_DIALECT >= 2017
157 template <typename Traits>
158 struct is_msvc_contiguous_iterator<
159  ::std::_String_view_iterator<Traits>
160 > : true_type {};
161 #endif
162 #else
163 template <typename Iterator>
164 struct is_msvc_contiguous_iterator : false_type {};
165 #endif
166 
167 
168 template <typename Iterator>
169 struct is_contiguous_iterator_impl
170  : integral_constant<
171  bool
172  , is_pointer<Iterator>::value
173  || is_thrust_pointer<Iterator>::value
174  || is_libcxx_wrap_iter<Iterator>::value
175  || is_libstdcxx_normal_iterator<Iterator>::value
176  || is_msvc_contiguous_iterator<Iterator>::value
177  || proclaim_contiguous_iterator<Iterator>::value
178  >
179 {};
180 
181 } // namespace detail
182 
183 THRUST_END_NS
184 
Definition: is_contiguous_iterator.h:59
Definition: is_contiguous_iterator.h:81