mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 09:00:22 +03:00
Merge remote-tracking branch 'upstream/stable' into merge_stable
This commit is contained in:
commit
d2e931f149
5 changed files with 66 additions and 7 deletions
|
@ -1392,7 +1392,7 @@ private T moveImpl(T)(ref T source)
|
|||
* source = value to be moved into target
|
||||
* target = uninitialized value to be filled by source
|
||||
*/
|
||||
void moveEmplace(T)(ref T source, ref T target) @system
|
||||
void moveEmplace(T)(ref T source, ref T target) pure @system
|
||||
{
|
||||
import core.stdc.string : memcpy, memset;
|
||||
import std.traits : hasAliasing, hasElaborateAssign,
|
||||
|
|
14
std/conv.d
14
std/conv.d
|
@ -1061,7 +1061,7 @@ if (!(isImplicitlyConvertible!(S, T) &&
|
|||
private T toImpl(T, S)(ref S value)
|
||||
if (!(isImplicitlyConvertible!(S, T) &&
|
||||
!isEnumStrToStr!(S, T) && !isNullToStr!(S, T)) &&
|
||||
!isInfinite!S && isExactSomeString!T && !isCopyable!S)
|
||||
!isInfinite!S && isExactSomeString!T && !isCopyable!S && !isStaticArray!S)
|
||||
{
|
||||
import std.array : appender;
|
||||
import std.format : FormatSpec, formatValue;
|
||||
|
@ -1100,6 +1100,18 @@ if (!(isImplicitlyConvertible!(S, T) &&
|
|||
assert(to!string(b) == "B(0, false)");
|
||||
}
|
||||
|
||||
// Bugzilla 20070
|
||||
@safe unittest
|
||||
{
|
||||
void writeThem(T)(ref inout(T) them)
|
||||
{
|
||||
assert(them.to!string == "[1, 2, 3, 4]");
|
||||
}
|
||||
|
||||
const(uint)[4] vals = [ 1, 2, 3, 4 ];
|
||||
writeThem(vals);
|
||||
}
|
||||
|
||||
/*
|
||||
Check whether type `T` can be used in a switch statement.
|
||||
This is useful for compile-time generation of switch case statements.
|
||||
|
|
|
@ -1175,7 +1175,7 @@ auto make(T, Allocator, A...)(auto ref Allocator alloc, auto ref A args)
|
|||
{
|
||||
// Assume cast is safe as allocation succeeded for `stateSize!T`
|
||||
auto p = () @trusted { return cast(T*) m.ptr; }();
|
||||
emplaceRef(*p, args);
|
||||
emplaceRef!T(*p, args);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
@ -1472,6 +1472,14 @@ if (T.sizeof != 1)
|
|||
assert(a == [ 42, 42, 42, 42, 42]);
|
||||
}
|
||||
|
||||
//Make shared object
|
||||
@system unittest
|
||||
{
|
||||
import core.atomic : atomicLoad;
|
||||
auto psi = theAllocator.make!(shared(int))(10);
|
||||
assert(10 == (*psi).atomicLoad());
|
||||
}
|
||||
|
||||
private T[] uninitializedFillDefault(T)(T[] array) nothrow
|
||||
{
|
||||
static if (__traits(isZeroInit, T))
|
||||
|
|
|
@ -10163,7 +10163,7 @@ do
|
|||
private:
|
||||
alias ElemType = Tuple!(Enumerator, "index", ElementType!Range, "value");
|
||||
Range range;
|
||||
Enumerator index;
|
||||
Unqual!Enumerator index;
|
||||
|
||||
public:
|
||||
ElemType front() @property
|
||||
|
@ -10272,6 +10272,14 @@ pure @safe nothrow unittest
|
|||
assert(aa[1]);
|
||||
}
|
||||
|
||||
// Make sure passing qualified types works
|
||||
pure @safe nothrow unittest
|
||||
{
|
||||
char[4] v;
|
||||
immutable start = 2;
|
||||
v[2 .. $].enumerate(start);
|
||||
}
|
||||
|
||||
pure @safe nothrow unittest
|
||||
{
|
||||
import std.internal.test.dummyrange : AllDummyRanges;
|
||||
|
|
|
@ -935,7 +935,7 @@ if (distinctFieldNames!(Specs))
|
|||
* It is an compile-time error to pass more names than
|
||||
* there are members of the $(LREF Tuple).
|
||||
*/
|
||||
ref rename(names...)() return
|
||||
ref rename(names...)() inout return
|
||||
if (names.length == 0 || allSatisfy!(isSomeString, typeof(names)))
|
||||
{
|
||||
import std.algorithm.comparison : equal;
|
||||
|
@ -1007,6 +1007,10 @@ if (distinctFieldNames!(Specs))
|
|||
.map!(t => t.a * t.b)
|
||||
.sum;
|
||||
assert(res == 68);
|
||||
|
||||
const tup = Tuple!(int, "a", int, "b")(2, 3);
|
||||
const renamed = tup.rename!("c", "d");
|
||||
assert(renamed.c + renamed.d == 5);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1019,7 +1023,7 @@ if (distinctFieldNames!(Specs))
|
|||
* The same rules for empty strings apply as for the variadic
|
||||
* template overload of $(LREF _rename).
|
||||
*/
|
||||
ref rename(alias translate)()
|
||||
ref rename(alias translate)() inout
|
||||
if (is(typeof(translate) : V[K], V, K) && isSomeString!V &&
|
||||
(isSomeString!K || is(K : size_t)))
|
||||
{
|
||||
|
@ -1087,6 +1091,11 @@ if (distinctFieldNames!(Specs))
|
|||
auto t2Named = t2.rename!(["a": "b", "b": "c"]);
|
||||
assert(t2Named.b == 3);
|
||||
assert(t2Named.c == 4);
|
||||
|
||||
const t3 = Tuple!(int, "a", int, "b")(3, 4);
|
||||
const t3Named = t3.rename!(["a": "b", "b": "c"]);
|
||||
assert(t3Named.b == 3);
|
||||
assert(t3Named.c == 4);
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -8780,7 +8789,7 @@ template ReplaceTypeUnless(alias pred, From, To, T...)
|
|||
static assert(0, "Function types not supported," ~
|
||||
" use a function pointer type instead of " ~ T[0].stringof);
|
||||
}
|
||||
else static if (is(T[0] : U!V, alias U, V...))
|
||||
else static if (is(T[0] == U!V, alias U, V...))
|
||||
{
|
||||
template replaceTemplateArgs(T...)
|
||||
{
|
||||
|
@ -9007,6 +9016,28 @@ private template replaceTypeInFunctionTypeUnless(alias pred, From, To, fun)
|
|||
static assert(is(B == A));
|
||||
}
|
||||
|
||||
|
||||
@safe unittest // Bugzilla 19696
|
||||
{
|
||||
static struct T(U) {}
|
||||
static struct S { T!int t; alias t this; }
|
||||
static assert(is(ReplaceType!(float, float, S) == S));
|
||||
}
|
||||
|
||||
@safe unittest // Bugzilla 19697
|
||||
{
|
||||
class D(T) {}
|
||||
class C : D!C {}
|
||||
static assert(is(ReplaceType!(float, float, C)));
|
||||
}
|
||||
|
||||
@safe unittest // Bugzilla 16132
|
||||
{
|
||||
interface I(T) {}
|
||||
class C : I!int {}
|
||||
static assert(is(ReplaceType!(int, string, C) == C));
|
||||
}
|
||||
|
||||
/**
|
||||
Ternary type with three truth values:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue