Parameterized Keywords
Patience via Digitalmars-d
digitalmars-d at puremagic.com
Mon Mar 7 13:01:09 PST 2016
On Monday, 7 March 2016 at 16:29:27 UTC, NX wrote:
> On Monday, 7 March 2016 at 05:56:54 UTC, Patience wrote:
>> Just curious if anyone can see the use for them?
>
> I believe 'new' keyword can take advantage of this quite good.
> For example you can pass memory usage strategy like so:
> MyClass mc = new[stream] MyClass();
> MyClass mc2 = new[static] MyClass();
>
> Deja-vu? Yes the idea comes from OpenGL. Also it might come in
> handy for other stuff:
> MyClass mc3 = new[no_internal_pointers] MyClass();
> MyClass mc4 = new[no_compacting] MyClass();
Yeah, Maybe... new seems more like a keyword hack though. Things
like if and loop are more natural as keywords(I guess since they
generally have precise meanings in hardware/assembly). If the
language already has new as a keyword though, it does seem like a
good way to modify its behavior.
More information about the Digitalmars-d
mailing list