Second CT-Parameter of isRange Predicates

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed Nov 4 18:27:08 PST 2015


On Wednesday, 4 November 2015 at 10:37:54 UTC, Atila Neves wrote:
> On Tuesday, 3 November 2015 at 10:08:04 UTC, Jonathan M Davis 
> wrote:
>> On Tuesday, 3 November 2015 at 08:37:22 UTC, Atila Neves wrote:
>>> Am I the only one who ever writes `int[]` or `Struct[]` in a 
>>> function signature?
>>
>> Probably not, but I write very little code that operates on 
>> arrays rather than ranges. If I do, it's usually in a short 
>> program or script where I'm doing something that I don't 
>> intend to ever reuse, and there's no point in making it 
>> generic.
>>
>> - Jonathan M Davis
>
> I'd _like_ to write functions that take ranges instead; that's 
> why I want to make it easier to declare "this parameter is an 
> input range of T".

I confess that I don't find is(ElementType!E == Foo) to be 
particularly onerous. If that's what I need, then I do it and 
move on. It takes less time to write than this post, and it's not 
that uncommon that far more complicated conditions are required 
for template constraints anyway.

So, while I can understand why you'd want it to be simpler, it 
really doesn't seem like a big deal to me. And for that matter, 
if you really do want it to be simpler, there's nothing stopping 
you from creating your own traits to test with rather than just 
those in Phobos. It just means that it's not something that's 
going to be commonly used.

IMHO, if anything is annoying about writing template constraints, 
it's dealing with several overloads, since that frequently 
requires that you essentially put the negation of each overload 
in the other overloads.

- Jonathan M Davis


More information about the Digitalmars-d mailing list