0

To give a complete example, let's say I have a template class that I now use to generate a type definition:

template <typename T>
struct A {};

using X = // I'm not asking about this
  A<int>; // I want to know what this is

What is the name of A<int>? My initial thoughts were that it was a generic specialisation of A, because I recall reading that somewhere in reference to the standard, but I can't find it now.

The answer should make reference to the standard or, if that is not possible, cite an authoritative source that sets some sort of precedent for how it is named.

I know these kinds of questions are borderline but I don't know of any other place to ask them and I've done my best to address the points raised in this meta discussion about questions on naming.

closed as primarily opinion-based by user40980, gnat, durron597, user22815, GlenH7 Aug 4 '15 at 18:23

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • en.cppreference.com/w/cpp/language/type_alias. In the standard the technical term would be "alias-declaration". – Jesse Good Oct 19 '14 at 5:30
  • A<int> is an instantiated template (or sometimes a template instantiation) – Basile Starynkevitch Oct 19 '14 at 7:52
  • I guess my question is more about what A<int> is in comparison to an actual specialisation, I should have made that clearer. – quant Oct 19 '14 at 9:27
  • How is this question "primarily opinion-based?" Call it off-topic if you want because "name that thing" is not on-topic, but there is a well-defined answer to this question. – user22815 Aug 4 '15 at 2:42
  • 1
    I'm voting to close this question as off-topic because it is asking "name that thing." – user22815 Aug 4 '15 at 2:43
4

It's just an alias: it takes A<T> , instantiate it with T=int and calls it X

Declare X a; and a will be an A<int>.

The documentation is as cppreference

Here are some references.

About A it is a "template instantiation": the generic type A is compiled using int in the place of T.

It is like vector<int> respect to vector<double> starting from vector<T>

  • 1
    I think I didn't explain it very well, but I'm not interested in what the using statement is, but rather A<int>. – quant Oct 19 '14 at 7:44
  • Great, thanks. So if I wanted to distinguish between a specialised instantiation and a normal template instantiation, e.g. std::vector<bool> and std::vector<double> could I refer to the latter as a "generic specialisation"? – quant Oct 19 '14 at 9:26
  • No. vector<T> is a "geberic type" because T is a formal parameter (and not an existing type). The declaration is template<class T> class vector { ... };. vector<int> a is the declaration of the variable a of type vector<int>; vector<bool> b is the declaration of the variable b of type vector<bool>; The fact the actual code of vector<int> and vector<bool> is different depends on the fact there is a template<> class vector<bool>{...}; somewhere in the <vector> header, not on the fact the vector<bool> is used here or there to instantiate this or that variable. – Emilio Garavaglia Oct 19 '14 at 15:43
  • Note that vector<T> a; is not the declaration of 'a' of type vector<T>: is just a syntax error. – Emilio Garavaglia Oct 19 '14 at 15:45
1

Scott Meyers' Effective Modern C++ mentions "function templates (i.e., templates that generate functions) and template functions (i.e., the functions generated from function templates)."

A can be called a struct template, and A<int> can be called a template struct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.