Getting the size of a type tuple

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Sep 21 19:59:05 UTC 2017


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;
> } ();
> ----

I'd just do:

	template sizeofStruct(Types...) {
		struct S { align(1) Types fields; }
		enum sizeofStruct = S.sizeof;
	}

Skip the CTFE implied by the function literal, the compiler already
knows the size very well.


T

-- 
What are you when you run out of Monet? Baroque.


More information about the Digitalmars-d-learn mailing list