On 9/01/11 1:28 PM, Tomek Sowiński wrote:
bearophile napisał:
Also, IMO, it has no real advantage, why not use std.algorithm.find instead ?
The syntax is worse, I don't like to call a function for something so common
and basic. It's like calling a library
function to join two strings (and find("hello", "llox") doesn't return a
boolean).
That can be pretty much solved with a wrapper:
bool has(alias pred = "a == b", R, E)(R haystack, E needle) {
return find(haystack, needle).empty;
}
-------
if (someString.has(c))
...
Can we add 'has' (or call it 'contains', I don't mind) to std.algorithm and end
the discussion?
What's wrong with std.algorithm.canFind?
http://www.digitalmars.com/d/2.0/phobos/std_algorithm.html#canFind
>bool canFind(alias pred = "a == b", Range, V)(Range range, V value);
>Returns true if and only if value can be found in range. Performs
Ο(r.length) evaluations of pred.