Is std :: string a default no-throw constructor?
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()) { }
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.
source to share