mirror of
https://github.com/dlang/phobos.git
synced 2025-05-03 00:20:26 +03:00
Schedule for deprecation the predicate-only version of canFind and make any handle that use case.
This commit is contained in:
parent
d1938e5563
commit
2e919aa77c
1 changed files with 19 additions and 16 deletions
|
@ -7777,24 +7777,35 @@ unittest
|
|||
}
|
||||
}
|
||||
|
||||
// canFind
|
||||
/**
|
||||
Forwards to $(D any) for backwards compatibility.
|
||||
|
||||
$(RED Scheduled for deprecation in August 2012. Please use $(D any) instead.)
|
||||
*/
|
||||
bool canFind(alias pred, Range)(Range range)
|
||||
{
|
||||
return any!pred(range);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns $(D true) if and only if a value $(D v) satisfying the
|
||||
predicate $(D pred) can be found in the forward range $(D
|
||||
range). Performs $(BIGOH r.length) evaluations of $(D pred).
|
||||
*/
|
||||
|
||||
bool canFind(alias pred, Range)(Range range)
|
||||
bool any(alias pred, Range)(Range range)
|
||||
if (is(typeof(find!pred(range))))
|
||||
{
|
||||
return !find!pred(range).empty;
|
||||
}
|
||||
|
||||
/**
|
||||
Alias for canFind, for consistency with terminology typically used in
|
||||
functional languages.
|
||||
*/
|
||||
alias canFind any;
|
||||
unittest
|
||||
{
|
||||
debug(std_algorithm) scope(success)
|
||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
||||
auto a = [ 1, 2, 0, 4 ];
|
||||
assert(canFind!"a == 2"(a));
|
||||
assert(any!"a == 2"(a));
|
||||
}
|
||||
|
||||
/**
|
||||
Returns $(D true) if and only if all values in $(D range) satisfy the
|
||||
|
@ -7818,14 +7829,6 @@ unittest
|
|||
assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
debug(std_algorithm) scope(success)
|
||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
||||
auto a = [ 1, 2, 0, 4 ];
|
||||
assert(canFind!"a == 2"(a));
|
||||
}
|
||||
|
||||
// Scheduled for deprecation. Use std.range.SortedRange.canFind.
|
||||
bool canFindSorted(alias pred = "a < b", Range, V)(Range range, V value) {
|
||||
pragma(msg, "std.algorithm.canFindSorted is scheduled for " ~
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue