Is cout guaranteed available during static deinitialization?
<p>I've got a quasi-singleton class (quasi-singleton in that most use refers to a single object that is a function static, but users can also construct their own local copy for short-term use) that I would like to have write to cout from its destructor, and wanted to know if cout was guaranteed to be available during the static deinitialization phase following program termination.  From <a href="http://stackoverflow.com/questions/3785808/can-static-allocated-memory-become-invalid-during-static-deinitialization">this question</a> it seems that the answer is yes (function static initialized objects should have their destructors called in reverse order from when they were constructed, which should be after cout was set up), but I wanted to check.</p>

<pre><code>// Count calls to a logging function from some point in our code, to determine
// how many times it gets executed during a run, then report calls at the end
// of the program.  A quick-and-dirty way of determining how often we execute
// code.
class callCounter;
class callCounter {
public:
    callCounter() : has_calls_(false), counts_() {}
    ~callCounter () {report(std::cout);}
    void logCall(const std::string callSite);
    void report(std::ostream &amp;os);
    void reset();
    static callCounter *theCounter();
private:
    typedef std::map&lt;std::string, callCount&gt; COUNTMAP;
    bool has_calls_;
    COUNTMAP counts_;
};

callCounter *callCounter::theCounter()
{
    static callCounter theCounts;
    return &amp;theCounts;
}
</code></pre>

<p>Typical usage would be:</p>

<pre><code>callCounter::theCounter()-&gt;logCall("foo");
</code></pre>

<p>So is this usage of cout in the destructor guaranteed safe (at least as far as using cout itself is concerned - arguably to be perfectly safe, I should wrap the report in a try block in case the write throws an exception.)?</p>
