mirror of
https://github.com/dlang/phobos.git
synced 2025-05-06 11:07:39 +03:00
Merge remote-tracking branch 'upstream/stable' into merge_stable
This commit is contained in:
commit
87301eb1b5
7 changed files with 106 additions and 18 deletions
|
@ -35,7 +35,7 @@ $(T2 endsWith,
|
||||||
`endsWith("rocks", "ks")` returns `true`.)
|
`endsWith("rocks", "ks")` returns `true`.)
|
||||||
$(T2 find,
|
$(T2 find,
|
||||||
`find("hello world", "or")` returns `"orld"` using linear search.
|
`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,
|
$(T2 findAdjacent,
|
||||||
`findAdjacent([1, 2, 3, 3, 4])` returns the subrange starting with
|
`findAdjacent([1, 2, 3, 3, 4])` returns the subrange starting with
|
||||||
two equal adjacent elements, i.e. `[3, 3, 4]`.)
|
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]`,
|
`maxPos([2, 3, 1, 3, 4, 1])` returns the subrange `[4, 1]`,
|
||||||
i.e., positions the range at the first occurrence of its maximal
|
i.e., positions the range at the first occurrence of its maximal
|
||||||
element.)
|
element.)
|
||||||
$(T2 mismatch,
|
|
||||||
`mismatch("parakeet", "parachute")` returns the two ranges
|
|
||||||
`"keet"` and `"chute"`.)
|
|
||||||
$(T2 skipOver,
|
$(T2 skipOver,
|
||||||
Assume `a = "blah"`. Then `skipOver(a, "bi")` leaves `a`
|
Assume `a = "blah"`. Then `skipOver(a, "bi")` leaves `a`
|
||||||
unchanged and returns `false`, whereas `skipOver(a, "bl")`
|
unchanged and returns `false`, whereas `skipOver(a, "bl")`
|
||||||
|
|
|
@ -8,8 +8,7 @@ $(BOOKTABLE Cheat Sheet,
|
||||||
$(TR $(TH Function Name) $(TH Description))
|
$(TR $(TH Function Name) $(TH Description))
|
||||||
$(T2 completeSort,
|
$(T2 completeSort,
|
||||||
If `a = [10, 20, 30]` and `b = [40, 6, 15]`, then
|
If `a = [10, 20, 30]` and `b = [40, 6, 15]`, then
|
||||||
`completeSort(a, b)` leaves `a = [6, 10, 15]` and `b = [20$D(
|
`completeSort(a, b)` leaves `a = [6, 10, 15]` and `b = [20, 30, 40]`.
|
||||||
30, 40]).
|
|
||||||
The range `a` must be sorted prior to the call, and as a result the
|
The range `a` must be sorted prior to the call, and as a result the
|
||||||
combination `$(REF chain, std,range)(a, b)` is sorted.)
|
combination `$(REF chain, std,range)(a, b)` is sorted.)
|
||||||
$(T2 isPartitioned,
|
$(T2 isPartitioned,
|
||||||
|
|
|
@ -425,7 +425,8 @@ void assertThrown(T : Throwable = Exception, E)
|
||||||
from `Dg`'s safety and purity.
|
from `Dg`'s safety and purity.
|
||||||
+/
|
+/
|
||||||
template enforce(E : Throwable = Exception)
|
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,
|
T enforce(T)(T value, lazy const(char)[] msg = null,
|
||||||
|
|
|
@ -10,8 +10,8 @@ module std.experimental.all;
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
const r = 6.iota
|
const r = 6.iota
|
||||||
.filter!(a => a % 2) // 0 2 4
|
.filter!(a => a % 2) // 1 3 5
|
||||||
.map!(a => a * 2) // 0 4 8
|
.map!(a => a * 2) // 2 6 10
|
||||||
.tee!(_ => len++)
|
.tee!(_ => len++)
|
||||||
.sum
|
.sum
|
||||||
.reverseArgs!format("Sum: %d");
|
.reverseArgs!format("Sum: %d");
|
||||||
|
|
|
@ -7784,15 +7784,15 @@ if (isForwardRange!Source && hasLength!Source)
|
||||||
A fixed-sized sliding window iteration
|
A fixed-sized sliding window iteration
|
||||||
of size `windowSize` over a `source` range by a custom `stepSize`.
|
of size `windowSize` over a `source` range by a custom `stepSize`.
|
||||||
|
|
||||||
The `Source` range must be at least an `ForwardRange` and
|
The `Source` range must be at least a $(REF_ALTTEXT ForwardRange, isForwardRange, std,range,primitives)
|
||||||
the `windowSize` must be greater than zero.
|
and the `windowSize` must be greater than zero.
|
||||||
|
|
||||||
For `windowSize = 1` it splits the range into single element groups (aka `unflatten`)
|
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)`.
|
For `windowSize = 2` it is similar to `zip(source, source.save.dropOne)`.
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
f = Whether the last element with fewer elements than `windowSize`
|
f = Whether the last element has fewer elements than `windowSize`
|
||||||
should be be ignored (`Yes.withPartial`)
|
it should be be ignored (`No.withPartial`) or added (`Yes.withPartial`)
|
||||||
source = Range from which the slide will be selected
|
source = Range from which the slide will be selected
|
||||||
windowSize = Sliding window size
|
windowSize = Sliding window size
|
||||||
stepSize = Steps between the windows (by default 1)
|
stepSize = Steps between the windows (by default 1)
|
||||||
|
@ -7800,9 +7800,9 @@ Params:
|
||||||
Returns: Range of all sliding windows with propagated bi-directionality,
|
Returns: Range of all sliding windows with propagated bi-directionality,
|
||||||
forwarding, random access, and slicing.
|
forwarding, random access, and slicing.
|
||||||
|
|
||||||
Note: To avoid performance overhead, bi-directionality is only forwarded when
|
Note: To avoid performance overhead, $(REF_ALTTEXT bi-directionality, isBidirectionalRange, std,range,primitives)
|
||||||
$(REF hasSlicing, std,range,primitives) and $(REF hasLength, std,range,primitives)
|
is only available when $(REF hasSlicing, std,range,primitives)
|
||||||
are true.
|
and $(REF hasLength, std,range,primitives) are true.
|
||||||
|
|
||||||
See_Also: $(LREF chunks)
|
See_Also: $(LREF chunks)
|
||||||
*/
|
*/
|
||||||
|
@ -7870,6 +7870,20 @@ if (isForwardRange!Source)
|
||||||
assert(d == ["AG"d: 2, "GA"d: 2]);
|
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)
|
private struct Slides(Flag!"withPartial" withPartial = Yes.withPartial, Source)
|
||||||
if (isForwardRange!Source)
|
if (isForwardRange!Source)
|
||||||
{
|
{
|
||||||
|
|
63
std/stdio.d
63
std/stdio.d
|
@ -4695,6 +4695,8 @@ enum StdFileHandle: string
|
||||||
Due to $(LINK2 https://issues.dlang.org/show_bug.cgi?id=15768, bug 15768),
|
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
|
it is thread un-safe to reassign `stdin` to a different `File` instance
|
||||||
than the default.
|
than the default.
|
||||||
|
|
||||||
|
Returns: stdin as a $(LREF File).
|
||||||
*/
|
*/
|
||||||
alias stdin = makeGlobal!(StdFileHandle.stdin);
|
alias stdin = makeGlobal!(StdFileHandle.stdin);
|
||||||
|
|
||||||
|
@ -4707,7 +4709,8 @@ alias stdin = makeGlobal!(StdFileHandle.stdin);
|
||||||
import std.array : array;
|
import std.array : array;
|
||||||
import std.typecons : Yes;
|
import std.typecons : Yes;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
stdin // read from stdin
|
stdin // read from stdin
|
||||||
.byLineCopy(Yes.keepTerminator) // copying each line
|
.byLineCopy(Yes.keepTerminator) // copying each line
|
||||||
.array() // convert to array of lines
|
.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),
|
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
|
it is thread un-safe to reassign `stdout` to a different `File` instance
|
||||||
than the default.
|
than the default.
|
||||||
|
|
||||||
|
Returns: stdout as a $(LREF File).
|
||||||
*/
|
*/
|
||||||
alias stdout = makeGlobal!(StdFileHandle.stdout);
|
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.
|
The standard error stream.
|
||||||
Bugs:
|
Bugs:
|
||||||
Due to $(LINK2 https://issues.dlang.org/show_bug.cgi?id=15768, bug 15768),
|
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
|
it is thread un-safe to reassign `stderr` to a different `File` instance
|
||||||
than the default.
|
than the default.
|
||||||
|
|
||||||
|
Returns: stderr as a $(LREF File).
|
||||||
*/
|
*/
|
||||||
alias stderr = makeGlobal!(StdFileHandle.stderr);
|
alias stderr = makeGlobal!(StdFileHandle.stderr);
|
||||||
|
|
||||||
|
///
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
stderr.writeln("Write a message to stderr.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@system unittest
|
@system unittest
|
||||||
{
|
{
|
||||||
static import std.file;
|
static import std.file;
|
||||||
|
|
18
std/traits.d
18
std/traits.d
|
@ -8073,7 +8073,8 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
|
||||||
else static if (isFunction!member)
|
else static if (isFunction!member)
|
||||||
{
|
{
|
||||||
enum hasSpecificUDA(alias member) = hasUDA!(member, attribute);
|
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))
|
else static if (hasUDA!(member, attribute))
|
||||||
{
|
{
|
||||||
|
@ -8216,6 +8217,21 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
|
||||||
static assert(res[0].stringof == "a");
|
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.
|
Returns: $(D true) iff all types $(D T) are the same.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue