title: Converting to different data types based on different template arguments
body: <p>I have two systems that I need to map types between - the source data fields, which can be numerical, chars, or strings, is all stored as string objects; the destination system needs a different data type for the underlying type of each data field, and I need to dynamically do this mapping.</p>
  
  <p>So basically, for each data field, I have the actual field string 's' and the type of the underlying data, 'type', and I am trying to convert to a type 'dest' based on 'type'. I've been trying to use templates and template constants to hack something that can do this, with no luck. </p>
  
  <p>The current try I have is the following, but this does not compile due to the conflicting return types:</p>
  
  <pre><code>template&lt;class CLASSTYPE, int CLASSID&gt;
  CLASSTYPE returnDifferentTypes()
  {
  using namespace std;
  
  if (CLASSID == 1) // 1 = "string"
      return std::string("returned string");
  
  if (CLASSID == 2) // 2 = int
      return 123;
  
  if (CLASSID == 3) // 3 = double 
      return 123.123;
  }
  </code></pre>
  
  <p>So I've been calling something like </p>
  
  <pre><code> string mapped = returnDifferentTypes&lt;string, 1&gt;()
  
  or 
    int mapped = returnDifferentTypes&lt;int, 2&gt;()
  </code></pre>
  
  <p>Can anyone recommend a smarter cleaner way to do this? Ideally I'm trying to return the appropriate return type with just a string representing the type to map it to. Thanks in advance.</p>