Is std :: string a default no-throw constructor?

Maybe std :: string s; quit under any circumstances? Is this a regulated standard (interested in C ++ 03 in case of differences)?

+3
c ++ stdstring c ++ 03 default-constructor


source to share


3 answers


This has been changed to WG21 / N4002 . The first working paper contains the following: WG21 / N4296 : // 21.4.2, construct/copy/destroy: basic_string() noexcept : basic_string(Allocator()) { }



+3


source to share


In C ++ 11, the default constructor takes one (default) argument, namely the allocator (21.4.2):

explicit basic_string(const Allocator& a = Allocator());

      



This constructor is not declared as noexcept

. ( This would require the allocator to have a constructor without metadata, I suppose. ) As Jonathan and Bo points out, the allocator copy constructor should not throw any exceptions, but the string constructor is allowed (for example, allocate the initial portion of memory). It should of course be possible to write a string-like class that is the no-throw constructor & shy; ing, constexpr

but the standard library line is not specified like this.

+5


source to share


Of course, if allocation is not possible for any reason, it will throw

-1


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics