Initializing defaults based on type.
Artur Skawina via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Mar 6 13:49:15 PST 2015
On 03/06/15 22:29, Artur Skawina wrote:
> No, you implement it using CTFE magic, and then that code becomes:
> #foreach (N; 0..PairInitValues.length/2) {
> enum PairInitValue(T:PairInitValues[$N*2]) = PairInitValues[$N*2+1];
> }
> Seriously though, avoid using `.stringof` when generating code - it will
> break if the symbol is not available at the string-mixin scope.
Ie try to access the types/parms/etc directly; eg `PairInitValues[i]` will
usually work, when `i` is a constant or a static-foreach variable.
[The code above obviously isn't plain D and won't work as-is w/o a magic
ctfe preprocessor.]
artur
More information about the Digitalmars-d-learn
mailing list