I have a function called add_vector_to_scalar
which adds a scalar value to a vector (in
) and stores the result in another vector (out
). I am learning C++ so I am not sure how to make the type parameter to add_op generic
? I thought about adding another typename T
but it did not work.
template<typename Vector>
void add(Vector& in, Vector& out, T& c) {
transform(in.begin(), in.end(), out.begin(), add_op<int>(c));
}
The vector could be of two type:
device_vector<T>
host_vector<T>
The add_op
struct looks like this:
template<typename T>
struct add_op : public thrust::unary_function<T,T> {
const T c;
add_op(T v) : c(v) {}
__host__ __device__
T operator()(const T x) {
return x + c;
}
};