Is std.variant useful for types only known at run time?

Chris Piker chris at hoopjump.com
Wed Sep 8 07:10:21 UTC 2021


Hi D

I'm working on data streaming reading module where the encoding 
of each input array isn't known until runtime.  For example 
date-time column values may be encoded as:

    * An ISO-8601 UTC time string (aka char[])
    * A ASCII floating point value with an indicated unit size and 
epoch (aka char[])
    * A IEEE double with an indicated endianness, unit size, and 
epoch. (aka double[])
    * A 64-bit signed in with an indicated endianness, unit size, 
and epoch. (aka long[])

My job when encountering a date-time array in the stream is to 
just to properly convert the info into a broken down time 
structure, regardless of the encoding.

Initially I've been reading chunks of the stream into a `ubyte[]` 
and then using `cast` and `to` as needed, but then I stumbled 
across std.variant which can hold any type.

I'm wondering if std.variant is useful in cases where type 
information is only known at run-time, since many of the flexible 
data structures I've run across so far in D require compile-time 
information.

Thanks,


More information about the Digitalmars-d-learn mailing list