Why are iostream watchman objects called “cerberos” in the standard?

I was wondering what __cerb means libstdc++ of g++ , and I found out that this seems to be a short name for cerberos , as stated in the official C ++ cerberos paper.

§ 22.3.1 / 3:

[Example: iostream operator<< can be implemented as:

 template <class charT, class traits> basic_ostream<charT,traits>& operator<< (basic_ostream<charT,traits>& s, Date d) { // !!!!!!!!!! typename basic_ostream<charT,traits>::sentry cerberos(s); // <--- !! HERE !! // !!!!!!!!!! if (cerberos) { ios_base::iostate err = ios_base::iostate::goodbit; tm tmbuf; d.extract(tmbuf); use_facet<time_put<charT,ostreambuf_iterator<charT,traits> > >( s.getloc()).put(s, s, s.fill(), err, &tmbuf, 'x'); s.setstate(err); // might throw } return s; } 

- end of example]

Why are iostream sentry objects called cerberos , and what does cerberos mean?

+8
c ++ iostream naming-conventions naming
source share
1 answer

Cerberus was the three-headed dog 1 which guarded the gates of hell , holding those who were trapped due to the crossing of the Styx River. Whoever wrote this section representing Greek and / or Roman mythology and decided that it would be a suitable name for a local variable sentinel.

As to why it ends with os, three scenarios can be presented:

  • They completely forgot the rules for Greek and Latin nouns declinations and thought that this is what is written.
  • I completely forgot the rules for Greek and Latin nouns declinations and pointing to a non-question.
  • They combined the inscriptions of Cerberus and Kerberos, giving birth to Cerberus the main brother of Greek and Roman origin.

<sub> 1. Apparently, the number of goals on Cerberus varies. Perhaps this is better expressed as "a dog with N-heads, where N is greater than or equal to 1".

+12
source share

All Articles