@@ -748,7 +748,8 @@ if (isInputRange!R && !isInfinite!R)
748
748
`haystack` before reaching an element for which
749
749
`startsWith!pred(haystack, needles)` is `true`. If
750
750
`startsWith!pred(haystack, needles)` is not `true` for any element in
751
- `haystack`, then `-1` is returned.
751
+ `haystack`, then `-1` is returned. If only `pred` is provided,
752
+ `pred(haystack)` is tested for each element.
752
753
753
754
See_Also: $(REF indexOf, std,string)
754
755
+/
@@ -898,18 +899,7 @@ if (isInputRange!R &&
898
899
assert (countUntil(" hello world" , " world" , ' l' ) == 2 );
899
900
}
900
901
901
- /+ +
902
- Similar to the previous overload of `countUntil`, except that this one
903
- evaluates only the predicate `pred`.
904
-
905
- Params:
906
- pred = Predicate to when to stop counting.
907
- haystack = An
908
- $(REF_ALTTEXT input range, isInputRange, std,range,primitives) of
909
- elements to be counted.
910
- Returns: The number of elements which must be popped from `haystack`
911
- before `pred(haystack.front)` is `true`.
912
- +/
902
+ // / ditto
913
903
ptrdiff_t countUntil (alias pred, R)(R haystack)
914
904
if (isInputRange! R &&
915
905
is (typeof (unaryFun! pred(haystack.front)) : bool ))
@@ -1457,35 +1447,51 @@ private auto extremum(alias selector = "a < b", Range,
1457
1447
1458
1448
// find
1459
1449
/**
1460
- Finds an individual element in an input range. Elements of $(D
1461
- haystack) are compared with `needle` by using predicate $(D
1462
- pred). Performs $(BIGOH walkLength(haystack)) evaluations of $(D
1463
- pred).
1450
+ Finds an individual element in an $(REF_ALTTEXT input range, isInputRange, std,range,primitives).
1451
+ Elements of `haystack` are compared with `needle` by using predicate
1452
+ `pred` with `pred(haystack.front, needle)`.
1453
+ `find` performs $(BIGOH walkLength(haystack)) evaluations of `pred`.
1454
+
1455
+ To _find the last occurrence of `needle` in a
1456
+ $(REF_ALTTEXT bidirectional, isBidirectionalRange, std,range,primitives) `haystack`,
1457
+ call `find(retro(haystack), needle)`. See $(REF retro, std,range).
1458
+
1459
+ If no `needle` is provided, `pred(haystack.front)` will be evaluated on each
1460
+ element of the input range.
1464
1461
1465
- To _find the last occurrence of `needle` in `haystack`, call $(D
1466
- find(retro(haystack), needle)). See $(REF retro, std,range).
1462
+ If `input` is a $(REF_ALTTEXT forward range, isForwardRange, std,range,primitives),
1463
+ `needle` can be a $(REF_ALTTEXT forward range, isForwardRange, std,range,primitives) too.
1464
+ In this case `startsWith!pred(haystack, needle)` is evaluated on each evaluation.
1465
+
1466
+ Note:
1467
+ `find` behaves similar to `dropWhile` in other languages.
1468
+
1469
+ Complexity:
1470
+ `find` performs $(BIGOH walkLength(haystack)) evaluations of `pred`.
1471
+ There are specializations that improve performance by taking
1472
+ advantage of $(REF_ALTTEXT bidirectional, isBidirectionalRange, std,range,primitives)
1473
+ or $(REF_ALTTEXT random access, isRandomAccess, std,range,primitives)
1474
+ ranges (where possible).
1467
1475
1468
1476
Params:
1469
1477
1470
- pred = The predicate for comparing each element with the needle, defaulting to
1471
- `"a == b"`.
1472
- The negated predicate `"a != b"` can be used to search instead for the first
1473
- element $(I not) matching the needle.
1478
+ pred = The predicate for comparing each element with the needle, defaulting to equality `"a == b"`.
1479
+ The negated predicate `"a != b"` can be used to search instead for the first
1480
+ element $(I not) matching the needle.
1474
1481
1475
- haystack = The $(REF_ALTTEXT input range, isInputRange, std,range,primitives)
1476
- searched in.
1482
+ haystack = The $(REF_ALTTEXT input range, isInputRange, std,range,primitives)
1483
+ searched in.
1477
1484
1478
- needle = The element searched for.
1485
+ needle = The element searched for.
1479
1486
1480
1487
Returns:
1481
1488
1482
- `haystack` advanced such that the front element is the one searched for;
1483
- that is, until `binaryFun!pred(haystack.front, needle)` is `true`. If no
1484
- such position exists, returns an empty `haystack`.
1489
+ `haystack` advanced such that the front element is the one searched for;
1490
+ that is, until `binaryFun!pred(haystack.front, needle)` is `true`. If no
1491
+ such position exists, returns an empty `haystack`.
1485
1492
1486
- See_Also:
1487
- $(HTTP sgi.com/tech/stl/_find.html, STL's _find)
1488
- */
1493
+ See_ALso: $(LREF findAdjacent), $(LREF findAmong), $(LREF findSkip), $(LREF findSplit), $(LREF startsWith)
1494
+ */
1489
1495
InputRange find (alias pred = " a == b" , InputRange, Element)(InputRange haystack, scope Element needle)
1490
1496
if (isInputRange! InputRange &&
1491
1497
is (typeof (binaryFun! pred(haystack.front, needle)) : bool ))
@@ -1760,35 +1766,7 @@ if (isInputRange!InputRange &&
1760
1766
assert ([x].find(x).empty == false );
1761
1767
}
1762
1768
1763
- /**
1764
- Advances the input range `haystack` by calling `haystack.popFront`
1765
- until either `pred(haystack.front)`, or $(D
1766
- haystack.empty). Performs $(BIGOH haystack.length) evaluations of $(D
1767
- pred).
1768
-
1769
- To _find the last element of a
1770
- $(REF_ALTTEXT bidirectional, isBidirectionalRange, std,range,primitives) `haystack` satisfying
1771
- `pred`, call `find!(pred)(retro(haystack))`. See $(REF retro, std,range).
1772
-
1773
- `find` behaves similar to `dropWhile` in other languages.
1774
-
1775
- Params:
1776
-
1777
- pred = The predicate for determining if a given element is the one being
1778
- searched for.
1779
-
1780
- haystack = The $(REF_ALTTEXT input range, isInputRange, std,range,primitives) to
1781
- search in.
1782
-
1783
- Returns:
1784
-
1785
- `haystack` advanced such that the front element is the one searched for;
1786
- that is, until `binaryFun!pred(haystack.front, needle)` is `true`. If no
1787
- such position exists, returns an empty `haystack`.
1788
-
1789
- See_Also:
1790
- $(HTTP sgi.com/tech/stl/find_if.html, STL's find_if)
1791
- */
1769
+ // / ditto
1792
1770
InputRange find (alias pred, InputRange)(InputRange haystack)
1793
1771
if (isInputRange! InputRange)
1794
1772
{
@@ -1842,31 +1820,7 @@ if (isInputRange!InputRange)
1842
1820
assert (find! (a=> a% 4 == 0 )(" 日本語" ) == " 本語" );
1843
1821
}
1844
1822
1845
- /**
1846
- Finds the first occurrence of a forward range in another forward range.
1847
-
1848
- Performs $(BIGOH walkLength(haystack) * walkLength(needle)) comparisons in the
1849
- worst case. There are specializations that improve performance by taking
1850
- advantage of $(REF_ALTTEXT bidirectional range, isBidirectionalRange, std,range,primitives)
1851
- or random access in the given ranges (where possible), depending on the statistics
1852
- of the two ranges' content.
1853
-
1854
- Params:
1855
-
1856
- pred = The predicate to use for comparing respective elements from the haystack
1857
- and the needle. Defaults to simple equality `"a == b"`.
1858
-
1859
- haystack = The $(REF_ALTTEXT forward range, isForwardRange, std,range,primitives)
1860
- searched in.
1861
-
1862
- needle = The $(REF_ALTTEXT forward range, isForwardRange, std,range,primitives)
1863
- searched for.
1864
-
1865
- Returns:
1866
-
1867
- `haystack` advanced such that `needle` is a prefix of it (if no
1868
- such position exists, returns `haystack` advanced to termination).
1869
- */
1823
+ // / ditto
1870
1824
R1 find (alias pred = " a == b" , R1 , R2 )(R1 haystack, scope R2 needle)
1871
1825
if (isForwardRange! R1 && isForwardRange! R2
1872
1826
&& is (typeof (binaryFun! pred(haystack.front, needle.front)) : bool ))
@@ -2664,8 +2618,7 @@ Returns:
2664
2618
`seq` advanced to the first matching element, or until empty if there are no
2665
2619
matching elements.
2666
2620
2667
- See_Also:
2668
- $(HTTP sgi.com/tech/stl/find_first_of.html, STL's find_first_of)
2621
+ See_Also: $(LREF find), $(REF std,algorithm,comparison,among)
2669
2622
*/
2670
2623
InputRange findAmong (alias pred = " a == b" , InputRange, ForwardRange)(
2671
2624
InputRange seq, ForwardRange choices)
@@ -2700,6 +2653,11 @@ if (isInputRange!InputRange && isForwardRange!ForwardRange)
2700
2653
* Finds `needle` in `haystack` and positions `haystack`
2701
2654
* right after the first occurrence of `needle`.
2702
2655
*
2656
+ * If no needle is provided, the `haystack` is advanced as long as `pred`
2657
+ * evaluates to `true`.
2658
+ * Similarly, the haystack is positioned so as `pred` evaluates to `false` for
2659
+ * `haystack.front`.
2660
+ *
2703
2661
* Params:
2704
2662
* haystack = The
2705
2663
* $(REF_ALTTEXT forward range, isForwardRange, std,range,primitives) to search
@@ -2711,7 +2669,10 @@ if (isInputRange!InputRange && isForwardRange!ForwardRange)
2711
2669
*
2712
2670
* Returns: `true` if the needle was found, in which case `haystack` is
2713
2671
* positioned after the end of the first occurrence of `needle`; otherwise
2714
- * `false`, leaving `haystack` untouched.
2672
+ * `false`, leaving `haystack` untouched. If no needle is provided, it returns
2673
+ * the number of times `pred(haystack.front)` returned true.
2674
+ *
2675
+ * See_Also: $(LREF find)
2715
2676
*/
2716
2677
bool findSkip (alias pred = " a == b" , R1 , R2 )(ref R1 haystack, R2 needle)
2717
2678
if (isForwardRange! R1 && isForwardRange! R2
@@ -2742,18 +2703,7 @@ if (isForwardRange!R1 && isForwardRange!R2
2742
2703
assert (findSkip(s, " def" ) && s.empty);
2743
2704
}
2744
2705
2745
- /**
2746
- * Advances the `haystack` as long as `pred` evaluates to `true`.
2747
- * The haystack is positioned so as pred evaluates to false for haystack.front.
2748
- *
2749
- * Params:
2750
- * haystack = The
2751
- * $(REF_ALTTEXT forward range, isForwardRange, std,range,primitives) to search
2752
- * in.
2753
- * pred = Custom predicate for comparison of haystack and needle
2754
- *
2755
- * Returns: The number of times `pred(haystack.front)` returned true.
2756
- */
2706
+ // / ditto
2757
2707
size_t findSkip (alias pred, R1 )(ref R1 haystack)
2758
2708
if (isForwardRange! R1 && ifTestable! (typeof (haystack.front), unaryFun! pred))
2759
2709
{
@@ -2827,6 +2777,8 @@ A sub-type of `Tuple!()` of the split portions of `haystack` (see above for
2827
2777
details). This sub-type of `Tuple!()` has `opCast` defined for `bool`. This
2828
2778
`opCast` returns `true` when the separating `needle` was found
2829
2779
(`!result[1].empty`) and `false` otherwise.
2780
+
2781
+ See_Also: $(LREF find)
2830
2782
*/
2831
2783
auto findSplit (alias pred = " a == b" , R1 , R2 )(R1 haystack, R2 needle)
2832
2784
if (isForwardRange! R1 && isForwardRange! R2 )
@@ -3192,6 +3144,8 @@ Returns: The minimum, respectively maximum element of a range together with the
3192
3144
number it occurs in the range.
3193
3145
3194
3146
Throws: `Exception` if `range.empty`.
3147
+
3148
+ See_Also: $(REF min, std,algorithm,comparison), $(LREF minIndex), $(LREF minElement), $(LREF minPos)
3195
3149
*/
3196
3150
Tuple ! (ElementType! Range , size_t )
3197
3151
minCount(alias pred = " a < b" , Range )(Range range)
@@ -3398,7 +3352,9 @@ Params:
3398
3352
Returns: The minimal element of the passed-in range.
3399
3353
3400
3354
See_Also:
3401
- $(REF min, std,algorithm,comparison)
3355
+
3356
+ $(LREF maxElement), $(REF min, std,algorithm,comparison), $(LREF minCount),
3357
+ $(LREF minIndex), $(LREF minPos)
3402
3358
*/
3403
3359
auto minElement (alias map, Range )(Range r)
3404
3360
if (isInputRange! Range && ! isInfinite! Range )
@@ -3511,8 +3467,11 @@ Params:
3511
3467
3512
3468
Returns: The maximal element of the passed-in range.
3513
3469
3470
+
3514
3471
See_Also:
3515
- $(REF max, std,algorithm,comparison)
3472
+
3473
+ $(LREF minElement), $(REF max, std,algorithm,comparison), $(LREF maxCount),
3474
+ $(LREF maxIndex), $(LREF maxPos)
3516
3475
*/
3517
3476
auto maxElement (alias map, Range )(Range r)
3518
3477
if (isInputRange! Range && ! isInfinite! Range )
@@ -3637,6 +3596,8 @@ Returns: The position of the minimum (respectively maximum) element of forward
3637
3596
range `range`, i.e. a subrange of `range` starting at the position of its
3638
3597
smallest (respectively largest) element and with the same ending as `range`.
3639
3598
3599
+ See_Also:
3600
+ $(REF max, std,algorithm,comparison), $(LREF minCount), $(LREF minIndex), $(LREF minElement)
3640
3601
*/
3641
3602
Range minPos (alias pred = " a < b" , Range )(Range range)
3642
3603
if (isForwardRange! Range && ! isInfinite! Range &&
@@ -3738,15 +3699,15 @@ Params:
3738
3699
range = The $(REF_ALTTEXT input range, isInputRange, std,range,primitives)
3739
3700
to search.
3740
3701
3741
- Complexity: O(n )
3742
- Exactly `n - 1` comparisons are needed.
3702
+ Complexity: $(BIGOH range.length )
3703
+ Exactly `range.length - 1` comparisons are needed.
3743
3704
3744
3705
Returns:
3745
3706
The index of the first encounter of the minimum element in `range`. If the
3746
3707
`range` is empty, -1 is returned.
3747
3708
3748
3709
See_Also:
3749
- $(REF min, std,algorithm,comparison), $(LREF minCount), $(LREF minElement), $(LREF minPos)
3710
+ $(LREF maxIndex), $( REF min, std,algorithm,comparison), $(LREF minCount), $(LREF minElement), $(LREF minPos)
3750
3711
*/
3751
3712
sizediff_t minIndex (alias pred = " a < b" , Range )(Range range)
3752
3713
if (isForwardRange! Range && ! isInfinite! Range &&
@@ -3852,8 +3813,8 @@ if (isForwardRange!Range && !isInfinite!Range &&
3852
3813
/**
3853
3814
Computes the index of the first occurrence of `range`'s maximum element.
3854
3815
3855
- Complexity: O(n )
3856
- Exactly `n - 1` comparisons are needed.
3816
+ Complexity: $(BIGOH range )
3817
+ Exactly `range.length - 1` comparisons are needed.
3857
3818
3858
3819
Params:
3859
3820
pred = The ordering predicate to use to determine the maximum element.
@@ -3864,7 +3825,7 @@ Returns:
3864
3825
`range` is empty, -1 is returned.
3865
3826
3866
3827
See_Also:
3867
- $(REF max, std,algorithm,comparison), $(LREF maxCount), $(LREF maxElement), $(LREF maxPos)
3828
+ $(LREF minIndex), $( REF max, std,algorithm,comparison), $(LREF maxCount), $(LREF maxElement), $(LREF maxPos)
3868
3829
*/
3869
3830
sizediff_t maxIndex (alias pred = " a < b" , Range )(Range range)
3870
3831
if (isInputRange! Range && ! isInfinite! Range &&
0 commit comments