OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
discard_output_iterator.cuh
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2011, Duane Merrill. All rights reserved.
3 * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the NVIDIA CORPORATION nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 ******************************************************************************/
28
34#pragma once
35
36#include <iterator>
37#include <iostream>
38
39#include "../util_namespace.cuh"
40#include "../util_macro.cuh"
41
42#if (THRUST_VERSION >= 100700)
43 // This iterator is compatible with Thrust API 1.7 and newer
44 #include <thrust/iterator/iterator_facade.h>
45 #include <thrust/iterator/iterator_traits.h>
46#endif // THRUST_VERSION
47
48
50CUB_NS_PREFIX
51
53namespace cub {
54
55
65template <typename OffsetT = ptrdiff_t>
67{
68public:
69
70 // Required iterator traits
73 typedef void value_type;
74 typedef void pointer;
75 typedef void reference;
76
77#if (THRUST_VERSION >= 100700)
78 // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods
79 typedef typename thrust::detail::iterator_facade_category<
80 thrust::any_system_tag,
81 thrust::random_access_traversal_tag,
84 >::type iterator_category;
85#else
86 typedef std::random_access_iterator_tag iterator_category;
87#endif // THRUST_VERSION
88
89private:
90
91 OffsetT offset;
92
93#if defined(_WIN32) || !defined(_WIN64)
94 // Workaround for win32 parameter-passing bug (ulonglong2 argmin DeviceReduce)
95 OffsetT pad[CUB_MAX(1, (16 / sizeof(OffsetT) - 1))];
96#endif
97
98public:
99
101 __host__ __device__ __forceinline__ DiscardOutputIterator(
102 OffsetT offset = 0)
103 :
104 offset(offset)
105 {}
106
108 __host__ __device__ __forceinline__ self_type operator++(int)
109 {
110 self_type retval = *this;
111 offset++;
112 return retval;
113 }
114
116 __host__ __device__ __forceinline__ self_type operator++()
117 {
118 offset++;
119 return *this;
120 }
121
123 __host__ __device__ __forceinline__ self_type& operator*()
124 {
125 // return self reference, which can be assigned to anything
126 return *this;
127 }
128
130 template <typename Distance>
131 __host__ __device__ __forceinline__ self_type operator+(Distance n) const
132 {
133 self_type retval(offset + n);
134 return retval;
135 }
136
138 template <typename Distance>
139 __host__ __device__ __forceinline__ self_type& operator+=(Distance n)
140 {
141 offset += n;
142 return *this;
143 }
144
146 template <typename Distance>
147 __host__ __device__ __forceinline__ self_type operator-(Distance n) const
148 {
149 self_type retval(offset - n);
150 return retval;
151 }
152
154 template <typename Distance>
155 __host__ __device__ __forceinline__ self_type& operator-=(Distance n)
156 {
157 offset -= n;
158 return *this;
159 }
160
162 __host__ __device__ __forceinline__ difference_type operator-(self_type other) const
163 {
164 return offset - other.offset;
165 }
166
168 template <typename Distance>
169 __host__ __device__ __forceinline__ self_type& operator[](Distance n)
170 {
171 // return self reference, which can be assigned to anything
172 return *this;
173 }
174
176 __host__ __device__ __forceinline__ pointer operator->()
177 {
178 return;
179 }
180
182 __host__ __device__ __forceinline__ void operator=(self_type const& other)
183 {
184 offset = other.offset;
185 }
186
188 template<typename T>
189 __host__ __device__ __forceinline__ void operator=(T const&)
190 {}
191
193 __host__ __device__ __forceinline__ operator void*() const { return NULL; }
194
196 __host__ __device__ __forceinline__ bool operator==(const self_type& rhs)
197 {
198 return (offset == rhs.offset);
199 }
200
202 __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs)
203 {
204 return (offset != rhs.offset);
205 }
206
208 friend std::ostream& operator<<(std::ostream& os, const self_type& itr)
209 {
210 os << "[" << itr.offset << "]";
211 return os;
212 }
213
214};
215
216 // end group UtilIterator
218
219} // CUB namespace
220CUB_NS_POSTFIX // Optional outer namespace(s)
__host__ __device__ __forceinline__ bool operator==(const self_type &rhs)
Equal to.
__host__ __device__ __forceinline__ difference_type operator-(self_type other) const
Distance.
__host__ __device__ __forceinline__ void operator=(T const &)
Assignment to anything else (no-op)
__host__ __device__ __forceinline__ self_type & operator*()
Indirection.
__host__ __device__ __forceinline__ self_type operator++(int)
Postfix increment.
void reference
The type of a reference to an element the iterator can point to.
OffsetT difference_type
Type to express the result of subtracting one iterator from another.
__host__ __device__ __forceinline__ self_type & operator-=(Distance n)
Subtraction assignment.
__host__ __device__ __forceinline__ self_type operator++()
Prefix increment.
DiscardOutputIterator self_type
My own type.
__host__ __device__ __forceinline__ self_type & operator+=(Distance n)
Addition assignment.
friend std::ostream & operator<<(std::ostream &os, const self_type &itr)
ostream operator
void value_type
The type of the element the iterator can point to.
void pointer
The type of a pointer to an element the iterator can point to.
std::random_access_iterator_tag iterator_category
The iterator category.
__host__ __device__ __forceinline__ DiscardOutputIterator(OffsetT offset=0)
Constructor.
__host__ __device__ __forceinline__ bool operator!=(const self_type &rhs)
Not equal to.
__host__ __device__ __forceinline__ self_type operator+(Distance n) const
Addition.
__host__ __device__ __forceinline__ pointer operator->()
Structure dereference.
__host__ __device__ __forceinline__ self_type operator-(Distance n) const
Subtraction.
__host__ __device__ __forceinline__ self_type & operator[](Distance n)
Array subscript.
__host__ __device__ __forceinline__ void operator=(self_type const &other)
Assignment to self (no-op)
#define CUB_MAX(a, b)
Select maximum(a, b)
Optional outer namespace(s)
OffsetT OffsetT
[in] Total number of input data items