title: Insert/get tuple into/from vector of tuples
body: <p>I'm trying to insert/get a tuple into/from a vector of tuples and came up with the following code snippet. It works fine, but I'm not entirely happy with it.
  Can anyone think of a more elegant solution? Is it possible to generalize the 'for_each_in_tuple_and_arg' function into a 'for_each_in_tuples' function?
  PS: I'm stuck with a C++14 compiler...</p>
  <pre><code>#include &lt;tuple&gt;
  #include &lt;vector&gt;
  #include &lt;utility&gt;
  
  template &lt;std::size_t I = 0, class Fn, class Tuple&gt;
  constexpr typename std::enable_if
      &lt;I == std::tuple_size&lt;Tuple&gt;::value, void&gt;::type
  for_each_in_tuple(Fn&amp;&amp;, Tuple&amp;) {}
  
  template &lt;std::size_t I = 0, class Fn, class Tuple&gt;
  constexpr typename std::enable_if
      &lt;I != std::tuple_size&lt;Tuple&gt;::value, void&gt;::type
  for_each_in_tuple(Fn&amp;&amp; fn, Tuple&amp; tup)
  {
      fn(std::get&lt;I&gt;(tup));
      for_each_in_tuple&lt;I + 1&gt;(fn, tup);
  }
  
  template &lt;std::size_t I = 0, class Fn, class Tuple, class Arg&gt;
  constexpr typename std::enable_if
      &lt;I == std::tuple_size&lt;Tuple&gt;::value, void&gt;::type
  for_each_in_tuple_and_arg(Fn&amp;&amp;, Tuple&amp;, const Arg&amp;) {}
  
  template &lt;std::size_t I = 0, class Fn, class Tuple, class Arg&gt;
  constexpr typename std::enable_if
      &lt;I != std::tuple_size&lt;Tuple&gt;::value, void&gt;::type
  for_each_in_tuple_and_arg(Fn&amp;&amp; fn, Tuple&amp; tup, const Arg&amp; arg)
  {
      fn(std::get&lt;I&gt;(tup), std::get&lt;I&gt;(arg));
      for_each_in_tuple_and_arg&lt;I + 1&gt;(fn, tup, arg);
  }
  
  class tuple_of_vectors
  {
  public:
      using tov_type = std::tuple&lt;
          std::vector&lt;int&gt;, std::vector&lt;int&gt;, std::vector&lt;int&gt;&gt;;
  
      using value_type = std::tuple&lt;int, int, int&gt;;
  
      void reserve(std::size_t n)
      {
          auto fn = [n](auto&amp; vec){ vec.reserve(n); };
          for_each_in_tuple(fn, tov_);
      }
  
      value_type at(std::size_t n) const noexcept
      {
          value_type res{};
          auto fn = [n](auto&amp; val, const auto&amp; vec)
              { val = vec.at(n); };
          for_each_in_tuple_and_arg(fn, res, tov_);
          return res;
      }
  
      void insert(const value_type&amp; tup)
      {
          std::size_t n = 0;
          auto fn = [n](auto&amp; vec, const auto&amp; val)
              { vec.insert(vec.cbegin() + n, val); };
          for_each_in_tuple_and_arg(fn, tov_, tup);
      }
  
      tov_type tov_;
  };
  </code></pre>