Capture parameter identifier name in a template?
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 12 11:16:53 PDT 2014
On Tue, Aug 12, 2014 at 05:36:40PM +0000, Maxime Chevalier-Boisvert via Digitalmars-d-learn wrote:
> In my JavaScript VM, I have a function whose purpose is to expose
> D/host constants to the JavaScript runtime code running inside the VM.
> This makes for somewhat redundant code, as follows:
>
> vm.defRTConst("OBJ_MIN_CAP"w, OBJ_MIN_CAP);
> vm.defRTConst("PROTO_SLOT_IDX"w, PROTO_SLOT_IDX);
> vm.defRTConst("FPTR_SLOT_IDX"w, FPTR_SLOT_IDX);
> vm.defRTConst("ATTR_CONFIGURABLE"w , ATTR_CONFIGURABLE);
> vm.defRTConst("ATTR_WRITABLE"w , ATTR_WRITABLE);
> vm.defRTConst("ATTR_ENUMERABLE"w , ATTR_ENUMERABLE);
> vm.defRTConst("ATTR_DELETED"w , ATTR_DELETED);
> vm.defRTConst("ATTR_GETSET"w , ATTR_GETSET);
> vm.defRTConst("ATTR_DEFAULT"w , ATTR_DEFAULT);
>
> I'm just wondering if there's a way to template defRTConst so that the
> name of an identifier I'm passing (e.g.: ATTR_DEFAULT) can be captured
> by the template, making it so that I don't also need to pass the name
> as a string. I expect the answer to be no, but maybe someone with
> more knowledge of D template magic knows better.
I know it's possible to get function (runtime) parameter names using
__traits(), but I'm not sure if that can be done for compile-time
parameters. See: std.traits.ParameterIdentifierTuple.
T
--
It said to install Windows 2000 or better, so I installed Linux instead.
More information about the Digitalmars-d-learn
mailing list