I have a template class, and would like to write a member method that's able to recognize what kind of type the template has been instantiated to.
I need to create a string identifier containing the following information on the type:
- bit depth
- signed or unsigned
- floating point or int or char
The method should return a string composed in the following way:
string: (BIT_DEPTH)-(U|S)-(C|I|F)
BIT_DEPTH -> is the number of bits used to represent type
U | S -> describes if type is signed or unsigned
C | I | F -> describes if type is char int or floating point
I thought of a way to find to bit depth:
int bitDepth = sizeof(TemplateType) * 8;
is it ok?
But have no idea on how to find the other information I need, unless a switch-case
statement like the following is ok (but don't think so):
THE FOLLOWING IS PSEUDO CODE THAT YOU SHOULD HELP ME EXPRESS IN A CORRECT SYNTAX
switch(TemplateType){
case signed: ...;
case unsigned: ...;
default: ...;
}
My questions are two:
- is bit depth calculation correct?
- is the
switch-case
statement a good idea? (if yes can you please correct the syntax)