title: Template functions to check "is int"/"is double"/etc
body: <p>I am a bit shaky with C++ template syntax, so I'm not sure if what I'm envisioning is possible, and if it is, I'm unclear on correct syntax.</p>
  
  <p>I would like to implement template functions like <code>template&lt;int&gt; bool is( std::string&amp; )</code>, <code>template&lt;double&gt; bool is( std::string&amp; )</code>, etc. so that I can call <code>is &lt;int&gt; (...)</code> or <code>is &lt;double&gt; (...)</code> instead of <code>isInt(...)</code> or <code>isDouble(...)</code>, etc. Is this possible? If so, how would you code the function signatures?</p>
  
  <p>With my tenuous grasp of template syntax, my attempt was:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  
  template&lt;int&gt;
  bool is( std::string&amp; raw )
  {
      if ( raw.empty() ) return false;
      char* p;
      int num = strtol( raw.c_str(), &amp;p, 10);
      return ( ( *p != '\0' ) ? false : true );
  }
  
  int main( int argc, char* argv[] )
  {
      std::string str("42");
      std::cout &lt;&lt; std::boolalpha &lt;&lt; is &lt;int&gt; ( str ) &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>This failed with the following errors:</p>
  
  <pre><code>&gt;g++ -g main.cpp
  main.cpp: In function ‘int main(int, char**)’:
  main.cpp:16:51: error: no matching function for call to ‘is(std::string&amp;)’
       std::cout &lt;&lt; std::boolalpha &lt;&lt; is &lt;int&gt; ( str ) &lt;&lt; std::endl;
                                                     ^
  main.cpp:5:6: note: candidate: template&lt;int &lt;anonymous&gt; &gt; bool is(std::string&amp;)
   bool is( std::string&amp; raw )
        ^
  main.cpp:5:6: note:   template argument deduction/substitution failed:
  </code></pre>