Below is a example program that illustrates my issue.

When compiled at run.dlang I get:
```
onlineapp.d(18): Error: `@safe` function `onlineapp.processSafely!(1, 4).processSafely` cannot call `@system` function pointer `shouldDo` onlineapp.d(28): Error: template instance `onlineapp.processSafely!(1, 4)` error instantiating
```

Why isn't this working? How can I get the effect I want?

Cheers,
-- john

```
bool[7] stagesToProcess = false;

@nogc nothrow @safe bool shouldDoInStages(int index)
{
    return stagesToProcess[index];
}

@nogc nothrow @safe bool shouldDoNever(int index)
{
    return false;
}

template processSafely(int low, int high)
{
    alias ShouldDoFnT = @nogc nothrow @safe bool function(int);

    @nogc nothrow @safe uint processSafely(ShouldDoFnT shouldDo)
    {
        assert(low < high);
        uint stepsProcessed;
        for (int ii = low; ii <= high; ii++)
        {
            if (shouldDo(ii))
            {
                stepsProcessed++;
            }
        }
        return stepsProcessed;
    }
}

void main()
{
stagesToProcess = [false, false, true, true, false, true, false];
    uint count = processSafely!(1, 4)(&shouldDoInStages);
    assert(count == 2);
}
```

  • How can I tell D... John Dougan via Digitalmars-d-learn
    • Re: How can... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: How... Steven Schveighoffer via Digitalmars-d-learn
        • Re:... John Dougan via Digitalmars-d-learn
          • ... Steven Schveighoffer via Digitalmars-d-learn
            • ... John Dougan via Digitalmars-d-learn
              • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... John Dougan via Digitalmars-d-learn
              • ... Monkyyy via Digitalmars-d-learn

Reply via email to