Skip to content

Commit 2f8e693

Browse files
authored
Merge pull request #4814 from e-y-e/fixflags
[trivial] [large diff] Update uses of Flag to use the Yes/No structs.
2 parents c5f2891 + befa0bf commit 2f8e693

File tree

12 files changed

+1031
-1031
lines changed

12 files changed

+1031
-1031
lines changed

std/algorithm/comparison.d

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import std.functional; // : unaryFun, binaryFun;
6060
import std.range.primitives;
6161
import std.traits;
6262
// FIXME
63-
import std.typecons; // : tuple, Tuple, Flag;
63+
import std.typecons; // : tuple, Tuple, Flag, Yes;
6464
import std.meta : allSatisfy;
6565

6666
/**
@@ -1805,8 +1805,8 @@ alias AllocateGC = Flag!"allocateGC";
18051805
/**
18061806
Checks if both ranges are permutations of each other.
18071807
1808-
This function can allocate if the $(D AllocateGC.yes) flag is passed. This has
1809-
the benefit of have better complexity than the $(D AllocateGC.no) option. However,
1808+
This function can allocate if the $(D Yes.allocateGC) flag is passed. This has
1809+
the benefit of have better complexity than the $(D Yes.allocateGC) option. However,
18101810
this option is only available for ranges whose equality can be determined via each
18111811
element's $(D toHash) method. If customized equality is needed, then the $(D pred)
18121812
template parameter can be passed, and the function will automatically switch to
@@ -1819,7 +1819,7 @@ Allocating forward range option: amortized $(BIGOH r1.length) + $(BIGOH r2.lengt
18191819
18201820
Params:
18211821
pred = an optional parameter to change how equality is defined
1822-
allocate_gc = AllocateGC.yes/no
1822+
allocate_gc = $(D Yes.allocateGC)/$(D No.allocateGC)
18231823
r1 = A finite forward range
18241824
r2 = A finite forward range
18251825
@@ -1830,7 +1830,7 @@ Returns:
18301830

18311831
bool isPermutation(AllocateGC allocate_gc, Range1, Range2)
18321832
(Range1 r1, Range2 r2)
1833-
if (allocate_gc == AllocateGC.yes &&
1833+
if (allocate_gc == Yes.allocateGC &&
18341834
isForwardRange!Range1 &&
18351835
isForwardRange!Range2 &&
18361836
!isInfinite!Range1 &&
@@ -1959,8 +1959,8 @@ bool isPermutation(alias pred = "a == b", Range1, Range2)
19591959
assert(!isPermutation([1, 1], [1, 1, 1]));
19601960

19611961
// Faster, but allocates GC handled memory
1962-
assert(isPermutation!(AllocateGC.yes)([1.1, 2.3, 3.5], [2.3, 3.5, 1.1]));
1963-
assert(!isPermutation!(AllocateGC.yes)([1, 2], [3, 4]));
1962+
assert(isPermutation!(Yes.allocateGC)([1.1, 2.3, 3.5], [2.3, 3.5, 1.1]));
1963+
assert(!isPermutation!(Yes.allocateGC)([1, 2], [3, 4]));
19641964
}
19651965

19661966
// Test @nogc inference
@@ -1985,23 +1985,23 @@ bool isPermutation(alias pred = "a == b", Range1, Range2)
19851985

19861986
auto r3 = new ReferenceForwardRange!int([1, 2, 3, 4]);
19871987
auto r4 = new ReferenceForwardRange!int([4, 2, 1, 3]);
1988-
assert(isPermutation!(AllocateGC.yes)(r3, r4));
1988+
assert(isPermutation!(Yes.allocateGC)(r3, r4));
19891989

19901990
auto r5 = new ReferenceForwardRange!int([1, 2, 3]);
19911991
auto r6 = new ReferenceForwardRange!int([4, 2, 1, 3]);
19921992
assert(!isPermutation(r5, r6));
19931993

19941994
auto r7 = new ReferenceForwardRange!int([4, 2, 1, 3]);
19951995
auto r8 = new ReferenceForwardRange!int([1, 2, 3]);
1996-
assert(!isPermutation!(AllocateGC.yes)(r7, r8));
1996+
assert(!isPermutation!(Yes.allocateGC)(r7, r8));
19971997

19981998
DummyRange!(ReturnBy.Reference, Length.Yes, RangeType.Random) r9;
19991999
DummyRange!(ReturnBy.Reference, Length.Yes, RangeType.Random) r10;
20002000
assert(isPermutation(r9, r10));
20012001

20022002
DummyRange!(ReturnBy.Reference, Length.Yes, RangeType.Random) r11;
20032003
DummyRange!(ReturnBy.Reference, Length.Yes, RangeType.Random) r12;
2004-
assert(isPermutation!(AllocateGC.yes)(r11, r12));
2004+
assert(isPermutation!(Yes.allocateGC)(r11, r12));
20052005

20062006
alias mytuple = Tuple!(int, int);
20072007

std/algorithm/searching.d

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ import std.functional; // : unaryFun, binaryFun;
102102
import std.range.primitives;
103103
import std.traits;
104104
// FIXME
105-
import std.typecons; // : Tuple, Flag;
105+
import std.typecons; // : Tuple, Flag, Yes, No;
106106

107107
/++
108108
Checks if $(I _all) of the elements verify $(D pred).
@@ -3959,8 +3959,8 @@ Params:
39593959
to iterate over.
39603960
sentinel = The element to stop at.
39613961
openRight = Determines whether the element for which the given predicate is
3962-
true should be included in the resulting range ($(D OpenRight.no)), or
3963-
not ($(D OpenRight.yes)).
3962+
true should be included in the resulting range ($(D No.openRight)), or
3963+
not ($(D Yes.openRight)).
39643964
39653965
Returns:
39663966
An $(REF_ALTTEXT input _range, isInputRange, std,_range,primitives) that
@@ -3971,7 +3971,7 @@ Returns:
39713971
*/
39723972
Until!(pred, Range, Sentinel)
39733973
until(alias pred = "a == b", Range, Sentinel)
3974-
(Range range, Sentinel sentinel, OpenRight openRight = OpenRight.yes)
3974+
(Range range, Sentinel sentinel, OpenRight openRight = Yes.openRight)
39753975
if (!is(Sentinel == OpenRight))
39763976
{
39773977
return typeof(return)(range, sentinel, openRight);
@@ -3980,7 +3980,7 @@ if (!is(Sentinel == OpenRight))
39803980
/// Ditto
39813981
Until!(pred, Range, void)
39823982
until(alias pred, Range)
3983-
(Range range, OpenRight openRight = OpenRight.yes)
3983+
(Range range, OpenRight openRight = Yes.openRight)
39843984
{
39853985
return typeof(return)(range, openRight);
39863986
}
@@ -4003,7 +4003,7 @@ struct Until(alias pred, Range, Sentinel) if (isInputRange!Range)
40034003
static if (!is(Sentinel == void))
40044004
///
40054005
this(Range input, Sentinel sentinel,
4006-
OpenRight openRight = OpenRight.yes)
4006+
OpenRight openRight = Yes.openRight)
40074007
{
40084008
_input = input;
40094009
_sentinel = sentinel;
@@ -4012,7 +4012,7 @@ struct Until(alias pred, Range, Sentinel) if (isInputRange!Range)
40124012
}
40134013
else
40144014
///
4015-
this(Range input, OpenRight openRight = OpenRight.yes)
4015+
this(Range input, OpenRight openRight = Yes.openRight)
40164016
{
40174017
_input = input;
40184018
_openRight = openRight;
@@ -4089,7 +4089,7 @@ struct Until(alias pred, Range, Sentinel) if (isInputRange!Range)
40894089
import std.algorithm.comparison : equal;
40904090
int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5];
40914091
assert(equal(a.until(7), [1, 2, 4][]));
4092-
assert(equal(a.until(7, OpenRight.no), [1, 2, 4, 7][]));
4092+
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7][]));
40934093
}
40944094

