Merge remote-tracking branch 'upstream/stable' into merge_stable

This commit is contained in:
Sebastian Wilzbach 2018-03-25 18:23:14 +02:00
commit 87301eb1b5
7 changed files with 106 additions and 18 deletions

View file

@ -35,7 +35,7 @@ $(T2 endsWith,
`endsWith("rocks", "ks")` returns `true`.)
$(T2 find,
`find("hello world", "or")` returns `"orld"` using linear search.
(For binary search refer to $(REF sortedRange, std,range).))
(For binary search refer to $(REF SortedRange, std,range).))
$(T2 findAdjacent,
`findAdjacent([1, 2, 3, 3, 4])` returns the subrange starting with
two equal adjacent elements, i.e. `[3, 3, 4]`.)
@ -79,9 +79,6 @@ $(T2 maxPos,
`maxPos([2, 3, 1, 3, 4, 1])` returns the subrange `[4, 1]`,
i.e., positions the range at the first occurrence of its maximal
element.)
$(T2 mismatch,
`mismatch("parakeet", "parachute")` returns the two ranges
`"keet"` and `"chute"`.)
$(T2 skipOver,
Assume `a = "blah"`. Then `skipOver(a, "bi")` leaves `a`
unchanged and returns `false`, whereas `skipOver(a, "bl")`

View file

@ -8,8 +8,7 @@ $(BOOKTABLE Cheat Sheet,
$(TR $(TH Function Name) $(TH Description))
$(T2 completeSort,
If `a = [10, 20, 30]` and `b = [40, 6, 15]`, then
`completeSort(a, b)` leaves `a = [6, 10, 15]` and `b = [20$D(
30, 40]).
`completeSort(a, b)` leaves `a = [6, 10, 15]` and `b = [20, 30, 40]`.
The range `a` must be sorted prior to the call, and as a result the
combination `$(REF chain, std,range)(a, b)` is sorted.)
$(T2 isPartitioned,

View file

@ -425,7 +425,8 @@ void assertThrown(T : Throwable = Exception, E)
from `Dg`'s safety and purity.
+/
template enforce(E : Throwable = Exception)
if (is(typeof(new E("", __FILE__, __LINE__)) : Throwable) || is(typeof(new E(__FILE__, __LINE__)) : Throwable))
if (is(typeof(new E("", string.init, size_t.init)) : Throwable) ||
is(typeof(new E(string.init, size_t.init)) : Throwable))
{
///
T enforce(T)(T value, lazy const(char)[] msg = null,

View file

@ -10,8 +10,8 @@ module std.experimental.all;
int len;
const r = 6.iota
.filter!(a => a % 2) // 0 2 4
.map!(a => a * 2) // 0 4 8
.filter!(a => a % 2) // 1 3 5
.map!(a => a * 2) // 2 6 10
.tee!(_ => len++)
.sum
.reverseArgs!format("Sum: %d");

View file

@ -7784,15 +7784,15 @@ if (isForwardRange!Source && hasLength!Source)
A fixed-sized sliding window iteration
of size `windowSize` over a `source` range by a custom `stepSize`.
The `Source` range must be at least an `ForwardRange` and
the `windowSize` must be greater than zero.
The `Source` range must be at least a $(REF_ALTTEXT ForwardRange, isForwardRange, std,range,primitives)
and the `windowSize` must be greater than zero.
For `windowSize = 1` it splits the range into single element groups (aka `unflatten`)
For `windowSize = 2` it is similar to `zip(source, source.save.dropOne)`.
Params:
f = Whether the last element with fewer elements than `windowSize`
should be be ignored (`Yes.withPartial`)
f = Whether the last element has fewer elements than `windowSize`
it should be be ignored (`No.withPartial`) or added (`Yes.withPartial`)
source = Range from which the slide will be selected
windowSize = Sliding window size
stepSize = Steps between the windows (by default 1)
@ -7800,9 +7800,9 @@ Params:
Returns: Range of all sliding windows with propagated bi-directionality,
forwarding, random access, and slicing.
Note: To avoid performance overhead, bi-directionality is only forwarded when
$(REF hasSlicing, std,range,primitives) and $(REF hasLength, std,range,primitives)
are true.
Note: To avoid performance overhead, $(REF_ALTTEXT bi-directionality, isBidirectionalRange, std,range,primitives)
is only available when $(REF hasSlicing, std,range,primitives)
and $(REF hasLength, std,range,primitives) are true.
See_Also: $(LREF chunks)
*/
@ -7870,6 +7870,20 @@ if (isForwardRange!Source)
assert(d == ["AG"d: 2, "GA"d: 2]);
}
/// withPartial only has an effect if last element in the range doesn't have the full size
@safe pure nothrow unittest
{
import std.algorithm.comparison : equal;
assert(5.iota.slide!(Yes.withPartial)(3, 4).equal!equal([[0, 1, 2], [4]]));
assert(6.iota.slide!(Yes.withPartial)(3, 4).equal!equal([[0, 1, 2], [4, 5]]));
assert(7.iota.slide!(Yes.withPartial)(3, 4).equal!equal([[0, 1, 2], [4, 5, 6]]));
assert(5.iota.slide!(No.withPartial)(3, 4).equal!equal([[0, 1, 2]]));
assert(6.iota.slide!(No.withPartial)(3, 4).equal!equal([[0, 1, 2]]));
assert(7.iota.slide!(No.withPartial)(3, 4).equal!equal([[0, 1, 2], [4, 5, 6]]));
}
private struct Slides(Flag!"withPartial" withPartial = Yes.withPartial, Source)
if (isForwardRange!Source)
{

View file

@ -4695,6 +4695,8 @@ enum StdFileHandle: string
Due to $(LINK2 https://issues.dlang.org/show_bug.cgi?id=15768, bug 15768),
it is thread un-safe to reassign `stdin` to a different `File` instance
than the default.
Returns: stdin as a $(LREF File).
*/
alias stdin = makeGlobal!(StdFileHandle.stdin);
@ -4707,7 +4709,8 @@ alias stdin = makeGlobal!(StdFileHandle.stdin);
import std.array : array;
import std.typecons : Yes;
void main() {
void main()
{
stdin // read from stdin
.byLineCopy(Yes.keepTerminator) // copying each line
.array() // convert to array of lines
@ -4723,18 +4726,76 @@ alias stdin = makeGlobal!(StdFileHandle.stdin);
Due to $(LINK2 https://issues.dlang.org/show_bug.cgi?id=15768, bug 15768),
it is thread un-safe to reassign `stdout` to a different `File` instance
than the default.
Returns: stdout as a $(LREF File).
*/
alias stdout = makeGlobal!(StdFileHandle.stdout);
///
@safe unittest
{
void main()
{
stdout.writeln("Write a message to stdout.");
}
}
///
@safe unittest
{
void main()
{
import std.algorithm.iteration : filter, map, sum;
import std.format : format;
import std.range : iota, tee;
int len;
const r = 6.iota
.filter!(a => a % 2) // 1 3 5
.map!(a => a * 2) // 2 6 10
.tee!(_ => stdout.writefln("len: %d", len++))
.sum;
assert(r == 18);
}
}
///
@safe unittest
{
void main()
{
import std.algorithm.mutation : copy;
import std.algorithm.iteration : map;
import std.format : format;
import std.range : iota;
10.iota
.map!(e => "N: %d".format(e))
.copy(stdout.lockingTextWriter()); // the OutputRange
}
}
/**
The standard error stream.
Bugs:
Due to $(LINK2 https://issues.dlang.org/show_bug.cgi?id=15768, bug 15768),
it is thread un-safe to reassign `stderr` to a different `File` instance
than the default.
Returns: stderr as a $(LREF File).
*/
alias stderr = makeGlobal!(StdFileHandle.stderr);
///
@safe unittest
{
void main()
{
stderr.writeln("Write a message to stderr.");
}
}
@system unittest
{
static import std.file;

View file

@ -8073,7 +8073,8 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
else static if (isFunction!member)
{
enum hasSpecificUDA(alias member) = hasUDA!(member, attribute);
alias getSymbolsByUDAImpl = Filter!(hasSpecificUDA, __traits(getOverloads, symbol, names[0]));
alias overloadsWithUDA = Filter!(hasSpecificUDA, __traits(getOverloads, symbol, names[0]));
alias getSymbolsByUDAImpl = AliasSeq!(overloadsWithUDA, tail);
}
else static if (hasUDA!(member, attribute))
{
@ -8216,6 +8217,21 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
static assert(res[0].stringof == "a");
}
// #18624: getSymbolsByUDA produces wrong result if one of the symbols having the UDA is a function
@safe unittest
{
enum Attr;
struct A
{
@Attr void a();
@Attr void a(int n);
void b();
@Attr void c();
}
static assert(getSymbolsByUDA!(A, Attr).stringof == "tuple(a, a, c)");
}
/**
Returns: $(D true) iff all types $(D T) are the same.
*/