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