well , I'm building an automation platform and I want to be able to prompt the developer about the variable status and change.
basically , I want to write an all-encompassing "toString" function , with similar behavior like javascript.
I am using visual studio 2013 if it helps anyway.
Code:
the logic goes like this:
if the variable is a const char * / const wchar_t * / std :: string / std :: wstring - turn the string to wstring and print it
else if the variable is a char / int / long etc - print it as it
if the variable is a pointer - type it as T* <memory address> where T is the type name
now it gets trickier :
if the variable is a one-dimensional array of T or std::vector<T> and T is one of the types above - print it as [ array[0],array[1].. ] etc. - where array[i] is the value of the above
if the variable is object - just print it as "{object}"
if the variable is array of objects - print it as "[{obj}..{obj}]"
all the rest are pretty trivial with all sorts of type_traits functions (like is_pointer , is_object etc). but the vector/array thing is kinda tricky..
I know it may seems caprice at first , but this function is important for the completeness of the platform
now that I see it again , I can use std::is_same. so my question is purely theoretical now.
yes , I have thought about analyzing typeif :: name , I'll see if VC++ gives some human-readable strings for that