thrust
permutation_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 
21 /*
22  * (C) Copyright Toon Knapen 2001.
23  * (C) Copyright David Abrahams 2003.
24  * (C) Copyright Roland Richter 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>
35 #include <thrust/detail/type_traits.h>
36 #include <thrust/iterator/detail/permutation_iterator_base.h>
39 
40 namespace thrust
41 {
42 
43 
118 template <typename ElementIterator,
119  typename IndexIterator>
121  : public thrust::detail::permutation_iterator_base<
122  ElementIterator,
123  IndexIterator
124  >::type
125 {
128  private:
129  typedef typename detail::permutation_iterator_base<ElementIterator,IndexIterator>::type super_t;
130 
131  friend class thrust::iterator_core_access;
135  public:
139  __host__ __device__
141  : m_element_iterator() {}
142 
150  __host__ __device__
151  explicit permutation_iterator(ElementIterator x, IndexIterator y)
152  : super_t(y), m_element_iterator(x) {}
153 
157  template<typename OtherElementIterator, typename OtherIndexIterator>
158  __host__ __device__
160  // XXX remove these guards when we have static_assert
161  , typename detail::enable_if_convertible<OtherElementIterator, ElementIterator>::type* = 0
162  , typename detail::enable_if_convertible<OtherIndexIterator, IndexIterator>::type* = 0
163  )
164  : super_t(r.base()), m_element_iterator(r.m_element_iterator)
165  {}
166 
169  private:
170  // MSVC 2013 and 2015 incorrectly warning about returning a reference to
171  // a local/temporary here.
172  // See goo.gl/LELTNp
173  THRUST_DISABLE_MSVC_WARNING_BEGIN(4172)
174 
175  __thrust_exec_check_disable__
176  __host__ __device__
177  typename super_t::reference dereference() const
178  {
179  return *(m_element_iterator + *this->base());
180  }
181 
182  THRUST_DISABLE_MSVC_WARNING_END(4172)
183 
184  // make friends for the copy constructor
185  template<typename,typename> friend class permutation_iterator;
186 
187  ElementIterator m_element_iterator;
190 }; // end permutation_iterator
191 
192 
203 template<typename ElementIterator, typename IndexIterator>
204 __host__ __device__
206 {
208 }
209 
216 } // end thrust
217 
__host__ __device__ permutation_iterator(ElementIterator x, IndexIterator y)
Definition: permutation_iterator.h:151
Definition: iterator_facade.h:61
thrust is the top-level namespace which contains all Thrust functions and types.
Definition: addressof.h:14
Definition: permutation_iterator.h:120
Traits and metafunctions for reasoning about the traits of iterators.
A class which exposes a public interface for iterators.
__host__ __device__ permutation_iterator()
Definition: permutation_iterator.h:140
__host__ __device__ permutation_iterator< ElementIterator, IndexIterator > make_permutation_iterator(ElementIterator e, IndexIterator i)
Definition: permutation_iterator.h:205
__host__ __device__ permutation_iterator(permutation_iterator< OtherElementIterator, OtherIndexIterator > const &r, typename detail::enable_if_convertible< OtherElementIterator, ElementIterator >::type *=0, typename detail::enable_if_convertible< OtherIndexIterator, IndexIterator >::type *=0)
Definition: permutation_iterator.h:159