Is there a trick to explicitly instantiate deep template classes?
Asked Answered
C

2

2

I have a problem; I want to explicitly instantiate a class like Datatype in:

using Layout = some::namespaces::Meat_Layout<Some,Parameters>;
using Datatype = other::namespaces::Meta_Datatype<Layout>;

For explicit instantiation I need to use elaborated type specifiers. Which do not allow the usage of typedefs. Therefor I can not write:

template class Datatype;

But I have to write:

template class some::namespaces::Meta_Datatype<other::namespaces::Meat_Layout<Some,Parameters>>;

If there are any typedefs left in there I would have to replace them too, which might lead to something like:

template class some::namespaces::Meta_Datatype<other::namespaces::Meta_Meat_Layout<Some,Meta_Parameters<int>,int,int>>;

As you see this becomes really fast unclear.

Is there any trick to avoid the deconstruction of all the typedefs?

It would be best if it is also possible to use the trick when using extern template.

Cazzie answered 7/11, 2019 at 9:19 Comment(3)
What about namespace some::namespaces { template class Meta_Datatype<Meat_Layout<Some,Parameters>>; }? And you can use type aliases as template parameters.Dinnage
@Dinnage some improvement, but does not help with the typedefs. I will edit my question to outrule this improvementCazzie
ref. explicit class template instantiation : "Explicit instantiation can only appear in the enclosing namespace of the template, unless it uses qualified-id"Segura
D
1

You don't have to deconstruct all typedefs. Those used as template parameters can be left as is:

using Layout = some::namespaces::Meat_Layout<Some,Parameters>;
using Datatype = other::namespaces::Meta_Datatype<Layout>;

template class other::namespaces::Meta_Datatype<Layout>;
Dinnage answered 7/11, 2019 at 9:38 Comment(0)
B
1

Actually, you don't need to deconstruct all the typedefs. It's true that you cannot use typedef as explicitely instantiated template, but you can use typedefs as parameters of your template, like Evg said earlier.

As you already mentioned:

14.7.2 Explicit instantiation [temp.explicit]: If the explicit instantiation is for a class or member class, the elaborated-type-specifier in the declaration shall include a simple-template-id.

But any limitations on template arguments are not mentioned in the standard, so you freely can use any arguments in the explicit instantiation, including the typedefs.

Braud answered 7/11, 2019 at 9:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.