Skip to content

Commit befa0bf

Browse files
committed
Updated Flag uses to Yes/No structs
1 parent 46824b6 commit befa0bf

File tree

11 files changed

+498
-497
lines changed

11 files changed

+498
-497
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
@@ -2944,7 +2944,7 @@ Params:
29442944
Returns: The slice of `target` containing the copied elements.
29452945
*/
29462946
TRange topNCopy(alias less = "a < b", SRange, TRange)
2947-
(SRange source, TRange target, SortOutput sorted = SortOutput.no)
2947+
(SRange source, TRange target, SortOutput sorted = No.sortOutput)
29482948
if (isInputRange!(SRange) && isRandomAccessRange!(TRange)
29492949
&& hasLength!(TRange) && hasSlicing!(TRange))
29502950
{
@@ -2954,7 +2954,7 @@ TRange topNCopy(alias less = "a < b", SRange, TRange)
29542954
auto heap = BinaryHeap!(TRange, less)(target, 0);
29552955
foreach (e; source) heap.conditionalInsert(e);
29562956
auto result = target[0 .. heap.length];
2957-
if (sorted == SortOutput.yes)
2957+
if (sorted == Yes.sortOutput)
29582958
{
29592959
while (!heap.empty) heap.removeFront();
29602960
}
@@ -2966,7 +2966,7 @@ unittest
29662966
{
29672967
int[] a = [ 10, 16, 2, 3, 1, 5, 0 ];
29682968
int[] b = new int[3];
2969-
topNCopy(a, b, SortOutput.yes);
2969+
topNCopy(a, b, Yes.sortOutput);
29702970
assert(b == [ 0, 1, 2 ]);
29712971
}
29722972

@@ -2983,7 +2983,7 @@ unittest
29832983
randomShuffle(a, r);
29842984
auto n = uniform(0, a.length, r);
29852985
ptrdiff_t[] b = new ptrdiff_t[n];
2986-
topNCopy!(binaryFun!("a < b"))(a, b, SortOutput.yes);
2986+
topNCopy!(binaryFun!("a < b"))(a, b, Yes.sortOutput);
29872987
assert(isSorted!(binaryFun!("a < b"))(b));
29882988
}
29892989

@@ -3021,7 +3021,7 @@ ignored.
30213021
*/
30223022
void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
30233023
Range, RangeIndex)
3024-
(Range r, RangeIndex index, SortOutput sorted = SortOutput.no)
3024+
(Range r, RangeIndex index, SortOutput sorted = No.sortOutput)
30253025
if (isRandomAccessRange!Range &&
30263026
isRandomAccessRange!RangeIndex &&
30273027
hasAssignableElements!RangeIndex &&
@@ -3045,7 +3045,7 @@ void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
30453045
{
30463046
heap.conditionalInsert(cast(ElementType!RangeIndex) i);
30473047
}
3048-
if (sorted == SortOutput.yes)
3048+
if (sorted == Yes.sortOutput)
30493049
{
30503050
while (!heap.empty) heap.removeFront();
30513051
}
@@ -3054,7 +3054,7 @@ void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
30543054
/// ditto
30553055
void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
30563056
Range, RangeIndex)
3057-
(Range r, RangeIndex index, SortOutput sorted = SortOutput.no)
3057+
(Range r, RangeIndex index, SortOutput sorted = No.sortOutput)
30583058
if (isRandomAccessRange!Range &&
30593059
isRandomAccessRange!RangeIndex &&
30603060
hasAssignableElements!RangeIndex &&
@@ -3076,7 +3076,7 @@ void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
30763076
{
30773077
heap.conditionalInsert(&r[i]);
30783078
}
3079-
if (sorted == SortOutput.yes)
3079+
if (sorted == Yes.sortOutput)
30803080
{
30813081
while (!heap.empty) heap.removeFront();
30823082
}
@@ -3088,12 +3088,12 @@ unittest
30883088
// Construct index to top 3 elements using numerical indices:
30893089
int[] a = [ 10, 2, 7, 5, 8, 1 ];
30903090
int[] index = new int[3];
3091-
topNIndex(a, index, SortOutput.yes);
3091+
topNIndex(a, index, Yes.sortOutput);
30923092
assert(index == [5, 1, 3]); // because a[5]==1, a[1]==2, a[3]==5
30933093

30943094
// Construct index to top 3 elements using pointer indices:
30953095
int*[] ptrIndex = new int*[3];
3096-
topNIndex(a, ptrIndex, SortOutput.yes);
3096+
topNIndex(a, ptrIndex, Yes.sortOutput);
30973097
assert(ptrIndex == [ &a[5], &a[1], &a[3] ]);
30983098
}
30993099

@@ -3107,14 +3107,14 @@ unittest
31073107
{
31083108
int[] a = [ 10, 8, 9, 2, 4, 6, 7, 1, 3, 5 ];
31093109
int*[] b = new int*[5];
3110-
topNIndex!("a > b")(a, b, SortOutput.yes);
3110+
topNIndex!("a > b")(a, b, Yes.sortOutput);
31113111
//foreach (e; b) writeln(*e);
31123112
assert(b == [ &a[0], &a[2], &a[1], &a[6], &a[5]]);
31133113
}
31143114
{
31153115
int[] a = [ 10, 8, 9, 2, 4, 6, 7, 1, 3, 5 ];
31163116
auto b = new ubyte[5];
3117-
topNIndex!("a > b")(a, b, SortOutput.yes);
3117+
topNIndex!("a > b")(a, b, Yes.sortOutput);
31183118
//foreach (e; b) writeln(e, ":", a[e]);
31193119
assert(b == [ cast(ubyte) 0, cast(ubyte)2, cast(ubyte)1, cast(ubyte)6, cast(ubyte)5], text(b));
31203120
}

0 commit comments

Comments
 (0)