For reference, the exact definition of std::queue
is listed here. So in answer to
In other words, does the standard state clearly that this variable must be named c
?
Yes, it is in this case (and it is similar for other container adapters);
template <class T, class Container = deque<T>>
class queue {
protected:
Container c;
// ...
};
In general, however, the names of the protected and private names and members are not standardised since the types are not all built to be derived from and the implementation is an implementation detail (and doesn't form part of the public API); e.g. std::vector
doesn't list any protected names.
Some std
containers and classes do define the names of protected
members, in particular the iostreams library comes to mind - basically the types that are intended to be derived from.
As a follow up - do all the compilers/libraries use c
? It appears as though at least the mainstream ones do (libstdc++, libc++ and MSVC). libstdc++ is interesting in that it includes the follow comment on the variable;
/**
* 'c' is the underlying container. Maintainers wondering why
* this isn't uglified as per style guidelines should note that
* this name is specified in the standard, [23.2.3.1]. (Why?
* Presumably for the same reason that it's protected instead
* of private: to allow derivation. But none of the other
* containers allow for derivation. Odd.)
*/
_Sequence c;