Serialization/deserialization of templated class

Dmitry Solomennikov via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 27 22:52:38 PDT 2017


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?


More information about the Digitalmars-d mailing list