Compile time values & implicit conditional mixin, as an alternative to tertiary operator hell and one-compile-time functions.
Sebastiaan Koppe
mail at skoppe.eu
Sat Jan 16 18:32:23 UTC 2021
On Saturday, 16 January 2021 at 15:17:04 UTC, Stefan Koch wrote:
> On Saturday, 16 January 2021 at 14:56:18 UTC, Sebastiaan Koppe
> wrote:
>> On Saturday, 16 January 2021 at 14:20:19 UTC, Paul wrote:
>>> On Saturday, 16 January 2021 at 04:13:12 UTC, Paul Backus
>>> wrote:
>>
>> you can also use CTFE. Generate the values in a normal
>> function, assign it to an enum.
>>
>> ---
>> string generateValues(uint L)() {
>> string result = "value.x";
>> if (L != 1) { result ~= ",value.y"; }
>> if (L != 2) { result ~= ",value.z"; }
>> if (L != 3) { result ~= ",value.w"; }
>> return result;
>> }
>>
>> enum string values = generateValues!3();
>>
>> pragma(msg, values);
>>
>> void main(){};
>> ---
>
> What you are doing here is an expensive template instantiation
> for no reason.
Yes thanks. I translated the thing without thinking too much.
More information about the Digitalmars-d
mailing list