title: Iterating over a tuple by index in c++17 on MSVC?
body: <p>I need to be able to iterate through a tuple at compile time, while having access to the index, in a cross-platform code. Ideally I could do it like so:</p>
  <pre><code>#include&lt;tuple&gt;
  #include &lt;array&gt;
      
  struct A { int val() { return 1; } };
  struct B { 
    int v;
    B( int v): v(v) {};
    int val() { return  v * 2; } 
  };
  
  int main() {
      auto arr = std::array&lt;int,3&gt;{};
      auto t   = std::tuple&lt;A,A,B&gt; {A{}, A{}, B{7}};
      
      // set each elem in arr with the result of the corresponding elem in
      // t's val() call
      [&amp;]&lt;size_t ... d&gt;(std::index_sequence&lt;d...&gt;) {
        ((arr[d] = std::get&lt;d&gt;(t).val()),...);
      }(std::make_index_sequence&lt;3&gt;());
  }
  
  </code></pre>
  <p>However, this doesn't compile on MSVC with std=c++17, but does on GCC and clang. Godbolt <a href="https://godbolt.org/z/vGzKs6jzE" rel="nofollow noreferrer">link</a>.</p>
  <p>I have also considered <code>std::apply</code>, but AFAIK I can't have access to the index (unless I fold my <code>tuple</code> with an <code>index_sequence</code> somehow?). If I can't do it nicely with fold expressions, my next option seems to be compile time recursion, but this seems very unweildy, especially if I can't use lambda function templates because c++17.</p>
  <p>Before I go down this route and make my code very ugly, is there a nice, idiomatic way to do what I want to do that I'm missing?</p>
  <p>If it matter, in the full code, the size of the array and tuple, are template parameters, as are the tuple types (they all derive from a base class though).</p>