Is it possible to initialize a vector of vectors of non-copyable objects?
class obj : private boost::noncopyable {
// ...
};
vector<vector<obj> > v(10); // OK
for(int i = 0; i < v.size(); ++i)
v[i].resize(10); // ERROR
also
vector<vector<obj> > v(10, vector<obj>(10)); // ERROR
I understand why the above code won't compile. What I'm asking is whether there's a workaround. It seems that if std::vector
had a member function like resize_from_zero
that didn't need a copy constructor, then this would be doable.
(My question is about C++03, if this makes a difference)
This is not possible; C++03 requires that elements of a
vector
be CopyConstructible and Assignable.Rreference: C++03 [lib.containers.requirements]/3
where "these components" means
deque
,list
,queue
,stack
,vector
,map
,set
,bitset
.(There may or may not be some way to have it appear to work on a particular compiler, but that is beyond the scope of Standard C++).