40954095
@safe unittest
@@ -4099,20 +4099,20 @@ struct Until(alias pred, Range, Sentinel) if (isInputRange!Range)
40994099
int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5];
41004100

41014101
static assert(isForwardRange!(typeof(a.until(7))));
4102-
static assert(isForwardRange!(typeof(until!"a == 2"(a, OpenRight.no))));
4102+
static assert(isForwardRange!(typeof(until!"a == 2"(a, No.openRight))));
41034103

41044104
assert(equal(a.until(7), [1, 2, 4][]));
41054105
assert(equal(a.until([7, 2]), [1, 2, 4, 7][]));
4106-
assert(equal(a.until(7, OpenRight.no), [1, 2, 4, 7][]));
4107-
assert(equal(until!"a == 2"(a, OpenRight.no), [1, 2][]));
4106+
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7][]));
4107+
assert(equal(until!"a == 2"(a, No.openRight), [1, 2][]));
41084108
}
41094109

41104110
unittest // bugzilla 13171
41114111
{
41124112
import std.algorithm.comparison : equal;
41134113
import std.range;
41144114
auto a = [1, 2, 3, 4];
4115-
assert(equal(refRange(&a).until(3, OpenRight.no), [1, 2, 3]));
4115+
assert(equal(refRange(&a).until(3, No.openRight), [1, 2, 3]));
41164116
assert(a == [4]);
41174117
}
41184118

