Identification library preliminary version

Hello all, I've uploaded a preliminary version of my type identification library into the vault (identification-v.01.zip) It's the current implementation of my type debugging facility that provides a simple function and class to build at run-time a human readable string containing the name of its type arguments. Identification supports a simple way to register user-defined types into itself. Samples and documentation are provided. It has been tested on g++ v4+ (both linux and windows) and on MSVC 2008 with equal success. Test on other platform and compiler are welcome as well as general comments on the interface or implementation choices. Thanks in advance.

joel falcou wrote:
It's the current implementation of my type debugging facility that provides a simple function and class to build at run-time a human readable string containing the name of its type arguments. Identification supports a simple way to register user-defined types into itself.
Why at runtime? Mangling/Unmangling a compile-time string at compile-time is perfectly doable and would be fairly useful, since it would allow constant-time visitation over std::type_info&.

Mathias Gaunard wrote:
Why at runtime? Mangling/Unmangling a compile-time string at compile-time is perfectly doable Well, I had a first compile-time version but its compilation time was really long (read over a couple of second per type_of call) and made it unusbale as a debugging purpose.
and would be fairly useful, since it would allow constant-time visitation over std::type_info&. I'm afraid I don't fully understand what you're implying. Would you mind elaborate on this point ?

joel falcou wrote:
and would be fairly useful, since it would allow constant-time visitation over std::type_info&. I'm afraid I don't fully understand what you're implying. Would you mind elaborate on this point ?
You could generate nested switches to identify what type std::type_info::name is within a finite set of possibilities. That allows identification to be done in constant-time. Imagine identifying whether type_info is "a" or "aa" for example. switch(type.name()[0] { case 'a': switch(type.name()[1]) { case 0: return f(*reinterpret_cast<a*>(ptr)); case 'a': switch(type.name()[2]) { case 0: return f(*reinterpret_cast<aa*>(ptr)); default: assert(0); } default: assert(0); } default: assert(0); } If you have the mangled names at compile-time, it is possible to generate that kind of automaton automatically.

Mathias Gaunard wrote :
You could generate nested switches to identify what type std::type_info::name is within a finite set of possibilities. That allows identification to be done in constant-time.
Imagine identifying whether type_info is "a" or "aa" for example. <snip code> If you have the mangled names at compile-time, it is possible to generate that kind of automaton automatically.
Well, I already generate such structure at compile time using type traits based decomposition and tag dispatching. The "runtime" part is just acually feeding all parts of the type name string description (volatile, const, repetition of *, array extent etc) to the ostringstream. I don't think using type_info is a better solution as its output depends on compiler and are sometimes non-existant.
participants (2)
-
joel falcou
-
Mathias Gaunard