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