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 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.
Yup. That's better.