@@ -21,7 +21,7 @@ module core.internal.array.construction;
21
21
* purity, and throwabilty checks. To prevent breaking existing code, this function template
22
22
* is temporarily declared `@trusted` until the implementation can be brought up to modern D expectations.
23
23
*/
24
- T[] _d_arrayctor (Tarr : T [], T )(scope Tarr from, size_t length ) @trusted
24
+ Tarr1 _d_arrayctor (Tarr1 : T1 [], Tarr2 : T2 [], T1 , T2 )(scope Tarr2 from) @trusted
25
25
{
26
26
pragma (inline, false );
27
27
import core.internal.traits : hasElaborateCopyConstructor, Unqual;
@@ -30,10 +30,9 @@ T[] _d_arrayctor(Tarr : T[], T)(scope Tarr from, size_t length) @trusted
30
30
import core.stdc.stdint : uintptr_t ;
31
31
debug (PRINTF ) import core.stdc.stdio : printf;
32
32
33
- debug (PRINTF ) printf(" _d_arrayctor(to = %p,%d, from = %p,%d) size = %d\n " , from.ptr, from.length, to.ptr, to.length, T .tsize);
33
+ debug (PRINTF ) printf(" _d_arrayctor(to = %p,%d, from = %p,%d) size = %d\n " , from.ptr, from.length, to.ptr, to.length, T1 .tsize);
34
34
35
- T[] to;
36
- to.length = length;
35
+ Tarr1 to = void ;
37
36
38
37
void [] vFrom = (cast (void * )from.ptr)[0 .. from.length];
39
38
void [] vTo = (cast (void * )to.ptr)[0 .. to.length];
@@ -49,13 +48,11 @@ T[] _d_arrayctor(Tarr : T[], T)(scope Tarr from, size_t length) @trusted
49
48
(cast (Type)&enforceRawArraysConformableNogc)(action, elementSize, a1, a2, false );
50
49
}
51
50
52
- enforceRawArraysConformable(" initialization" , T .sizeof, vFrom, vTo);
51
+ enforceRawArraysConformable(" initialization" , T1 .sizeof, vFrom, vTo);
53
52
54
- static if (hasElaborateCopyConstructor! T )
53
+ static if (hasElaborateCopyConstructor! T1 )
55
54
{
56
- // Use uint instead of size_t as a temporary workaround until this bug is fixed:
57
- // https://issues.dlang.org/show_bug.cgi?id=22372
58
- uint i;
55
+ size_t i;
59
56
try
60
57
{
61
58
for (i = 0 ; i < to.length; i++ )
@@ -67,7 +64,7 @@ T[] _d_arrayctor(Tarr : T[], T)(scope Tarr from, size_t length) @trusted
67
64
*/
68
65
while (i-- )
69
66
{
70
- auto elem = cast (Unqual! T * )&to[i];
67
+ auto elem = cast (Unqual! T1 * )&to[i];
71
68
destroy (* elem);
72
69
}
73
70
@@ -77,7 +74,7 @@ T[] _d_arrayctor(Tarr : T[], T)(scope Tarr from, size_t length) @trusted
77
74
else
78
75
{
79
76
// blit all elements at once
80
- memcpy(cast (void * ) to.ptr, from.ptr, to.length * T .sizeof);
77
+ memcpy(cast (void * ) to.ptr, from.ptr, to.length * T1 .sizeof);
81
78
}
82
79
83
80
return to;
@@ -95,7 +92,7 @@ T[] _d_arrayctor(Tarr : T[], T)(scope Tarr from, size_t length) @trusted
95
92
96
93
S[4 ] arr1;
97
94
S[4 ] arr2 = [S(0 ), S(1 ), S(2 ), S(3 )];
98
- arr1 = _d_arrayctor( arr2[], arr1.length );
95
+ arr1 = _d_arrayctor! ( typeof (arr1))( arr2[]);
99
96
100
97
assert (counter == 4 );
101
98
assert (arr1 == arr2);
@@ -118,7 +115,7 @@ T[] _d_arrayctor(Tarr : T[], T)(scope Tarr from, size_t length) @trusted
118
115
119
116
S[4 ] arr1;
120
117
S[4 ] arr2 = [S(0 ), S(1 ), S(2 ), S(3 )];
121
- arr1 = _d_arrayctor( arr2[], arr1.length );
118
+ arr1 = _d_arrayctor! ( typeof (arr1))( arr2[]);
122
119
123
120
assert (counter == 4 );
124
121
assert (arr1 == arr2);
@@ -144,7 +141,7 @@ T[] _d_arrayctor(Tarr : T[], T)(scope Tarr from, size_t length) @trusted
144
141
{
145
142
Throw[4 ] a;
146
143
Throw[4 ] b = [Throw(1 ), Throw(2 ), Throw(3 ), Throw(4 )];
147
- a = _d_arrayctor( b[], a.length );
144
+ a = _d_arrayctor! ( typeof (a))( b[]);
148
145
}
149
146
catch (Exception )
150
147
{
@@ -169,7 +166,7 @@ T[] _d_arrayctor(Tarr : T[], T)(scope Tarr from, size_t length) @trusted
169
166
{
170
167
NoThrow[4 ] a;
171
168
NoThrow[4 ] b = [NoThrow(1 ), NoThrow(2 ), NoThrow(3 ), NoThrow(4 )];
172
- a = _d_arrayctor( b[], a.length );
169
+ a = _d_arrayctor! ( typeof (a))( b[]);
173
170
}
174
171
catch (Exception )
175
172
{
@@ -276,7 +273,7 @@ void _d_arraysetctor(Tarr : T[], T)(scope Tarr p, scope ref T value) @trusted
276
273
{
277
274
Throw[4 ] a;
278
275
Throw[4 ] b = [Throw(1 ), Throw(2 ), Throw(3 ), Throw(4 )];
279
- a = _d_arrayctor( b[], a.length );
276
+ a = _d_arrayctor! ( typeof (a))( b[]);
280
277
}
281
278
catch (Exception )
282
279
{
0 commit comments