vendredi 29 décembre 2017

extern template class vector

This started out as a question of: "Why isn't it possible to explicitly instantiate an std::vector of std::unique_ptr?" as in:

template class std::vector<std::unique_ptr<int>>;

although following explicit instantiations and variables are fine:

template class std::vector<int>;
template class std::unique_ptr<int>;

int main() {
    std::vector<int> ints;
    std::vector<std::unique_ptr<int>> pointers;
}

But the question changed to: "What would be the alternatives?"

I'll post my though walk-through to answer both, since I didn't find a question that felt similar enough. I am also looking for alternatives, if any other.

Aucun commentaire:

Enregistrer un commentaire