sso tradeoffs

Howard Hinnant hhinnant@apple.com
Fri Nov 11 14:19:00 GMT 2005


On Nov 10, 2005, at 5:37 PM, Howard Hinnant wrote:

> When we do an sso string (as the official std::string), we at the  
> same time need an extension non-mutable string whose copy  
> constructor can't throw (probably via refcounting).  This will be  
> needed in the <stdexcept> classes (which currently use std::string).
>
> Hmm... unless we can get the exception throwing mechanism in the  
> language to promise to always move instead of copy...

At the risk of arguing with myself, my above comment about having the  
language always move instead of copy exceptions would not be  
sufficient to relax the nothrow requirement on the <stdexcept>  
classes.  After sleeping on it I realized that users may well have  
built exceptions in advance, perhaps stored them in a container, and  
are counting on a nothrow copy to safely throw them.  E.g.:

map<int, runtime_error> exceptions;
... fill exceptions ...

...

void foo()
{
     ...
     if (something bad happens)
         throw exceptions[id_for_something_bad];  // should never  
throw bad_alloc
     ...
}

So no matter what, it looks like we need that non-mutable string with  
a nothrow copy ctor.

-Howard



More information about the Libstdc++ mailing list