C++ Nifty Counter idiom; why?
问题 I recently came across the Nifty Counter Idiom. My understanding is that this is used to implement globals in the standard library like cout, cerr, etc. Since the experts have chosen it, I assume that it's a very strong technique. I'm trying to understand what the advantage is over using something more like a Meyer Singleton. For example, one could just have, in a header file: inline Stream& getStream() { static Stream s; return s; } static Stream& stream = getStream(); The advantage is you