The following code is ok:
#include <memory>
#include <vector>
extern template class std::vector<int>;
template class std::vector<int>; // ok on copyable types
int main()
{
[[maybe_unused]] auto v1 = std::vector<int>{}; // ok
[[maybe_unused]] auto v2 = std::vector<std::unique_ptr<int>>{}; // ok
}
However, below is failed to compile:
#include <memory>
#include <vector>
extern template class std::vector<std::unique_ptr<int>>;
template class std::vector<std::unique_ptr<int>>; // error on move-only types
int main()
{
[[maybe_unused]] auto v1 = std::vector<int>{};
[[maybe_unused]] auto v2 = std::vector<std::unique_ptr<int>>{};
}
See: https://godbolt.org/z/8qe94oGx5
Why does extern template instantiation not work on move-only types?