I dun a DIP, possibly the best DIP ever
Adam D. Ruppe
destructionator at gmail.com
Fri May 8 15:48:22 UTC 2020
Another potential use for this would be writing type translation
functions.
I've written something along these lines many times:
ParameterTypeTuple!T fargs;
foreach(idx, a; fargs) {
if(idx == args.length)
break;
cast(Unqual!(typeof(a))) fargs[idx] =
args[idx].get!(typeof(a));
This converts arguments of a dynamic type to the static parameter
types of a given function in preparation to call it.
That ugly cast on the lhs there is to deal with const.
void foo(const int a) {}
That function there needs the cast to assign to the const param.
Well, with the static map, we MIGHT be able to just do
foo(fromDynamic(fargs, args.pop)...)
or something like that which expands in place so the mutable
thing is implicitly cast to const without the explicit cast
intermediate.
I haven't tried that btw i just think it might work given the
concept. That would be impossible with staticMap as-is because of
the runtime variable in there.
More information about the Digitalmars-d
mailing list