TypeInfoEx and Variant: suggestions?
Christopher Wright
dhasenan at gmail.com
Thu Apr 16 17:13:41 PDT 2009
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.
More information about the Digitalmars-d
mailing list