Logically, one would expect something like:
template<typename T, template<typenameU> class C = std::deque> class queue { protected: C<T> c; public:
The problem is that std::deque will not match the template argument, because actually it is:
template<typename T, typename Allocator = allocator<T> > class deque ...
An additional argument to the template does not allow it to work. And if an additional argument was added to the second queue parameter, then most custom containers cannot be used because they would not have a second argument. An electric current solution wraps around this problem (while resolving the client, the code to instantiate std::queue<float> , for example, without worrying about the basic type of container).
And in the end, why not? Your example std::queue<float, std::deque<std::string> > will probably not compile, but what's wrong with something like std::queue<bool, std::vector<char> > (avoiding the problematic std::vector<bool> )? As long as there is an implicit conversion in both directions, it is up to the client to do what he wants. (In practice, of course, this is almost never a problem, because it is rare for client code to specify a container.)
source share