Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ typeid()

Name: Anonymous 2006-01-11 12:59

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: Anonymous 2006-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: Anonymous 2006-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.

Name: Anonymous 2006-01-15 11:48

>>42
seconded

Name: Anonymous 2006-01-15 15:16

Fine then.
Lets say that C++ can't acomplish that
using macros and templates.

In that case, how about overloading typeid?
I'm sure THAT's possible, right?

There is always more than one way to skin a cat.
Its just a matter of creativity
 

Name: Anonymous 2006-01-15 16:06

>>44
You are either mentally retarded or one of most persistent trolls evar.

Name: Anonymous 2006-01-15 17:59

>>44
Next up, there MUST be a way to solve the travelling sales person problem in linear time right?

Name: Anonymous 2006-01-15 19:45

>>44

And there MUST be a way to solve the halting problem, right?

Name: Anonymous 2006-01-15 20:13

ITT we will prove P != NP:

Name: Anonymous 2006-01-16 3:22

>>46
>>47
>>48
I love you guys.

Name: Anonymous 2006-01-16 4:29

>>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: Anonymous 2006-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!

C++ RULZ!!!

There MUST be a way. U guys just suck.

Name: Anonymous 2006-01-16 5:52 (sage)

>>50

Dammit, dude, stop feeding the troll.

Name: Anonymous 2006-01-16 7:46

>>52
I'm not a troll, I'm a C++ programmer!
HAH! SO THERE!

Name: Anonymous 2006-01-16 8:21 (sage)

>>51,53
lol

Name: Anonymous 2006-01-16 9:06

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: Anonymous 2006-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: Anonymous 2006-01-16 9:23

>>56
Yes but I meant that C could easily get a good macro language that recognises types, etc.

Name: Anonymous 2006-01-16 10:37 (sage)

>>57
Gee, that almost sounds like Objective C. Except not.

Name: Anonymous 2006-01-16 12:57

>>51
PRRRRRRROOOOOOOOOGGGGGGG

Name: Anonymous 2006-01-19 5:49

bump

Name: Anonymous 2006-01-19 7:16 (sage)

Mmmm, yummy, troll bumpage.

Name: Anonymous 2006-01-19 7:49 (sage)

Name: Anonymous 2006-02-02 3:37 (sage)

>>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: Anonymous 2010-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!

Name: Anonymous 2010-01-27 15:34

<<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: Anonymous 2010-01-27 15:58

Depending on what you want to do, this is possible using type_traits from the boost library.

Name: Anonymous 2010-01-27 16:05

>>65
what OP needs is clearly:
2006-01-11 12:59

Name: Anonymous 2010-01-28 5:00

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.

Name: Anonymous 2010-11-26 3:25

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List