title: Using templated function to read numbers from CSV file
body: <p>I'm wondering if there is an elegant way of writing a single function that reads list of numbers (int or double) into a vector using a templated function?</p>
  
  <p>Here is what I usually do:</p>
  
  <pre><code>template&lt;class VecType&gt;
  vector&lt;VecType&gt; read_vector(const string&amp; file){
      vector&lt;VecType&gt; vec;
  
      ifstream indata;
      indata.open(file);
  
      string line;    
  
      while (getline(indata, line)) {
          stringstream lineStream(line);
          string cell;
          while (std::getline(lineStream, cell, ',')) {
              vec.push_back(stod(cell));
          }        
      }
  
      indata.close();
  
      return vec;
  }
  </code></pre>
  
  <p>My problem is with the <code>stoi</code> or <code>stod</code> part. How to handle this nicely here?</p>
  
  <p>What I usually do, is to use <code>stod</code> and let the conversion happen automatically from <code>double</code> to <code>int</code> if the <code>VecType</code> is <code>int</code> for example. But there should be much better way to do this, right?</p>