The C++ Language Standard states the following concerning template components in the Standard Library:
The effects are undefined...if an incomplete type is used as a template argument when instantiating a template component, unless specifically allowed for that component (C++11 §17.6.4.8/2).
Does the following cause instantiation of the std::vector
class template?
class X;
std::vector<X> f(); // Declaration only; we will define it when X is complete
To ask it another way, in the function declaration std::vector<X> f();
, is std::vector
instantiated with the argument X
? Or, is std::vector<X>
not instantiated until f()
is odr-used or defined?
Likewise, does the following cause instantiation of the std::vector
class template?
class X;
typedef std::vector<X> XVector; // We will complete X before we use XVector
While I use std::vector
in these examples, the question applies equally to all templates.