I'll try to be straight.

I have the following function:

public size_t indexOf(alias pred = "a == b", Range)(Range array)
{
        alias predicate = unaryFun!pred;
        for(size_t i = 0; i < array.length; i++)
                if(predicate(array[i]))
                        return i;
        return size_t.max;
}

Say that I may want to use the function in a @nogc scope, providing a @nogc callable, but I also want to reuse the same code in managed scope while passing a delegate: how can I apply the attributes of the given callable to the function so that they're automatically determined at compile time?

I know of std.traits.SetFunctionAttributes and std.traits.FunctionAttributes, but I have no idea on how to apply them to solve this. Perhaps I should declare indexOf as a template?

Reply via email to