std/algorithm/setops.d

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import std.traits;
4646
import std.meta; // : AliasSeq, staticMap, allSatisfy, anySatisfy;
4747

4848
import std.algorithm.sorting; // : Merge;
49+
import std.typecons : No;
4950

5051
// cartesianProduct
5152
/**
@@ -574,7 +575,7 @@ duplicate in between calls).
574575
*/
575576
void largestPartialIntersection
576577
(alias less = "a < b", RangeOfRanges, Range)
577-
(RangeOfRanges ror, Range tgt, SortOutput sorted = SortOutput.no)
578+
(RangeOfRanges ror, Range tgt, SortOutput sorted = No.sortOutput)
578579
{
579580
struct UnitWeights
580581
{
@@ -631,7 +632,7 @@ Params:
631632
*/
632633
void largestPartialIntersectionWeighted
633634
(alias less = "a < b", RangeOfRanges, Range, WeightsAA)
634-
(RangeOfRanges ror, Range tgt, WeightsAA weights, SortOutput sorted = SortOutput.no)
635+
(RangeOfRanges ror, Range tgt, WeightsAA weights, SortOutput sorted = No.sortOutput)
635636
{
636637
import std.algorithm.iteration : group;
637638
import std.algorithm.sorting : topNCopy;
@@ -672,7 +673,7 @@ unittest
672673
unittest
673674
{
674675
import std.conv : text;
675-
import std.typecons : tuple, Tuple;
676+
import std.typecons : tuple, Tuple, Yes;
676677

677678
debug(std_algorithm) scope(success)
678679
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
@@ -686,7 +687,7 @@ unittest
686687
[ 7 ],
687688
];
688689
auto b = new Tuple!(double, uint)[2];
689-
largestPartialIntersection(a, b, SortOutput.yes);
690+
largestPartialIntersection(a, b, Yes.sortOutput);
690691
//sort(b);
691692
//writeln(b);
692693
assert(b == [ tuple(7.0, 4u), tuple(1.0, 3u) ][], text(b));
@@ -696,7 +697,7 @@ unittest
696697
unittest
697698
{
698699
import std.conv : text;
699-
import std.typecons : tuple, Tuple;
700+
import std.typecons : tuple, Tuple, Yes;
700701

701702
debug(std_algorithm) scope(success)
702703
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
@@ -710,7 +711,7 @@ unittest
710711
[ "7" ],
711712
];
712713
auto b = new Tuple!(string, uint)[2];
713-
largestPartialIntersection(a, b, SortOutput.yes);
714+
largestPartialIntersection(a, b, Yes.sortOutput);
714715
//writeln(b);
715716
assert(b == [ tuple("7", 4u), tuple("1", 3u) ][], text(b));
716717
}

std/algorithm/sorting.d

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,7 +3148,7 @@ Params:
31483148
Returns: The slice of `target` containing the copied elements.
31493149
*/
31503150
TRange topNCopy(alias less = "a < b", SRange, TRange)
3151-
(SRange source, TRange target, SortOutput sorted = SortOutput.no)
3151+
(SRange source, TRange target, SortOutput sorted = No.sortOutput)
31523152
if (isInputRange!(SRange) && isRandomAccessRange!(TRange)
31533153
&& hasLength!(TRange) && hasSlicing!(TRange))
31543154
{
@@ -3158,7 +3158,7 @@ TRange topNCopy(alias less = "a < b", SRange, TRange)
31583158
auto heap = BinaryHeap!(TRange, less)(target, 0);
31593159
foreach (e; source) heap.conditionalInsert(e);
31603160
auto result = target[0 .. heap.length];
3161-
if (sorted == SortOutput.yes)
3161+
if (sorted == Yes.sortOutput)
31623162
{
31633163
while (!heap.empty) heap.removeFront();
31643164
}
@@ -3170,7 +3170,7 @@ unittest
31703170
{
31713171
int[] a = [ 10, 16, 2, 3, 1, 5, 0 ];
31723172
int[] b = new int[3];
3173-
topNCopy(a, b, SortOutput.yes);
3173+
topNCopy(a, b, Yes.sortOutput);
31743174
assert(b == [ 0, 1, 2 ]);
31753175
}
31763176

@@ -3187,7 +3187,7 @@ unittest
31873187
randomShuffle(a, r);
31883188
auto n = uniform(0, a.length, r);
31893189
ptrdiff_t[] b = new ptrdiff_t[n];
3190-
topNCopy!(binaryFun!("a < b"))(a, b, SortOutput.yes);
3190+
topNCopy!(binaryFun!("a < b"))(a, b, Yes.sortOutput);
31913191
assert(isSorted!(binaryFun!("a < b"))(b));
31923192
}
31933193

@@ -3225,7 +3225,7 @@ ignored.
32253225
*/
32263226
void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
32273227
Range, RangeIndex)
3228-
(Range r, RangeIndex index, SortOutput sorted = SortOutput.no)
3228+
(Range r, RangeIndex index, SortOutput sorted = No.sortOutput)
32293229
if (isRandomAccessRange!Range &&
32303230
isRandomAccessRange!RangeIndex &&
32313231
hasAssignableElements!RangeIndex &&
@@ -3249,7 +3249,7 @@ void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
32493249
{
32503250
heap.conditionalInsert(cast(ElementType!RangeIndex) i);
32513251
}
3252-
if (sorted == SortOutput.yes)
3252+
if (sorted == Yes.sortOutput)
32533253
{
32543254
while (!heap.empty) heap.removeFront();
32553255
}
@@ -3258,7 +3258,7 @@ void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
32583258
/// ditto
32593259
void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
32603260
Range, RangeIndex)
3261-
(Range r, RangeIndex index, SortOutput sorted = SortOutput.no)
3261+
(Range r, RangeIndex index, SortOutput sorted = No.sortOutput)
32623262
if (isRandomAccessRange!Range &&
32633263
isRandomAccessRange!RangeIndex &&
32643264
hasAssignableElements!RangeIndex &&
@@ -3280,7 +3280,7 @@ void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
32803280
{
32813281
heap.conditionalInsert(&r[i]);
32823282
}
3283-
if (sorted == SortOutput.yes)
3283+
if (sorted == Yes.sortOutput)
32843284
{
32853285
while (!heap.empty) heap.removeFront();
32863286
}
@@ -3292,12 +3292,12 @@ unittest
32923292
// Construct index to top 3 elements using numerical indices:
32933293
int[] a = [ 10, 2, 7, 5, 8, 1 ];
32943294
int[] index = new int[3];
3295-
topNIndex(a, index, SortOutput.yes);
3295+
topNIndex(a, index, Yes.sortOutput);
32963296
assert(index == [5, 1, 3]); // because a[5]==1, a[1]==2, a[3]==5
32973297

32983298
// Construct index to top 3 elements using pointer indices:
32993299
int*[] ptrIndex = new int*[3];
3300-
topNIndex(a, ptrIndex, SortOutput.yes);
3300+
topNIndex(a, ptrIndex, Yes.sortOutput);
33013301
assert(ptrIndex == [ &a[5], &a[1], &a[3] ]);
33023302
}
33033303

@@ -3311,14 +3311,14 @@ unittest
33113311
{
33123312
int[] a = [ 10, 8, 9, 2, 4, 6, 7, 1, 3, 5 ];
33133313
int*[] b = new int*[5];
3314-
topNIndex!("a > b")(a, b, SortOutput.yes);
3314+
topNIndex!("a > b")(a, b, Yes.sortOutput);
33153315
//foreach (e; b) writeln(*e);
33163316
assert(b == [ &a[0], &a[2], &a[1], &a[6], &a[5]]);
33173317
}
33183318
{
33193319
int[] a = [ 10, 8, 9, 2, 4, 6, 7, 1, 3, 5 ];
33203320
auto b = new ubyte[5];
3321-
topNIndex!("a > b")(a, b, SortOutput.yes);
3321+
topNIndex!("a > b")(a, b, Yes.sortOutput);
33223322
//foreach (e; b) writeln(e, ":", a[e]);
33233323
assert(b == [ cast(ubyte) 0, cast(ubyte)2, cast(ubyte)1, cast(ubyte)6, cast(ubyte)5], text(b));
33243324
}

0 commit comments

Comments
 (0)