title: Is it possible for a function to only accept a limited set of types for a given argument?
body: <p>I know how to do it with any data type with template:</p>
  
  <pre><code>template&lt;typename T&gt;
  T myFunc(T data) { ... }
  </code></pre>
  
  <p>But is there a way to narrow the set of allowed types to for example <code>int</code> and <code>char</code> or <code>std::string</code> and <code>std::wstring</code>, so the compiler would throw an error when encountering not allowed argument type and I will get error on compile time instead of run time ?</p>
  
  <p>edit: Big thanks to ecatmur, now I understand the whole concept.</p>
  
  <pre><code>template&lt;typename itemA_type, typename itemB_type&gt;
  typename std::enable_if&lt;
    (
      std::is_same&lt;itemA_type, int&gt;::value ||
      std::is_same&lt;itemA_type, char&gt;::value) &amp;&amp;
    (
      std::is_same&lt;itemB_type, std::string&gt;::value ||
      std::is_same&lt;itemB_type, std::wstring&gt;::value ||
      std::is_same&lt;itemB_type, const char*&gt;::value ||
      std::is_same&lt;itemB_type, const wchar_t*&gt;::value
    ) ,
    void
  &gt;::type
  myFunction(itemA_type itemA, itemB_type itemB) {
    using namespace std;
    cout &lt;&lt; itemA &lt;&lt; itemB &lt;&lt; endl;
  }
  </code></pre>