Compiler as dll

Bill Baxter wbaxter at gmail.com
Fri Jan 30 12:21:49 PST 2009


On Fri, Jan 30, 2009 at 11:35 PM, Daniel Keep
<daniel.keep.lists at gmail.com> wrote:
>
>> Out of curiosity, does anyone actually use Variant in D?  When I was new to the
>> language, I thought it was a great idea, but then I discovered D templates, so now
>> I never use it.
>
> The only case where I've really used it* was, not coincidentally, the
> reason I wrote it in the first place: a generalised CVar system for a
> game engine.
>
> Really, you can pretty easily get away with never needing it.  If you
> want runtime polymorphism and you're only storing class instances, then
> you can just use Object instead.  Variant is really only useful if you
> want to store non-class types as well without having to Box them, or you
> really want value semantics.
>
> Still, it's cool that it works as well as it does... :D
>
>  -- Daniel
>
>
> * I'm referring to Tango's Variant, not Phobos'.

Does Tango's Variant have a fixed type?
It seems the std2 Variant doesn't really care what the type of the
thing you stuff in it is, as long as it fits in the memory space
allotted.   How is that useful?   What's the use case for needing
something that can be either 2.4f or "fred"?    (Sorry I don't know
what a "CVar" system is...)   What I actually needed was something
with a fixed, internal type that could expose its value in a flexible
way via templated get/set routines.  But for me a float property is
never going to mutate into a string property.

--bb



More information about the Digitalmars-d mailing list