Affected subclause: [string.classes]
Change: Additional rvalue overload for the
substr member function and
the corresponding constructor
. Rationale: Improve efficiency of operations on rvalues
. Effect on original feature: Valid C++ 2020 code that created a substring
by calling
substr (or the corresponding constructor)
on an xvalue expression with type
S
that is a specialization of
basic_string
may change meaning in this revision of C++
. For example:
std::string s1 = "some long string that forces allocation", s2 = s1;
std::move(s1).substr(10, 5);
assert(s1 == s2);
std::string s3(std::move(s2), 10, 5);
assert(s1 == s2);