TypeInfoEx and Variant: suggestions?

dsimcha dsimcha at yahoo.com
Thu Apr 16 17:54:49 PDT 2009


== Quote from Christopher Wright (dhasenan at gmail.com)'s article
> Hi all,
> I finally found some time to work on TypeInfoEx. It's usable, in that
> you can view information about a type; but you can't do anything with
> that information. One large barrier is the lack of a usable Variant type.
> To invoke a function on an object or struct, you need to pass it as
> either Object or void* or Variant.
> If you invoke a function, you want to pass in an array of Variant for
> the arguments. You want to get the return type as a Variant.
> If you get a field, you want to get it as a Variant.
> You could use templates instead, but that's not usable in many
> situations, so I won't have that as the only option.
> Andrei's std.variant has an interesting design, but it has two flaws
> that render it unusable:
>   - It cannot be used with structs of arbitrary size. It's parameterized
> on size, but no size will always be sufficient; and due to its
> allocation scheme, choosing to support (for instance) 1KB structs will
> force a bool to take 1KB.
>   - It cannot be created with RTTI; it requires compile-time type
> information.
> So, my options are:
>   - Write my own Variant supporting the necessary operations. This makes
> things annoying for anyone wanting to use my code with Phobos, since now
> there are two Variant structs running around.
>   - Use std.boxer, which is deprecated.
>   - Pass around an opaque Pair!(TypeInfo, void*).
> Any suggestions? I've written such a Variant for D1 and Tango, but I
> relish neither the idea of supporting both with the same class, nor code
> duplication.

Andrei has said that he would like to fix std.variant to support arbitrary sized
stuff, but just doesn't have time right now.  If you are able and willing, submit
a patch.  If it's decent, it will probably be accepted.  If you don't have time or
don't want to, someone who does should submit one since this seems to be something
a lot of people want.  I've looked at doing this before, and I'd be willing to
step up and submit a patch after some of my coursework dies down and I have more
free time (fairly soon), if noone else gets around to it before then.



More information about the Digitalmars-d mailing list