@@ -94,54 +94,40 @@ THRUST_DECLTYPE_RETURNS(
94
94
* #include <thrust/zip_function.h>
95
95
*
96
96
* struct SumTuple {
97
- * float operator()(Tuple tup) {
98
- * return std ::get<0>(tup) + std ::get<1>(tup) + std ::get<2>(tup);
97
+ * float operator()(auto tup) const {
98
+ * return thrust ::get<0>(tup) + thrust ::get<1>(tup) + thrust ::get<2>(tup);
99
99
* }
100
100
* };
101
101
* struct SumArgs {
102
- * float operator()(float a, float b, float c) {
102
+ * float operator()(float a, float b, float c) const {
103
103
* return a + b + c;
104
104
* }
105
105
* };
106
106
*
107
107
* int main() {
108
- * thrust::device_vector<float> A(3) ;
109
- * thrust::device_vector<float> B(3) ;
110
- * thrust::device_vector<float> C(3) ;
108
+ * thrust::device_vector<float> A{0.f, 1.f, 2.f} ;
109
+ * thrust::device_vector<float> B{1.f, 2.f, 3.f} ;
110
+ * thrust::device_vector<float> C{2.f, 3.f, 4.f} ;
111
111
* thrust::device_vector<float> D(3);
112
- * A[0] = 0.f; A[1] = 1.f; A[2] = 2.f;
113
- * B[0] = 1.f; B[1] = 2.f; B[2] = 3.f;
114
- * C[0] = 2.f; C[1] = 3.f; C[2] = 4.f;
115
112
*
116
- * // The following four invocations of transform are equivalent
113
+ * auto begin = thrust::make_zip_iterator(thrust::make_tuple(A.begin(), B.begin(), C.begin()));
114
+ * auto end = thrust::make_zip_iterator(thrust::make_tuple(A.end(), B.end(), C.end()));
115
+ *
116
+ * // The following four invocations of transform are equivalent:
117
117
* // Transform with 3-tuple
118
- * thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(A.begin(), B.begin(), C.begin())),
119
- * thrust::make_zip_iterator(thrust::make_tuple(A.end(), B.end(), C.end())),
120
- * D.begin(),
121
- * SumTuple{});
118
+ * thrust::transform(begin, end, D.begin(), SumTuple{});
122
119
*
123
120
* // Transform with 3 parameters
124
121
* thrust::zip_function<SumArgs> adapted{};
125
- * thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(A.begin(), B.begin(), C.begin())),
126
- * thrust::make_zip_iterator(thrust::make_tuple(A.end(), B.end(), C.end())),
127
- * D.begin(),
128
- * adapted);
122
+ * thrust::transform(begin, end, D.begin(), adapted);
129
123
*
130
124
* // Transform with 3 parameters with convenience function
131
- * thrust::zip_function<SumArgs> adapted{};
132
- * thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(A.begin(), B.begin(), C.begin())),
133
- * thrust::make_zip_iterator(thrust::make_tuple(A.end(), B.end(), C.end())),
134
- * D.begin(),
135
- * thrust::make_zip_function(SumArgs{}));
125
+ * thrust::transform(begin, end, D.begin(), thrust::make_zip_function(SumArgs{}));
136
126
*
137
127
* // Transform with 3 parameters with convenience function and lambda
138
- * thrust::zip_function<SumArgs> adapted{};
139
- * thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(A.begin(), B.begin(), C.begin())),
140
- * thrust::make_zip_iterator(thrust::make_tuple(A.end(), B.end(), C.end())),
141
- * D.begin(),
142
- * thrust::make_zip_function([] (float a, float b, float c) {
143
- * return a + b + c;
144
- * }));
128
+ * thrust::transform(begin, end, D.begin(), thrust::make_zip_function([] (float a, float b, float c) {
129
+ * return a + b + c;
130
+ * }));
145
131
* return 0;
146
132
* }
147
133
* \endcode
@@ -153,9 +139,13 @@ template <typename Function>
153
139
class zip_function
154
140
{
155
141
public:
142
+ // ! Default constructs the contained function object.
143
+ zip_function () = default ;
144
+
156
145
/* ! Constructs a \p zip_function with the provided function object \p func. */
157
- THRUST_HOST_DEVICE
158
- zip_function (Function func) : func(std::move(func)) {}
146
+ THRUST_HOST_DEVICE zip_function (Function func)
147
+ : func(std::move(func))
148
+ {}
159
149
160
150
/* ! Applies the N-ary function object to elements of the tuple \p args. */
161
151
// Add workaround for decltype(auto) on C++11-only compilers:
@@ -183,6 +173,12 @@ class zip_function
183
173
184
174
#endif // THRUST_CPP_DIALECT
185
175
176
+ // ! Returns a reference to the underlying function.
177
+ THRUST_HOST_DEVICE Function& underlying_function () const
178
+ {
179
+ return func;
180
+ }
181
+
186
182
private:
187
183
mutable Function func;
188
184
};
0 commit comments