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
    }
}

Reply via email to