endsWith - for a string vs an array of strings

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 10 15:05:52 PST 2015


> Take a look at your error messages:
>
>> std.algorithm.endsWith(alias pred = "a == b", Range, 
>> Needles...)(Range doesThisEnd, Needles withOneOfThese)
>
> Needles is not an array type, it's a type tuple, so 
> withOneOfThese doesn't accept an array of strings.

ahhh.. thank you so much for this.

> In D there is a feature that allows a function to accept both 
> an array of items and items, but it's not used here by 
> endsWith, for reasons I don't understand (other people can 
> answer this).

yes - it is funny there is not an overloading that accepts arrays 
given I suppose this will be quite a common use case.  and it's 
another one of those things far from obvious to a new learner - 
actually a two stage problem: knowing what the right thing to do 
is not obvious, and neither is it obvious how to correct your 
mistake when your first attempt fails.  we should cover this in 
any informal D overview of string-related library functions, on a 
section for text processing, and for those coming to D from other 
languages.

I very much appreciate your help.


Laeeth.


More information about the Digitalmars-d-learn mailing list