Mixin operator 'if' directly
bauss
jj_1337 at live.dk
Wed Dec 19 15:09:47 UTC 2018
On Wednesday, 19 December 2018 at 13:37:17 UTC, Andrey wrote:
> Hi,
> Here is a template mixin:
>> mixin template create(alias input, uint index, alias data)
>> {
>> if(input.length < index) return;
>>
>> // ... some code
>> }
>
> When I try to compile it, I get:
>> Error: declaration expected, not if
>
> Is it possible to mixin operator 'if' directly inside my
> template mixin?
What you want to use is "static if".
The correct way to do the above would be this:
mixin template create(alias input, uint index, alias data)
{
static if(input.length >= index) // Reversed the logic.
{
// ... some code
}
}
More information about the Digitalmars-d-learn
mailing list