I was wondering what __cerb
means in the libstdc++
of g++
, and I found out that this seems to be a short name for cerberos
as named in the official C++ standard document.
§ 22.3.1 / 3:
[ Example: An iostream
operator<<
might 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 example ]
Why are iostream sentry
objects called cerberos
, and what does cerberos
actually mean?
Cerberus was the three headed dog1 who guarded the gates of hell, keeping those trapped within from crossing back over the river Styx. Whomever wrote that section fancied Greek and/or Roman mythology and decided it would be an applicable name for a local variable sentry.
As to why it ends in os, one can imagine three scenarios:
1. Apparently the number of heads on Cerberus is variable. Perhaps this is better expressed as the "N-headed dog, where N is greater than or equal to 1."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With