Does anyone know how typeid() is implemented in C++???
I mean, how do I make a function like typeid() where I can pass the TYPE as a paramter.
Example:
int main()
{
typeid(int);//<-- works of course
f(int);//<-- how to do something like this
// without using macros or templates
}
Name:
Anonymous2006-01-15 10:19
I don't know C++ but I googled 'c++ type argument' and there was much about templates and 'List<T>' and 'Template non-type arguments (C++ only)'. I will assume that C++ can take types as argument during compile time when macros and templates are being evaluated.
Name:
Anonymous2006-01-15 11:35
I hereby officially declare the OP or whomever continues insisting that "there must be a way" to be a troll. No non-troll would continue to be this stupid.
>>22
Lower level languages have less features like that. You can't expect to know implementation details at run time.
So you don't do that. If you need to, think again. If you *really* *really* *pretty really* need to, user a higher level language and be prepared for a performance loss which you usually can afford. I discourage Java, it sucks. Try Python.
Name:
Anonymous2006-01-16 5:43
>>50
Oh really?
If lower level languages
can't allow us to know implementation details at run time,
then how come typeid() does exactly that?
Come on man!
Lower level languages allows us to do MORE stuff
than higher level language.
Take JAVA and C++ for example.
JAVA can't communicate with hardware without C++ dlls.
HAH! SO THERE!
It's not whether the language is higher level or not. It just depends on whether the language has a good macro language (when the language is static type).
Name:
Anonymous2006-01-16 9:16
>>55
Lisp is the highest level language of them all. It also has the most powerful macros. In fact once you've used Lisp macros you wonder how you ever got along with all that shitty #define crap.
Name:
Anonymous2006-01-16 9:23
>>56
Yes but I meant that C could easily get a good macro language that recognises types, etc.
Name:
Anonymous2006-01-16 10:37 (sage)
>>57
Gee, that almost sounds like Objective C. Except not.
>>38
I have no idea why you want to do that anyways. Get over it. What about the data? Just overload your function if you want to be able to call it with different types. If you're working with Variant-style data, you've already got some kind of boost::any thing going on. Just keep using it.
Name:
Anonymous2010-01-27 14:41
#define int m_class
where m_class contains an integer, and type info about it.
I DID IT, I FIX'D THIS NECRO THREAD!
<<64 DONT DO THAT it breaks my SFINAE based metaprogramming reusable libraries depending on member method pointer overload resolution precedence differences between builtin and user defined types
what OP needs is clearly:
1: get a list of all used types (for example: A,B,C,D,...)
2:
/*returns the type, as string*/ template<T*> std::string typeID(T* buio){return dynamic_cast<A*>(buio)?"A":(dynamic_cast<B*>(buio)?"B":(dynamic_cast<C*>(buio)?"C":(dynamic_cast<D*>(buio)?"D":(dynamic_cast<E*>(buio)?"E":(/*more of this, also dont forget additional FV-izeation for production code*/)))));}
Name:
Anonymous2010-01-27 15:58
Depending on what you want to do, this is possible using type_traits from the boost library.
Either:
#define f(x) _f(typeid(*x))
void f(type_info t) { /* stuff */ }
or
#define f(x) _f<x>()
template<class F>
void f() { /* stuff */ };
but you should probably stick to vanilla templates to avoid confusion unless you really need to confuse things.