在关于优化和代码风格的C++问题中,在优化副本的上下文中,有几个答案提到了"SSO" std::string.在这种情况下,SSO意味着什么?
显然不是"单点登录"."共享字符串优化",或许?
我想将两个(或更多)流组合成一个.我的目标是将任何输出定向到cout,cerr并且clog还将其与原始流一起输出到文件中.(例如,当事情记录到控制台时.关闭后,我仍然希望能够返回并查看输出.)
我在考虑做这样的事情:
class stream_compose : public streambuf, private boost::noncopyable
{
public:
// take two streams, save them in stream_holder,
// this set their buffers to `this`.
stream_compose;
// implement the streambuf interface, routing to both
// ...
private:
// saves the streambuf of an ios class,
// upon destruction restores it, provides
// accessor to saved stream
class stream_holder;
stream_holder mStreamA;
stream_holder mStreamB;
};
Run Code Online (Sandbox Code Playgroud)
这看起来很简单.然后在main中的调用将是这样的:
// anything that goes to cout goes to both …Run Code Online (Sandbox Code Playgroud)