title: How do I get the type of the elements in a vector?
body: <p>Considering template metaprogramming techniques if I have</p>
  
  <pre><code>std::vector&lt;int&gt; v;
  v.push_back(42.42f);
  </code></pre>
  
  <p>this works, mainly because the constructor being used it's not marked <code>explicit</code>, in other words my <code>push_back</code> it's not type safe.</p>
  
  <p>Now I'm in a situation where I don't even know how a container <code>v</code> is declared, in this case it's <code>int</code>, but I need to deduce the type automatically while having a generic <code>std::vector&lt;T&gt;</code>. I would like a solution to get <code>T</code>.</p>
  
  <p>in C++11 there is something like <a href="http://en.cppreference.com/w/cpp/types/remove_all_extents" rel="noreferrer"><code>remove_all_extents</code></a> ( with an useful member <code>type</code> ) but apparently it's only useful for the old arrays, but it's basically what I would like to achieve.</p>
  
  <p>I would like to trigger an error when the <code>push_back</code> it's not type safe or deduce the type so I can write an assertion or implement something on my own.</p>
  
  <p>I really can't find a working solution for this, it's so simple in theory, but once a vector is declared there is no explicit information about the type used for the elements.</p>
  
  <p>I also would like to avoid explicit type inference, like translating <code>foo</code> from my ideal function call</p>
  
  <pre><code>foo( container, elements ... )
  </code></pre>
  
  <p>to</p>
  
  <pre><code>foo&lt;int&gt;(container, elements ...)
  </code></pre>
  
  <p>where <code>int</code> is the type for the elements of <code>container</code>, this is not safe too in my opinion, it's also more verbose and error prone.</p>
  
  <p>So how do I retrieve the type for the elements of a container in C++11 ?</p>