Simply make T
another template parameter of add_vector_to_scalar
:
template<typename Vector, typename Scalar>
void add(const Vector& in, Vector& out, const Scalar& c) {
transform(in.begin(), in.end(), out.begin(), add_op<Scalar>(c));
}
Note that I changed the in
and c
parameters to be taken as const &
- as they're input-only parameters, you don't want to (be able to) modify them inside the function. And taking them as const &
allows temporaries to be passed in, which is not possible with non-const references.