On Wednesday, 8 July 2020 at 20:11:05 UTC, IGotD- wrote:


Now since mySize is a template, shouldn't this work mySize!v, but it doesn't? What essential understanding have I missed here?

You are trying to use a run-time value of v at compile-time, which is not possible. If you want the modified size of the type of a variable, you can pass the variable to the compile-time function by alias:

enum mySize(alias e) = e.sizeof + 42;

int v;
enum size = mySize!v;

pragma(msg, size); // 46LU


If you want to the size of the type of a run-time expression, you will have to use typeof:

static assert(mySize!(typeof(v + 1)) == 46);

Reply via email to