Suppose there is a certain class_adapter like this:
template <typename T> class Sequence { std::vector<T> v; public: explicit Sequence(size_t n = 0) : v(n) {} void push(const T& i) { v.push_back(i); } T& operator [](const size_t i) { return v[i]; } bool empty() const { return v.empty(); } size_t size() const { return v.size(); } //... } The same can be expressed by closed (protected) inheritance. For example:
template < typename T > class Alternative : private std::vector<T> { using Rep = std::vector<T>; public: explicit Alternative(size_t n = 0) : Rep(n) {} void push(const T& i) { Rep::push_back(i); } T& operator [](const size_t i) { return Rep::operator [](i); } bool empty() const { return Rep::empty(); } size_t size() const { return Rep::size(); } //... }; In what cases the closed inheritance is preferable to aggregation? .. (examples made up)
std::string_viewin relation tostd::string. - isnullxbh