I have following piece of code.
#include <iostream>
#include <type_traits>
typedef char stringType1;
typedef char stringType2;
typedef enum
{
myType_noType, // 0
myType_stringType1, // 1
myType_stringType2 // 2
} MyDataType_t;
//TYPE CHECK
template <typename T>
constexpr MyDataType_t TYPE_NAME(T x)
{
if constexpr (std::is_same<decltype(x),stringType1>::value){return myType_stringType1;}
if constexpr (std::is_same<decltype(x),stringType2>::value){return myType_stringType2;}
return myType_noType;
}
template <typename T>
MyDataType_t myFunction(T *value)
{
return TYPE_NAME(*value);
}
int main()
{
std::cout<<"Hello World"<< std::endl;
stringType1 var1;
stringType2 var2;
MyDataType_t aTypeId = myFunction(&var1);
std::cout << aTypeId << std::endl;
aTypeId = myFunction(&var2);
std::cout << aTypeId << std::endl;
return 0;
}
Running this piece of code gives following result:
Hello World
1
1
So it looks like I have variables of different types that cannot be recognized properly during runtime.
And there is a question: is there any way we could distinguish these types as different?