Choosing arity of a template function
Marc Schütz via Digitalmars-d
digitalmars-d at puremagic.com
Sat Feb 27 04:38:27 PST 2016
On Friday, 26 February 2016 at 23:11:32 UTC, Andrei Alexandrescu
wrote:
> On 02/26/2016 06:09 PM, Andrei Alexandrescu wrote:
>> static if (is(partition == function) || is(partition ==
>> delegate))
>> partition(r);
>> else if (__traits(compiles, partition!less(r, n)))
>> partition!less(r, n);
>> else
>> partition!less(r);
>>
> Nevertheless, I'm still on lookout for a more elegant solution!
> I have this mindset that using __traits(compiles) is some sort
> of cheating.
I don't see it as cheating; in fact it is more elegant, because
it checks for exactly the thing you depend on, namely that
`partition` is callable. Your explicit check above rejects
structs with opCall(), for example, which is probably not what
you intended.
More information about the Digitalmars-d
mailing list