Getting the size of a type tuple
David Zhang
straivers98 at gmail.com
Thu Sep 21 18:44:45 UTC 2017
Given the function F, where: F(Args...)(Args args) { ... }
How can I statically determine the size of the argument list in
bytes?
Preferably, I would like a one-liner. However, std.algorithm
doesn't seem to support tuples, or `Args.each!(T =>
T.sizeof).sum` would work.
For the moment, I've settled on using a helper function:
size_t size(Args...)()
{
size_t size;
foreach(Arg; Args)
size += Arg.sizeof;
return size;
}
But it's a bit clunky. Is there a more idiomatic way to do this?
Thanks
More information about the Digitalmars-d-learn
mailing list