@@ -1319,7 +1319,34 @@ private struct FilterBidiResult(alias pred, Range)
1319
1319
}
1320
1320
}
1321
1321
1322
- // group
1322
+ /**
1323
+ Groups consecutively equivalent elements into a single tuple of the element and
1324
+ the number of its repetitions.
1325
+
1326
+ Similarly to $(D uniq), $(D group) produces a range that iterates over unique
1327
+ consecutive elements of the given range. Each element of this range is a tuple
1328
+ of the element and the number of times it is repeated in the original range.
1329
+ Equivalence of elements is assessed by using the predicate $(D pred), which
1330
+ defaults to $(D "a == b"). The predicate is passed to $(XREF functional,binaryFun),
1331
+ and can either accept a string, or any callable that can be executed via
1332
+ $(D pred(element, element)).
1333
+
1334
+ Params:
1335
+ pred = Binary predicate for determining equivalence of two elements.
1336
+ r = The $(XREF_PACK_NAMED range,primitives,isInputRange,input range) to
1337
+ iterate over.
1338
+
1339
+ Returns: A range of elements of type $(D Tuple!(ElementType!R, uint)),
1340
+ representing each consecutively unique element and its respective number of
1341
+ occurrences in that run. This will be an input range if $(D R) is an input
1342
+ range, and a forward range in all other cases.
1343
+ */
1344
+ Group! (pred, Range ) group(alias pred = " a == b" , Range )(Range r)
1345
+ {
1346
+ return typeof (return )(r);
1347
+ }
1348
+
1349
+ // / ditto
1323
1350
struct Group (alias pred, R) if (isInputRange! R)
1324
1351
{
1325
1352
import std.typecons : Rebindable, tuple, Tuple ;
@@ -1344,12 +1371,14 @@ struct Group(alias pred, R) if (isInputRange!R)
1344
1371
private R _input;
1345
1372
private Tuple ! (MutableE, uint ) _current;
1346
1373
1374
+ // /
1347
1375
this (R input)
1348
1376
{
1349
1377
_input = input;
1350
1378
if (! _input.empty) popFront();
1351
1379
}
1352
1380
1381
+ // /
1353
1382
void popFront ()
1354
1383
{
1355
1384
if (_input.empty)
@@ -1370,23 +1399,27 @@ struct Group(alias pred, R) if (isInputRange!R)
1370
1399
1371
1400
static if (isInfinite! R)
1372
1401
{
1402
+ // /
1373
1403
enum bool empty = false ; // Propagate infiniteness.
1374
1404
}
1375
1405
else
1376
1406
{
1407
+ // /
1377
1408
@property bool empty()
1378
1409
{
1379
1410
return _current[1 ] == 0 ;
1380
1411
}
1381
1412
}
1382
1413
1414
+ // /
1383
1415
@property auto ref front()
1384
1416
{
1385
1417
assert (! empty);
1386
1418
return _current;
1387
1419
}
1388
1420
1389
1421
static if (isForwardRange! R) {
1422
+ // /
1390
1423
@property typeof (this ) save() {
1391
1424
typeof (this ) ret = this ;
1392
1425
ret._input = this ._input.save;
@@ -1396,33 +1429,6 @@ struct Group(alias pred, R) if (isInputRange!R)
1396
1429
}
1397
1430
}
1398
1431
1399
- /**
1400
- Groups consecutively equivalent elements into a single tuple of the element and
1401
- the number of its repetitions.
1402
-
1403
- Similarly to $(D uniq), $(D group) produces a range that iterates over unique
1404
- consecutive elements of the given range. Each element of this range is a tuple
1405
- of the element and the number of times it is repeated in the original range.
1406
- Equivalence of elements is assessed by using the predicate $(D pred), which
1407
- defaults to $(D "a == b"). The predicate is passed to $(XREF functional,binaryFun),
1408
- and can either accept a string, or any callable that can be executed via
1409
- $(D pred(element, element)).
1410
-
1411
- Params:
1412
- pred = Binary predicate for determining equivalence of two elements.
1413
- r = The $(XREF_PACK_NAMED range,primitives,isInputRange,input range) to
1414
- iterate over.
1415
-
1416
- Returns: A range of elements of type $(D Tuple!(ElementType!R, uint)),
1417
- representing each consecutively unique element and its respective number of
1418
- occurrences in that run. This will be an input range if $(D R) is an input
1419
- range, and a forward range in all other cases.
1420
- */
1421
- Group! (pred, Range ) group(alias pred = " a == b" , Range )(Range r)
1422
- {
1423
- return typeof (return )(r);
1424
- }
1425
-
1426
1432
// /
1427
1433
@safe unittest
1428
1434
{
@@ -4874,13 +4880,31 @@ private struct UniqResult(alias pred, Range)
4874
4880
}
4875
4881
}
4876
4882
4877
- // permutations
4883
+ /**
4884
+ Lazily computes all _permutations of $(D r) using $(WEB
4885
+ en.wikipedia.org/wiki/Heap%27s_algorithm, Heap's algorithm).
4886
+
4887
+ Returns:
4888
+ A forward range the elements of which are an $(XREF range,
4889
+ indexed) view into $(D r).
4890
+
4891
+ See_Also:
4892
+ $(XREF_PACK algorithm,sorting,nextPermutation).
4893
+ */
4894
+ Permutations! Range permutations (Range )(Range r)
4895
+ if (isRandomAccessRange! Range && hasLength! Range )
4896
+ {
4897
+ return typeof (return )(r);
4898
+ }
4899
+
4900
+ // / ditto
4878
4901
struct Permutations (Range )
4879
4902
if (isRandomAccessRange! Range && hasLength! Range )
4880
4903
{
4881
4904
size_t [] indices, state;
4882
4905
Range r;
4883
4906
4907
+ // /
4884
4908
this (Range r)
4885
4909
{
4886
4910
import std.range : iota;
@@ -4892,14 +4916,17 @@ struct Permutations(Range)
4892
4916
empty = r.length == 0 ;
4893
4917
}
4894
4918
4919
+ // /
4895
4920
bool empty;
4896
4921
4922
+ // /
4897
4923
@property auto front()
4898
4924
{
4899
4925
import std.range : indexed;
4900
4926
return r.indexed(indices);
4901
4927
}
4902
4928
4929
+ // /
4903
4930
void popFront ()
4904
4931
{
4905
4932
void next (int n)
@@ -4928,23 +4955,6 @@ struct Permutations(Range)
4928
4955
}
4929
4956
}
4930
4957
4931
- /**
4932
- Lazily computes all _permutations of $(D r) using $(WEB
4933
- en.wikipedia.org/wiki/Heap%27s_algorithm, Heap's algorithm).
4934
-
4935
- Returns:
4936
- A forward range the elements of which are an $(XREF range,
4937
- indexed) view into $(D r).
4938
-
4939
- See_Also:
4940
- $(XREF_PACK algorithm,sorting,nextPermutation).
4941
- */
4942
- Permutations! Range permutations (Range )(Range r)
4943
- if (isRandomAccessRange! Range && hasLength! Range )
4944
- {
4945
- return typeof (return )(r);
4946
- }
4947
-
4948
4958
// /
4949
4959
unittest
4950
4960
{
0 commit comments