ISO/IEC JTC1 SC22 WG21 N2233 = 07-0093 - 2007-04-27
Lawrence Crowl
There are two problems with the current string concatenation syntax.
std::string x, y; ((x += "a") += 'b') += y; x.append("a").append('b').append(y);
basic_string
has a syntax
that is distinct from similar operations on streams,
thus requiring, at minimum, a concept map.
We propose to add
operator <<
member functions
that are otherwise identical to the existing
operator +=
member functions.
The resulting concatenation syntax requires no parentheses.
std::string x, y; x << "a" << 'b' << y;
The resulting <<
operator syntax
is common with stream.
We specifically do not propose to add formatting operations to strings. For this purpose, stringstream is the right solution.
To paragraph 5, subparagraph "21.3.6 modifiers",
after the +=
operators, add
basic_string& operator<<(const basic_string& str); basic_string& operator<<(const charT* s); basic_string& operator<<(charT c);
After section 21.3.6.1 basic_string::operator+= [string::op+=], add the following section.
basic_string
Returns:
Returns:
Returns:
append(str)
.
basic_string
append(s).
basic_string
append(1,c).