Protected Variable Names and Standard

I came across this message where an iterative queue was introduced. OP used a protected variable named c from std::queue in the implementation.

Is this really true? Will this variable have the same name in all implementations? In other words, is the standard state clear that this variable needs to be called c ?

+6
source share
1 answer

For reference, the exact definition of std::queue listed here . Therefore, in response to

In other words, is the standard state clear that this variable needs to be called c ?

Yes, this is the case (and similarly for other container adapters);

 template <class T, class Container = deque<T>> class queue { protected: Container c; // ... }; 

In general, however, the names of protected and private names and members are not standardized, because the types are not all built to be retrieved, and the implementation is an implementation detail (and is not part of the public API); for example std::vector does not contain any protected names.

Some containers and std classes define protected member names, in particular, I like the iostreams library - basically the types that need to be received.


As a follow up - do all compilers / libraries use c ? It seems that at least the core ones (libstdc ++, libc ++ and msvc). libstdC ++ is interesting in that it includes following a comment on a 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 protected instead * of private: to allow derivation. But none of the other * containers allow for derivation. Odd.) */ _Sequence c; 
+10
source

All Articles