Template shenannigans with multiple datatypes
frame
frame86 at live.com
Fri May 13 15:08:50 UTC 2022
On Friday, 13 May 2022 at 07:32:16 UTC, Chris Katko wrote:
> This is a kinda "dynamic language" feature but it feels like
> this information is theoretically, knowable at static,
> compile-time. I know what the variable types will be at
> compile-time, but I don't know how to put them all in one class
> and reference them automatically.
Like `std.json.JSONValue` or `std.variant.Variant` you can also
use a struct with a type flag and possible data types that fit
for you. Boolean and Integer may share the same memory location
via `union` for example. Or just use the built one `Variant` type.
In case you only store the pointers to the data, you just need
`void*[]` and proper casting.
More information about the Digitalmars-d-learn
mailing list