@@ -51,7 +51,7 @@ if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
5151 size_t i;
5252 foreach (e; r)
5353 {
54- emplaceRef(result[i], e);
54+ emplaceRef! E (result[i], e);
5555 ++ i;
5656 }
5757 return cast (E[])result;
@@ -110,6 +110,12 @@ unittest
110110 static assert (bug12315[0 ].i == 123456789 );
111111}
112112
113+ unittest
114+ {
115+ static struct S {int * p;}
116+ auto a = array(immutable (S).init.repeat(5 ));
117+ }
118+
113119/**
114120Convert a narrow string to an array type that fully supports random access.
115121This is handled as a special case and always returns a $(D dchar[]),
@@ -1059,13 +1065,13 @@ void insertInPlace(T, U...)(ref T[] array, size_t pos, U stuff)
10591065 {
10601066 static if (is (E : T)) // ditto
10611067 {
1062- emplaceRef(tmp[j++ ], stuff[i]);
1068+ emplaceRef! T (tmp[j++ ], stuff[i]);
10631069 }
10641070 else
10651071 {
10661072 foreach (v; stuff[i])
10671073 {
1068- emplaceRef(tmp[j++ ], v);
1074+ emplaceRef! T (tmp[j++ ], v);
10691075 }
10701076 }
10711077 }
@@ -2434,12 +2440,7 @@ struct Appender(A : T[], T)
24342440 auto bigDataFun () @trusted nothrow { return _data.arr.ptr[0 .. len + 1 ];}
24352441 auto bigData = bigDataFun();
24362442
2437- static if (is (Unqual! T == T))
2438- alias uitem = item;
2439- else
2440- auto ref uitem () @trusted nothrow @property { return cast (Unqual! T)item;}
2441-
2442- emplaceRef(bigData[len], uitem);
2443+ emplaceRef! T(bigData[len], item);
24432444
24442445 // We do this at the end, in case of exceptions
24452446 _data.arr = bigData;
@@ -2484,28 +2485,18 @@ struct Appender(A : T[], T)
24842485 auto bigDataFun () @trusted nothrow { return _data.arr.ptr[0 .. newlen];}
24852486 auto bigData = bigDataFun();
24862487
2487- enum mustEmplace = is (typeof (bigData[0 ].opAssign(cast (Unqual! T)items.front))) ||
2488- ! is (typeof (bigData[0 ] = cast (Unqual! T)items.front));
2488+ alias UT = Unqual! T;
24892489
2490- static if (is (typeof (_data.arr[] = items[])) && ! mustEmplace)
2490+ static if (is (typeof (_data.arr[] = items[])) &&
2491+ ! hasElaborateAssign! (Unqual! T) && isAssignable! (UT , ElementEncodingType! Range ))
24912492 {
2492- // pragma(msg, T.stringof); pragma(msg, Range.stringof);
24932493 bigData[len .. newlen] = items[];
24942494 }
2495- else static if (is (Unqual! T == ElementType! Range ))
2496- {
2497- foreach (ref it ; bigData[len .. newlen])
2498- {
2499- emplaceRef(it, items.front);
2500- items.popFront();
2501- }
2502- }
25032495 else
25042496 {
2505- static auto ref getUItem (U)(U item) @trusted {return cast (Unqual! T)item;}
25062497 foreach (ref it ; bigData[len .. newlen])
25072498 {
2508- emplaceRef(it, getUItem ( items.front) );
2499+ emplaceRef! T (it, items.front);
25092500 items.popFront();
25102501 }
25112502 }
0 commit comments