How to mixin repeated text?
Kamil Koczurek
koczurekk at gmail.com
Mon Aug 27 11:56:08 UTC 2018
On Monday, 27 August 2018 at 11:52:02 UTC, Andrey wrote:
> Hello again,
> I have this part of code:
>> ...
>>if(index + 3 >= data.length || data[index + 1][0] == '&' ||
>>data[index + 2][0] == '&' || data[index + 3][0] == '&' ||
>>data[index + 4][0] == '&')
>>{
>> writeln("Some text...");
>>}
>
> I don't want to write manually these four "or" conditions
> because in each case I know at compile time how many conditions
> should be.
> I would be great if I could do something like this:
>>if(index + 3 >= data.length || mixin OrCondition!4) { ... }
>
> where "OrCondition" will insert text using this expression:
>> data[index + j][0] == '&' // j is between [1 and 4]
>
> I know that it is possible but don't know how to implement...
Mixins seem to be an overkill here. Maybe something like this
would suffice:
data[index + 1 .. index + 5].map!(k => k[0]).array == "&&&&"
More information about the Digitalmars-d-learn
mailing list