Copy-Control Members
Given our alloc_n_copy
and free
members, the copy-control members of our class are straightforward. The copy constructor calls alloc_n_copy
:
StrVec::StrVec(const StrVec &s) { // call alloc_n_copy to allocate exactly as many elements as in s auto newdata = alloc_n_copy(s.begin(), s.end()); elements = newdata.first; first_free = cap = newdata.second; }
and assigns the results from that call to the data members. The return value from alloc_n_copy
is a pair
of pointers. The first
pointer points to the first constructed element and the second
points just past the last constructed element. Because alloc_n_copy
allocates space for exactly as many elements as it is given, cap
also points just past the last constructed ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.