Merge pull request #3634 from MartinNowak/merge_stable

Merge remote-tracking branch 'upstream/stable' into merge_stable
This commit is contained in:
Hara Kenji 2015-09-08 01:46:43 +09:00
commit bb7e5fb3cc
5 changed files with 67 additions and 28 deletions

View file

@ -2534,8 +2534,10 @@ template reduce(fun...) if (fun.length >= 1)
foreach (/+auto ref+/ E e; r) // @@@4707@@@
{
foreach (i, f; binfuns)
static assert(is(typeof(args[i] = f(args[i], e))),
{
static assert(!is(typeof(f(args[i], e))) || is(typeof(args[i] = f(args[i], e))),
algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static if (mustInitialize) if (initialized == false)
{

View file

@ -430,6 +430,7 @@ assert(std.algorithm.equal(sl[], ["a", "b", "c", "d", "e"]));
size_t insertAfter(Stuff)(Range r, Stuff stuff)
{
initialize();
if (!_first)
{
enforce(!r._head);
@ -761,3 +762,11 @@ unittest
r.front = 1; //test frontAssign
assert(r.front == 1);
}
unittest
{
// issue 14920
SList!int s;
s.insertAfter(s[], 1);
assert(s.front == 1);
}

View file

@ -90,7 +90,7 @@ auto tempCString(To = char, From)(From str)
alias CF = Unqual!(ElementEncodingType!From);
enum To* useStack = null;
enum To* useStack = () @trusted { return cast(To*)size_t.max; }();
static struct Res
{
@ -182,7 +182,14 @@ auto tempCString(To = char, From)(From str)
}
import std.utf : byUTF;
static if (isSomeString!From)
{
auto r = cast(const(CF)[])str; // because inout(CF) causes problems with byUTF
if (r is null) // Bugzilla 14980
{
res._ptr = null;
return res;
}
}
else
alias r = str;
foreach (const c; byUTF!(Unqual!To)(r))
@ -232,8 +239,14 @@ nothrow @nogc unittest
assert(tempCString(abc[].byWchar).buffPtr.asArray == abc);
}
// Bugzilla 14980
nothrow @nogc unittest
{
const(char[]) str = null;
auto res = tempCString(str);
const char* ptr = res;
assert(ptr is null);
}
version(Windows)
alias tempCStringW = tempCString!(wchar, const(char)[]);

View file

@ -2824,36 +2824,13 @@ auto generate(Fun)(Fun fun)
return Generator!(Fun)(fun);
}
///
/// ditto
auto generate(alias fun)()
if (isCallable!fun)
{
return Generator!(fun)();
}
//private struct Generator(bool onPopFront, bool runtime, Fun...)
private struct Generator(Fun...)
{
static assert(Fun.length == 1);
static assert(isInputRange!Generator);
private:
static if (is(Fun[0]))
Fun[0] fun;
else
alias fun = Fun[0];
public:
enum empty = false;
auto ref front() @property
{
return fun();
}
void popFront() { }
}
///
@safe pure unittest
{
@ -2879,6 +2856,38 @@ public:
assert(equal(generate(infiniteIota(1, 4)).take(10), [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]));
}
///
unittest
{
import std.format, std.random;
auto r = generate!(() => uniform(0, 6)).take(10);
format("%(%s %)", r);
}
//private struct Generator(bool onPopFront, bool runtime, Fun...)
private struct Generator(Fun...)
{
static assert(Fun.length == 1);
static assert(isInputRange!Generator);
private:
static if (is(Fun[0]))
Fun[0] fun;
else
alias fun = Fun[0];
public:
enum empty = false;
auto ref front() @property
{
return fun();
}
void popFront() { }
}
@safe unittest
{
import std.algorithm : equal;

View file

@ -1061,6 +1061,12 @@ unittest
assert(results.length && results[0].family == AddressFamily.INET6);
}
});
if (getaddrinfoPointer)
{
auto results = getAddressInfo(null, "1234", AddressInfoFlags.PASSIVE, SocketType.STREAM, ProtocolType.TCP, AddressFamily.INET);
assert(results.length == 1 && results[0].address.toString() == "0.0.0.0:1234");
}
}