This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.
basic_string(str, pos)Section: 27.4.3.3[string.cons]Status:C++17Submitter: Pablo HalpernOpened: 2016-01-05Last modified: 2017-07-30
Priority:0
View all otherissues in [string.cons].
View all issues withC++17 status.
Discussion:
Container andstring constructors in the standard follow two general rules:
Every constructor needs a version with and without an allocator argument (possibly through the use of default arguments).
Every constructorexcept the copy constructor for which an allocator is not provided uses a default-constructed allocator.
The first rule ensures emplacing astring into a container that uses a scoped allocator will correctly propagate the container's allocator to the new element.
string asbasic_string(str, pos) but notbasic_string(str, pos, alloc). This omission breaks the first rule and causes something like the following to fail:typedef basic_string<char, char_traits<char>, A<char>> stringA;vector<stringA, scoped_allocator_adaptor<A<stringA>>> vs;stringA s;vs.emplace_back(s, 2); // Ill-formed
[2016-02, Issues Telecon]
P0; move to Tentatively Ready.
Proposed resolution:
This wording is relative to N4567.
Change 27.4.3[basic.string], class templatebasic_string synopsis, as indicated
basic_string(const basic_string& str, size_type pos,size_type n = npos,const Allocator& a = Allocator());basic_string(const basic_string& str, size_type pos, size_type n, const Allocator& a = Allocator());
Change 27.4.3.3[string.cons] as indicated
basic_string(const basic_string& str, size_type pos,size_type n = npos,const Allocator& a = Allocator());-3-Throws:
-4-Effects: Constructs an object of classout_of_rangeifpos > str.size().basic_stringand determines the effective lengthrlenof the initial string value asthe smaller ofnandstr.size() - pos, as indicated in Table 65.basic_string(const basic_string& str, size_type pos, size_type n, const Allocator& a = Allocator());-?-Throws:
-?-Effects: Constructs an object of classout_of_rangeifpos > str.size().basic_stringand determines the effective lengthrlenof the initial string value as the smaller ofnandstr.size() - pos, as indicated in Table 65.
Table 65 — basic_string(const basic_string&, size_type,andsize_type,const Allocator&)basic_string(const basic_string&, size_type, size_type, const Allocator&)effectsElement Value data()points at the first element of an allocated copy of rlenconsecutive elements of the string controlledbystrbeginning at positionpossize()rlencapacity()a value at least as large as size()