VS2010
I have a structure with unique_ptrinside. Then I have vectorthis structure. If I try to resize (or use the reserve) to a vector, I get compilation errors. Below is a stripped-down example that still detects the problem.
unique_ptr
vector
struct Test { unique_ptr<int> pValue; }; void test() { // this doesn't compile vector<Test> testVector; testVector.resize(5); // this also doesn't compile testVector.reserve(5); // this, of course, compiles vector<unique_ptr<int>> testVector2; testVector2.resize(5); testVector2.reserve(5); }
I receive complaints about access to private members unique_ptr(assignment operators). The compiler is trying to dynamically build Test &Test::operator =(const Test &)and Test::Test(const Test &). I donβt understand why the resize operation should call any of these functions (why not call the default constructor if necessary?). Both of them present problems because it is impossible to do with help unique_ptrbecause of const.
Test &Test::operator =(const Test &)
Test::Test(const Test &)
const
.: -)
, VS2010 ++ 11 ( ). Test noexcept move, unique_ptr. VS2010 Test. , , . vector noexcept move constructors , .
Test
( , )
, , , unique_ptr<> . , , resize(). , resize() . . , , - unique_ptr<> .
unique_ptr<>
resize()
, unique_ptr<> , vector<unique_ptr<>> . , .
vector<unique_ptr<>>
, , vector<Test>, , , . , shared_ptr<> , .
vector<Test>
shared_ptr<>