How to "Inherit" the attributes from a given callable argument?
Mek101
anEmailAddress at mail.somewhere
Wed Jun 12 19:46:12 UTC 2019
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?
More information about the Digitalmars-d-learn
mailing list