On Wednesday, 28 June 2017 at 05:52:38 UTC, Dmitry Solomennikov
wrote:
On Wednesday, 28 June 2017 at 05:01:17 UTC, Eugene Wissner
wrote:
On Wednesday, 28 June 2017 at 04:41:25 UTC, Dmitry
Solomennikov wrote:
Probably if you have serialized data, you convert strings to
other types, so it may be possible to perfom if-checks:
if (myDataIsStringAndDouble(data))
{
auto var = new Some!(Pair!(string, double))(new
Pair!(string, double)("df", 5.0));
}
else if (myDataIsStringAndInt(data))
{
auto var = new Some!(Pair!(string, int))(new Pair!(string,
int)("df", 5));
}
It is possible, but it is not a general solution. I've posted
couple of sample classes, but there are more complicated cases,
of course, and it well be combinatorial explosion here.
I got the Variant idea, I'll give it a try.
From other point of view, is there a reflection, say
auto i = newInstance("Pair!(int, string)(10, \"asdf\")"),
something like in Java?
As far as I know, Java can modify the byte code at runtime. D is
a compiled language. It has good compile-time reflection. Anyway
you have to find a way to initialize the classes with the types
you need. If the type isn't initialized at compile-time, it isn't
just there at runtime and can't be used.