Andrei Alexandrescu wrote:
Christopher Wright wrote:
Andrei Alexandrescu wrote:
Christopher Wright wrote:
What information did you find that you needed but is not available
in TypeInfo?
To have constant-type dispatching without limitations you need the
static type information.
What do you mean by this? At first I thought you meant that TypeInfo
does not contain sufficient information to determine whether something
is const or immutable, but that is not the case. If you wish to
convert a Variant of a mutable thing to a const version of it, then
you can check whether the type you get is convertible, and without any
trouble -- the template instantiation to get the appropriate type will
provide the TypeInfo you need.
So what's the issue?
You may want to peruse the std.variant implementation. Variant is a
struct containing a buffer for the data and a pointer to function. The
function is a dispatcher for a handful of primitive operations.
The pointer to function is assigned from the address of a function
template. To get that address, you need the static type. That's the
necessity.
It's a very fast and very flexible design, but it does need the static
type during initialization.
Your Variant can be extended more easily than mine. Your Variant is
faster than mine. But yours cannot be used everywhere, and mine can.
Also, given that only a very few operations can ever be supported by
Variant, I think it's not a big deal if Variant never lets you do
anything interesting with the stored values besides boxing, unboxing,
equality testing, hashing, and any standard reflection stuff that is
available.
Andrei