title: How to test the type contained in a map
body: <p>Say I had a template function that calculates the sum of a map's elements like this:</p>
  
  <pre><code>template &lt;class A, class B&gt; double Total(const map&lt;A, B&gt;&amp; cntr)
  {
      map&lt;A, B&gt;::const_iterator iter;
      double total = 0;
  
      for (iter = cntr.begin(); iter != cntr.end(); ++iter)
          total += iter-&gt;second;
  
      return total;
  }
  </code></pre>
  
  <p>It would work fine whenever B was a numeric type; however, obviously if you passed in a reference to something like <code>map&lt;int, string&gt;</code>, it wouldn't work.</p>
  
  <p>I was wondering how I could test the type contained in the non-key section of the map so I can through an exception or something. I tried using isdigit() but couldn't seem to get a working version.</p>
  
  <p>EDIT: My intended use of the test would be to add functionality so that the int type is always used to calculate the total, so I can pass in <code>map&lt;int, string&gt;</code> or <code>map&lt;string, int&gt;</code> and it will always calculate the int types.</p>