Manifest constants (was const again)
Janice Caron
caron800 at googlemail.com
Sat Dec 8 15:51:22 PST 2007
On 12/8/07, Walter Bright <newshound1 at digitalmars.com> wrote:
> enum defname = "upload.log";
> enum float fudge = 61.74;
> enum char starter = 'r';
> enum qwerty = 0xF4;
Just to be evil...
<EVIL>
I thought there was a principle that if something could be done with
templates then it shouldn't be a language feature?
string defname()() { return "upload.log" };
float fudge()() { return 61.74; }
char starter()() { return 'r'; }
ubyte qwerty()() { return 0xF4 }
Now...
auto x = fudge;
should instantiate fudge!()(), then inline it, ultimately yielding
"auto x = 61.74;", but the other manifest constants won't be
instantiated, because they're never referenced.
:-)
</EVIL>
More information about the Digitalmars-d
mailing list