Place your attributes on the right hand side of the function, not the left side.

Use the left side for attributes/type qualifiers that go on the return type.

```d
bool[7] stagesToProcess = false;

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

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

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

     uint processSafely(ShouldDoFnT shouldDo) @nogc nothrow @safe
     {
         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