This is how standard library container templates are designed: the first argument of the template is the type of data contained (or the first two for associative containers).
Nothing prevents you from developing your own template in different ways, for example. as you suggest:
template <typename Backend> class my_stack { public: typedef Backend container_type; typedef typename container_type::value_type value_type; private: container_type container;
However, this design has two drawbacks:
It is not minimal and simple. If I need an int s stack, I have to think about the container myself, and I can't just say my_stack<int> .
It sets restrictions on the container, namely that it exposes the element type value_type . I can not say my_stack<my_insane_container<int>> .
Now you can overcome the second complaint like this:
template <typename> class my_crazy_stack; template <template <typename ...> class Tmpl, typename T, typename ...Args> class my_cazy_stack<Tmpl<T, Args...>> { public: typedef Tmpl<T, Args...> container_type; typedef T value_type;
But now you just made it even crazier: the container should now be a template (i.e., bye bye class my_specialized_int_container ), and it needs to take its value type as the first element (i.e., bye bye stack of stacks).
So, in short, the standard library design is pretty reasonable.
source share