Re: Getting the size of a type tuple

2017-09-21 Thread ag0aep6g via Digitalmars-d-learn
On 09/21/2017 09:59 PM, H. S. Teoh wrote: On Thu, Sep 21, 2017 at 09:49:14PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] 3) Declaring a packed struct in a function literal that gets immediately called: enum size_so_very_clever(Types ...) = () { struct S { align(1) Types

Re: Getting the size of a type tuple

2017-09-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 21, 2017 at 09:49:14PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] > 3) Declaring a packed struct in a function literal that gets > immediately called: > > enum size_so_very_clever(Types ...) = () { > struct S { align(1) Types fields; } > return S.sizeof; > } ();

Re: Getting the size of a type tuple

2017-09-21 Thread David Zhang via Digitalmars-d-learn
On Thursday, 21 September 2017 at 19:49:14 UTC, ag0aep6g wrote: I don't have a one-liner, but here are some other solutions that might be interesting. None of them is particularly pretty, though. 1) Recursive template: 2) Using the std library: 3) Declaring a packed struct in a function

Re: Getting the size of a type tuple

2017-09-21 Thread ag0aep6g via Digitalmars-d-learn
On 09/21/2017 08:44 PM, David Zhang wrote: 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 =>

Getting the size of a type tuple

2017-09-21 Thread David Zhang via Digitalmars-d-learn
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,