|
Boost : |
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2008-08-18 06:23:46
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk