Christopher Wright Wrote: > Justin Johansson wrote: > > I've had a good poke around the forums and couldn't find anything on this > > so ... > > > > What's the recommended method for dispatching code off the runtime type of > > a variant variable > > (Phobos D2 std.variant)? > > > > Does one use a bunch of > > > > if ( var.peek!(type1)) { ... } > > else if ( var.peek!(type2) { ... } > > > > for all N possible types, or is there a better & faster way with a switch > > or jump table of sorts? > > Variant should have an accessible typeinfo property. (When I say should, > I mean that it would be appropriate for it to have it. I am not saying > that I believe it has it.) It should be faster to compare that (or > switch on typeinfo.name) than to peek for each type.
Thanks, there is and I was considering that. TypeInfo type() { TypeInfo result; fptr(OpID.getTypeInfo, null, &result); return result; } Would you need a full char-by-char string compare or could you cook it on the basis of a string memory address == comparison? (Sorry, I'm a veteran C++'er not a fully-fledged D'er yet).