@@ -2536,13 +2536,13 @@ was successful.
2536
2536
For more information about `pred` see $(LREF find).
2537
2537
2538
2538
See_Also:
2539
- $(REF among, std,algorithm,comparison) for checking a value against multiple possibilities .
2539
+ $(REF among, std,algorithm,comparison) for checking a value against multiple arguments .
2540
2540
+/
2541
2541
template canFind (alias pred=" a == b" )
2542
2542
{
2543
2543
/+ +
2544
- Returns `true` if and only if any value `v` found in the
2545
- input range `range` satisfies the predicate `pred` .
2544
+ Returns `true` if and only if `pred(e)` is true for any value `e` in the
2545
+ input range `range`.
2546
2546
Performs (at most) $(BIGOH haystack.length) evaluations of `pred`.
2547
2547
+/
2548
2548
bool canFind (Range )(Range haystack)
@@ -2565,11 +2565,11 @@ template canFind(alias pred="a == b")
2565
2565
Returns the 1-based index of the first needle found in `haystack`. If no
2566
2566
needle is found, then `0` is returned.
2567
2567
2568
- So, if used directly in the condition of an if statement or loop, the result
2568
+ So, if used directly in the condition of an `if` statement or loop, the result
2569
2569
will be `true` if one of the needles is found and `false` if none are
2570
2570
found, whereas if the result is used elsewhere, it can either be cast to
2571
2571
`bool` for the same effect or used to get which needle was found first
2572
- without having to deal with the tuple that ` LREF find` returns for the
2572
+ without having to deal with the tuple that $( LREF find) returns for the
2573
2573
same operation.
2574
2574
+/
2575
2575
size_t canFind (Range , Ranges... )(Range haystack, scope Ranges needles)
@@ -2584,15 +2584,17 @@ template canFind(alias pred="a == b")
2584
2584
// /
2585
2585
@safe unittest
2586
2586
{
2587
- assert (canFind([0 , 1 , 2 , 3 ], 2 ) == true );
2588
- assert (canFind([0 , 1 , 2 , 3 ], [1 , 2 ], [2 , 3 ]));
2589
- assert (canFind([0 , 1 , 2 , 3 ], [1 , 2 ], [2 , 3 ]) == 1 );
2590
- assert (canFind([0 , 1 , 2 , 3 ], [1 , 7 ], [2 , 3 ]));
2591
- assert (canFind([0 , 1 , 2 , 3 ], [1 , 7 ], [2 , 3 ]) == 2 );
2587
+ const arr = [0 , 1 , 2 , 3 ];
2588
+ assert (canFind(arr, 2 ));
2589
+ assert (! canFind(arr, 4 ));
2592
2590
2593
- assert (canFind([0 , 1 , 2 , 3 ], 4 ) == false );
2594
- assert (! canFind([0 , 1 , 2 , 3 ], [1 , 3 ], [2 , 4 ]));
2595
- assert (canFind([0 , 1 , 2 , 3 ], [1 , 3 ], [2 , 4 ]) == 0 );
2591
+ // find one of several needles
2592
+ assert (canFind(arr, [1 , 2 ], [2 , 3 ]));
2593
+ assert (canFind(arr, [1 , 2 ], [2 , 3 ]) == 1 );
2594
+ assert (canFind(arr, [1 , 7 ], [2 , 3 ]));
2595
+ assert (canFind(arr, [1 , 7 ], [2 , 3 ]) == 2 );
2596
+ assert (! canFind(arr, [1 , 3 ], [2 , 4 ]));
2597
+ assert (canFind(arr, [1 , 3 ], [2 , 4 ]) == 0 );
2596
2598
}
2597
2599
2598
2600
/**
@@ -2607,18 +2609,18 @@ template canFind(alias pred="a == b")
2607
2609
" cardboard"
2608
2610
];
2609
2611
assert (! canFind(words, " bees" ));
2610
- assert ( canFind! ((string a , string b ) => a .startsWith(b ))(words, " bees" ));
2612
+ assert ( canFind! ((string elem , string needle ) => elem .startsWith(needle ))(words, " bees" ));
2611
2613
}
2612
2614
2613
- // / Search for mutliple items in an array of items (search for needles in an array of hay stacks )
2615
+ // / Search for multiple items in an array of items (search for needles in an array of haystacks )
2614
2616
@safe unittest
2615
2617
{
2616
2618
string s1 = " aaa111aaa" ;
2617
2619
string s2 = " aaa222aaa" ;
2618
2620
string s3 = " aaa333aaa" ;
2619
2621
string s4 = " aaa444aaa" ;
2620
2622
const hay = [s1, s2, s3, s4];
2621
- assert (hay.canFind! (e => ( e.canFind(" 111" , " 222" ) )));
2623
+ assert (hay.canFind! (e => e.canFind(" 111" , " 222" )));
2622
2624
}
2623
2625
2624
2626
@safe unittest
@@ -2736,7 +2738,7 @@ Returns:
2736
2738
`seq` advanced to the first matching element, or until empty if there are no
2737
2739
matching elements.
2738
2740
2739
- See_Also: $(LREF find), $(REF std,algorithm,comparison,among )
2741
+ See_Also: $(LREF find), $(REF among, std,algorithm,comparison)
2740
2742
*/
2741
2743
InputRange findAmong (alias pred = " a == b" , InputRange, ForwardRange)(
2742
2744
InputRange seq, ForwardRange choices)
0 commit comments