StrVec Class Definition
Having sketched the implementation, we can now define our StrVec class:
// simplified implementation of the memory allocation strategy for a vector-like class class StrVec { public: StrVec(): // the allocator member is default initialized elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(const StrVec&); // copy constructor StrVec &operator=(const StrVec&); // copy assignment ~StrVec(); // destructor void push_back(const std::string&); // copy the element size_t size() const { return first_free - elements; } size_t capacity() const { return cap - elements; } std::string *begin() const { return elements; } std::string *end() const ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access