In C++ it's common to use static objects as part of other static object functions. The main challenge is order of static object initialization and destruction.
One of well known idioms for static objects lifetime/use management is Nifty counter
, which suggests to keep a static counter and initialize the 'actual' instance/buffer as first translation unit will start to use the instance(counter == 0) and the destroy the buffer as the last translation unit instances are destroyed(counter == 0)
Question: what about static storage lifetime of nifty counter nifty_counter
and stream_buf
which is incapsulated in a single translation unit -> can be destroyed till all remaining translation unit instances are destroyed.