Topic: Can we check the actual data type in template?


Author: saito@orange.ridgefield.sdr.slb.com (Naoki Saito)
Date: 18 Nov 1994 21:20:20 GMT
Raw View
Hello!  I would like to know whether it is possible to check the data type
in the template constructs.  What I want to do can be described roughly
as follows:

template <class DT>
void f(DT x)
{
 switch (datatype of(DT)) // check what the actual DT is in the calling prog.
  {
   case "int":
     task_int(x);
     break;
   case "float":
     task_float(x);
     break;
   case "double":
     task_double(x);
     break;
 }
}

I asked this question before in comp.lang.c++. But I got only one answer
saying that it is possible to do in Ada, but not sure in C++.

I would greatly appreciate your help!
Best regards and thanks in advance,
--
===============================================================================
            Naoki Saito                         Schlumberger-Doll Research
Email: saito@ridgefield.sdr.slb.com             Old Quarry Road
Voice: (203) 431-5209  Fax: (203) 438-3819      Ridgefield, CT 06877 USA
===============================================================================