title: Deducing the base type from a template parameter
body: <p>Visual Studio 2017, C++ with C++17</p>
  
  <p>Is there any way to use a template parameter and deduce the base type?</p>
  
  <p>Example: If the template parameter is <code>std::string</code> I want to declare a <code>char</code> inside the function.
  If the template parameter is <code>std::basic_string&lt;unsigned char&gt;</code> I want to declare an <code>unsigned char</code> inside the function:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;typeinfo&gt;
  
  using namespace std;
  
  typedef unsigned char uchar;
  typedef basic_string&lt;uchar&gt; ustring;
  
  template &lt;typename str&gt;
  void exampleFunc(vector&lt;str&gt; &amp;vec)
  {
      // Pseudo-code to be evaluated at ***compile time***
      if (typeof(str) == ustring)
          uchar c;
      if (typeof(str) == string)
          char c;
  
      // ... code ...
  }
  int main()
  {
      vector&lt;string&gt; vec;
      vector&lt;ustring&gt; uvec;
  
      exampleFunc(vec);
      exampleFunc(uvec);
  }
  </code></pre>