On Thu, 23 May 2013 17:06:57 -0400, Steven Schveighoffer
<[email protected]> wrote:
On Thu, 23 May 2013 16:42:30 -0400, Artur Skawina <[email protected]>
wrote:
For example you couldn't then do this:
struct Packet(uint TY) { /*...*/immutable uint type=TY; immutable ubyte
len=PLen(TY); /*...*/ }
auto PProcess(PT)(PT* p) { static if (p.type<128) if (p.type==42)
sendp(p, p.len*4); }
static if(TY < 128) if(TY == 42) ....
Sorry, I realize this wouldn't work. You must enum the TY in order to
fetch it in PProcess, or declare type and len static.
But the point is still valid, you cannot use the runtime value of a member
variable for const folding.
You can use both the runtime value to occupy space, and the compile-time
value to do tests. For instance:
struct Packet(uint TY) { enum type = TY; private immutable _type = type;
enum len = PLen(TY); private immutable _len = len; ...}
In the current compiler, it's pretty much impossible to do this, unless
you use a trick like I outlined in the last post.
-Steve