Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions std/algorithm.d
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ template reduce(fun...) if (fun.length >= 1)
result = void;
foreach (i, T; result.Types)
{
emplaceRef(result[i], seed);
emplaceRef!T(result[i], seed);
}
r.popFront();
return reduce(result, r);
Expand Down Expand Up @@ -856,7 +856,7 @@ template reduce(fun...) if (fun.length >= 1)

foreach (i, T; result.Types)
{
emplaceRef(result[i], elem);
emplaceRef!T(result[i], elem);
}
}
}
Expand Down Expand Up @@ -1407,7 +1407,7 @@ void uninitializedFill(Range, Value)(Range range, Value filler)

// Must construct stuff by the book
for (; !range.empty; range.popFront())
emplaceRef(range.front, filler);
emplaceRef!T(range.front, filler);
}
else
// Doesn't matter whether fill is initialized or not
Expand Down
37 changes: 14 additions & 23 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
size_t i;
foreach (e; r)
{
emplaceRef(result[i], e);
emplaceRef!E(result[i], e);
++i;
}
return cast(E[])result;
Expand Down Expand Up @@ -110,6 +110,12 @@ unittest
static assert(bug12315[0].i == 123456789);
}

unittest
{
static struct S{int* p;}
auto a = array(immutable(S).init.repeat(5));
}

/**
Convert a narrow string to an array type that fully supports random access.
This is handled as a special case and always returns a $(D dchar[]),
Expand Down Expand Up @@ -1059,13 +1065,13 @@ void insertInPlace(T, U...)(ref T[] array, size_t pos, U stuff)
{
static if (is(E : T)) //ditto
{
emplaceRef(tmp[j++], stuff[i]);
emplaceRef!T(tmp[j++], stuff[i]);
}
else
{
foreach (v; stuff[i])
{
emplaceRef(tmp[j++], v);
emplaceRef!T(tmp[j++], v);
}
}
}
Expand Down Expand Up @@ -2434,12 +2440,7 @@ struct Appender(A : T[], T)
auto bigDataFun() @trusted nothrow { return _data.arr.ptr[0 .. len + 1];}
auto bigData = bigDataFun();

static if (is(Unqual!T == T))
alias uitem = item;
else
auto ref uitem() @trusted nothrow @property { return cast(Unqual!T)item;}

emplaceRef(bigData[len], uitem);
emplaceRef!T(bigData[len], item);

//We do this at the end, in case of exceptions
_data.arr = bigData;
Expand Down Expand Up @@ -2484,28 +2485,18 @@ struct Appender(A : T[], T)
auto bigDataFun() @trusted nothrow { return _data.arr.ptr[0 .. newlen];}
auto bigData = bigDataFun();

enum mustEmplace = is(typeof(bigData[0].opAssign(cast(Unqual!T)items.front))) ||
!is(typeof(bigData[0] = cast(Unqual!T)items.front));
alias UT = Unqual!T;

static if (is(typeof(_data.arr[] = items[])) && !mustEmplace)
static if (is(typeof(_data.arr[] = items[])) &&
!hasElaborateAssign!(Unqual!T) && isAssignable!(UT, ElementEncodingType!Range))
{
//pragma(msg, T.stringof); pragma(msg, Range.stringof);
bigData[len .. newlen] = items[];
}
else static if (is(Unqual!T == ElementType!Range))
{
foreach (ref it ; bigData[len .. newlen])
{
emplaceRef(it, items.front);
items.popFront();
}
}
else
{
static auto ref getUItem(U)(U item) @trusted {return cast(Unqual!T)item;}
foreach (ref it ; bigData[len .. newlen])
{
emplaceRef(it, getUItem(items.front));
emplaceRef!T(it, items.front);
items.popFront();
}
}
Expand Down
Loading