I have a class testthat is not standard constructive and assignable for certain reasons. However, it copies the construct - on may say that it behaves like a link.
Unfortunately, I need a dynamic array of these elements and realized that vector<test>this is not the right choice, because the vector elements must be standard constructive and assignable. Fortunately, I ran into this problem
- using
vector<T>::reserveand vector<T>::push_backinstead of vector<T>::resizedirect filling of records (without standard construction) copy'n'swap trick for assignment and the fact that a is vectorusually implemented using Pimpl-idiom (without directly assigning an existing element test), i.e.
class base {
private:
std::vector<test> vect;
public:
base& operator= (base y) {
swap(y);
return *this;
}
void swap(base& y) {
using std::swap;
swap(vect, y.vect);
}
};
Now I assume that I probably did not count every little bit, and, above all, these tricks are highly implementation dependent. The standard guarantees only the standard behavior of standard constructive and assignable types.
Now what's next? How to get a dynamic array of objects test?
Note: I should prefer the built-in solutions and classes provided by standard C ++.
: , . , . , : test?
(*) test , .