This is similar to the previous question I asked but it is concerning a templated vector component-wise addition function.
I have a function called add
which takes two vectors and stores their addition in an output vector. I am learning c++ so I am not sure how to make the type parameter to thrust::plus
generic? The problem is that T
is the type parameter for both device_vector
and host_vector
; which should be a type parameter for Vector
.
template<typename Vector, typename T>
void add(const Vector& in1, const Vector& in2, Vector& out) {
transform(in1.begin(), in1.end(), in2.begin(), out.begin(), thrust::plus<T>(c));
}
The vector could be of two type:
device_vector<T>
host_vector<T>
My code doesn't compile as it is complaining about:
error: no instance of function template "add" matches the argument list
How can I play the plus function generic so it easily works with T
of either device_vector<T>
or host_vector<T>
?