November 1999
Intermediate to advanced
240 pages
5h 22m
English
Difficulty: 8
How flexible can you make this simple container class? Hint: You'll learn more than a little about member templates along the way.
How can you best implement copy construction and copy assignment for the following fixed-length vector class? How can you provide maximum usability for construction and assignment? Hint: Think about the kinds of things that client code might want to do.
template<typename T, size_t size> class fixed_vector { public: typedef T* iterator; typedef const T* const_iterator; iterator begin() { return v_; } iterator end() { return v_+size; } const_iterator begin() const { return v_; } const_iterator end() const { return v_+size; } private: T v_[size]; }; ...