title: Using initializer_list in template function
body: <p>I am trying to use a function template <code>foo</code> to convert arguments to a <code>initializer_list</code>. However, the <code>initializer_list</code> it converted has strange values which are not the same as the input arguments.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  template&lt;class T&gt;
  void func(std::initializer_list&lt;T&gt; a_args)
  {
      if (a_args.begin() != a_args.end())
      {
          auto last = prev(a_args.end());
          copy(a_args.begin(), last, ostream_iterator&lt;int&gt;(cout, ","));
          cout &lt;&lt; *last;
      }
      cout &lt;&lt; endl;
  }
  
  template&lt;class T, class ...Args&gt;
  struct first_of
  {
      typedef T type;
  };
  
  template&lt;class ...Args&gt;
  initializer_list&lt;typename first_of&lt;Args...&gt;::type&gt; foo(Args&amp;&amp;... args)
  {
      return { forward&lt;Args&gt;(args)... };
  }
  
  int main()
  {
      func({1,2,3});
      auto x = foo(1,2,3);
      func(x); //this should be the same as func({1,2,3}) but not.
  }
  </code></pre>
  
  <p><a href="http://coliru.stacked-crooked.com/a/b48381daeb329646" rel="nofollow">LIVE CODE</a></p>
  
  <p>The ouput is as follows:</p>
  
  <pre><code>1,2,3
  -326483696,32767,0
  </code></pre>
  
  <p>What is wrong here?</p>