thrust
counting_iterator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2013 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 
17 
23 /*
24  * Copyright David Abrahams 2003.
25  *
26  * Distributed under the Boost Software License, Version 1.0.
27  * (See accompanying NOTICE file for the complete license)
28  *
29  * For more information, see http://www.boost.org
30  */
31 
32 #pragma once
33 
34 #include <thrust/detail/config.h>
38 
39 // #include the details first
40 #include <thrust/iterator/detail/counting_iterator.inl>
41 
42 namespace thrust
43 {
44 
128 template<typename Incrementable,
129  typename System = use_default,
130  typename Traversal = use_default,
131  typename Difference = use_default>
133  : public detail::counting_iterator_base<Incrementable, System, Traversal, Difference>::type
134 {
137  typedef typename detail::counting_iterator_base<Incrementable, System, Traversal, Difference>::type super_t;
138 
139  friend class thrust::iterator_core_access;
140 
141  public:
142  typedef typename super_t::reference reference;
143  typedef typename super_t::difference_type difference_type;
144 
151  __host__ __device__
152  counting_iterator() {}
153 
159  __host__ __device__
160  counting_iterator(counting_iterator const &rhs):super_t(rhs.base()){}
161 
167  template<typename OtherSystem>
168  __host__ __device__
170  typename thrust::detail::enable_if_convertible<
171  typename thrust::iterator_system<counting_iterator<Incrementable,OtherSystem,Traversal,Difference> >::type,
172  typename thrust::iterator_system<super_t>::type
173  >::type * = 0)
174  : super_t(rhs.base()){}
175 
182  __host__ __device__
183  explicit counting_iterator(Incrementable x):super_t(x){}
184 
187  private:
188  __host__ __device__
189  reference dereference() const
190  {
191  return this->base_reference();
192  }
193 
194  // note that we implement equal specially for floating point counting_iterator
195  template <typename OtherIncrementable, typename OtherSystem, typename OtherTraversal, typename OtherDifference>
196  __host__ __device__
198  {
199  typedef thrust::detail::counting_iterator_equal<difference_type,Incrementable,OtherIncrementable> e;
200  return e::equal(this->base(), y.base());
201  }
202 
203  template <class OtherIncrementable>
204  __host__ __device__
205  difference_type
207  {
208  typedef typename
209  thrust::detail::eval_if<
210  thrust::detail::is_numeric<Incrementable>::value,
211  thrust::detail::identity_<thrust::detail::number_distance<difference_type, Incrementable, OtherIncrementable> >,
212  thrust::detail::identity_<thrust::detail::iterator_distance<difference_type, Incrementable, OtherIncrementable> >
213  >::type d;
214 
215  return d::distance(this->base(), y.base());
216  }
217 
220 }; // end counting_iterator
221 
222 
229 template <typename Incrementable>
230 inline __host__ __device__
232 {
234 }
235 
242 } // end thrust
243 
Definition: iterator_facade.h:61
An iterator which adapts a base iterator.
__host__ __device__ bool equal(const thrust::detail::execution_policy_base< DerivedPolicy > &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
thrust is the top-level namespace which contains all Thrust functions and types.
Definition: addressof.h:14
Types for reasoning about the categories of iterators.
__host__ __device__ thrust::iterator_traits< InputIterator >::difference_type distance(InputIterator first, InputIterator last)
A class which exposes a public interface for iterators.
Definition: counting_iterator.h:132
__host__ __device__ counting_iterator< Incrementable > make_counting_iterator(Incrementable x)
Definition: counting_iterator.h:231