Skip to content

Commit ecde30e

Browse files
authored
Merge pull request #8554 from BBasile/tup-ctor
dtemplate Tuple, add a ctor taking num elements merged-on-behalf-of: Jacob Carlborg <jacob-carlborg@users.noreply.github.com>
2 parents 4dba41a + 292345b commit ecde30e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/dmd/dtemplate.d

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,17 @@ extern (C++) final class Tuple : RootObject
476476
{
477477
Objects objects;
478478

479+
extern (D) this() {}
480+
481+
/**
482+
Params:
483+
numObjects = The initial number of objects.
484+
*/
485+
extern (D) this(size_t numObjects)
486+
{
487+
objects.setDim(numObjects);
488+
}
489+
479490
// kludge for template.isType()
480491
override DYNCAST dyncast() const
481492
{
@@ -1151,11 +1162,10 @@ extern (C++) final class TemplateDeclaration : ScopeDsymbol
11511162
/* The extra initial template arguments
11521163
* now form the tuple argument.
11531164
*/
1154-
auto t = new Tuple();
1165+
auto t = new Tuple(ntargs - n);
11551166
assert(parameters.dim);
11561167
(*dedargs)[parameters.dim - 1] = t;
11571168

1158-
t.objects.setDim(ntargs - n);
11591169
for (size_t i = 0; i < t.objects.dim; i++)
11601170
{
11611171
t.objects[i] = (*tiargs)[n + i];
@@ -3727,8 +3737,7 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* param
37273737
else
37283738
{
37293739
// Create new tuple
3730-
auto tup = new Tuple();
3731-
tup.objects.setDim(tuple_dim);
3740+
auto tup = new Tuple(tuple_dim);
37323741
for (size_t i = 0; i < tuple_dim; i++)
37333742
{
37343743
Parameter arg = Parameter.getNth(t.parameters, nfparams - 1 + i);
@@ -3905,9 +3914,8 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* param
39053914

39063915
/* Create tuple from remaining args
39073916
*/
3908-
auto vt = new Tuple();
39093917
size_t vtdim = (tempdecl.isVariadic() ? t.tempinst.tiargs.dim : t.tempinst.tdtypes.dim) - i;
3910-
vt.objects.setDim(vtdim);
3918+
auto vt = new Tuple(vtdim);
39113919
for (size_t k = 0; k < vtdim; k++)
39123920
{
39133921
RootObject o;

0 commit comments

Comments
 (0)