Topic: Completing string and string_view concatenation
Author: johelegp@gmail.com
Date: Sat, 26 Nov 2016 19:14:16 -0800 (PST)
Raw View
------=_Part_993_122573437.1480216456644
Content-Type: multipart/alternative;
boundary="----=_Part_994_856131139.1480216456644"
------=_Part_994_856131139.1480216456644
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Currently, the following, reasonable expressions are ill-formed
"string"s + "_view"sv
"string"sv + "_view"s
even though you can use std::string's operator+=3D and append member=20
functions if the rhs is a std::string_view.
I would like to propose the introduction of the std::string::operator+=20
overloads that would make such expressions well-formed. This would make the=
=20
interface consistent, and prevent having to do less intuitive work-arounds=
=20
to get equivalent effects:
auto sv {"C++17"sv};
auto str1 {std::string{sv} + " today"s}; // explicit conversion
auto str2 {"Today: "s +=3D sv}; // why not +?
auto str3 {("Today: "s +=3D sv) + ", tomorrow: "s +=3D sv}; // messy
I had submitted a LWG issue on this. Here, I quote part of the reply by=20
Daniel Kr=C3=BCgler.
The second point is whether this is actually a feature request, not a
> library defect. The design of basic_string_view intentionally did
> support comparison, but not concatenations. This is obviously
> evolution material, so I would strongly recommend to write a proposal
> for this.
>
I tried hunting down why there's no operator+, and *only* found this in=20
N3512:
I also omitted operator+(basic_string, basic_string_ref) because LLVM=20
> returns a lightweight object from this overload and only performs the=20
> concatenation lazily. If we define this overload, we'll have a hard time=
=20
> introducing that lightweight concatenation later.
>
I can't believe that would be the only reason.
Here's the proposed wording included in my non-accepted issue.
*Proposed wording:*
This wording is relative to N4606.
Modify [string.classes]:
...
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string<charT, traits, Allocator>&& lhs,
basic_string<charT, traits, Allocator>&& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string_view<charT, traits> lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string_view<charT, traits> lhs,
basic_string<charT, traits, Allocator>&& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const charT* lhs,
const basic_string<charT, traits, Allocator>& rhs);
...
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(charT lhs, basic_string<charT, traits, Allocator>&& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs,
basic_string_view<charT, traits> rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string<charT, traits, Allocator>&& lhs,
basic_string_view<charT, traits> rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs,
const charT* rhs);
...
Add after [string::op+]/4:
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string_view<charT, traits> lhs,
const basic_string<charT, traits, Allocator>& rhs);
Returns: basic_string<charT, traits, Allocator>(lhs) + rhs.
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string_view<charT, traits> lhs,
basic_string<charT, traits, Allocator>&& rhs);
Returns: std::move(rhs.insert(0, lhs)).
Add after [string::op+]/10:
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs,
basic_string_view<charT, traits> rhs);
Returns: lhs + basic_string<charT, traits, Allocator>(rhs).
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string<charT, traits, Allocator>&& lhs,
basic_string_view<charT, traits> rhs);
Returns: std::move(lhs.insert(rhs)).
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/f9db8d2d-4d7a-4582-8152-74ab370652d0%40isocpp.or=
g.
------=_Part_994_856131139.1480216456644
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Currently, the following, reasonable expressions are ill-f=
ormed<br><br><div style=3D"margin-left: 40px;"><span style=3D"font-family: =
courier new,monospace;">"string"s=C2=A0 + "_view"sv<br>=
"string"sv + "_view"s</span><br></div><br>even though y=
ou can use <span style=3D"font-family: courier new,monospace;">std::string<=
/span>'s <span style=3D"font-family: courier new,monospace;">operator+=
=3D</span> and <span style=3D"font-family: courier new,monospace;">append</=
span> member functions if the rhs is a <span style=3D"font-family: courier =
new,monospace;">std::string_view</span>.<br><br>I would like to propose the=
introduction of the <span style=3D"font-family: courier new,monospace;">st=
d::string::operator+</span> overloads that would make such expressions well=
-formed. This would make the interface consistent, and prevent having to do=
less intuitive work-arounds to get equivalent effects:<br><br><div style=
=3D"margin-left: 40px;"><span style=3D"font-family: courier new,monospace;"=
>auto sv {"C++17"sv};<br>auto str1 {std::string{sv} + " toda=
y"s}; // explicit conversion<br>auto str2 {"Today: "s +=3D s=
v}; // why not +?<br>auto str3 {("Today: "s +=3D sv) + ", to=
morrow: "s +=3D sv}; // messy</span><br></div><br>I had submitted a LW=
G issue on this. Here, I quote part of the reply by Daniel Kr=C3=BCgler.<br=
><br><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; =
border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">The second p=
oint is whether this is actually a feature request, not a<br>library defect=
.. The design of basic_string_view intentionally did<br>support comparison, =
but not concatenations. This is obviously<br>evolution material, so I would=
strongly recommend to write a proposal<br>for this.<br></blockquote><br>I =
tried hunting down why there's no <span style=3D"font-family: courier n=
ew,monospace;">operator+</span>, and <i>only</i> found this in N3512:<br><b=
r><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; bor=
der-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I also omitted =
operator+(basic_string, basic_string_ref) because LLVM returns a lightweigh=
t object from this overload and only performs the concatenation lazily. If =
we define this overload, we'll have a hard time introducing that lightw=
eight concatenation later.<br></blockquote><br>I can't believe that wou=
ld be the only reason.<br><br>Here's the proposed wording included in m=
y non-accepted issue.<br><br><b>Proposed wording:</b><br><br>This wording i=
s relative to N4606.<br><br>Modify [string.classes]:<br><br><span style=3D"=
font-family: courier new,monospace;">=C2=A0=C2=A0=C2=A0 ...<br>=C2=A0=C2=A0=
=C2=A0 template<class charT, class traits, class Allocator><br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<charT, traits, Allocator><br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 operator+(basic_string<charT,=
traits, Allocator>&& lhs,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic=
_string<charT, traits, Allocator>&& rhs);<br><span style=3D"c=
olor: rgb(255, 255, 255);"><span style=3D"background-color: rgb(106, 168, 7=
9);"><span style=3D"background-color: rgb(56, 118, 29);">=C2=A0=C2=A0=C2=A0=
template<class charT, class traits, class Allocator><br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 basic_string<charT, traits, Allocator><br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 operator+(basic_string_view<charT, =
traits> lhs,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const basic_string<char=
T, traits, Allocator>& rhs);<br>=C2=A0=C2=A0=C2=A0 template<class=
charT, class traits, class Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
basic_string<charT, traits, Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 operator+(basic_string_view<charT, traits> lhs,<br=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<charT, traits, Allocator>=
&& rhs);</span><br></span></span>=C2=A0=C2=A0=C2=A0 template<cla=
ss charT, class traits, class Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 basic_string<charT, traits, Allocator><br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 operator+(const charT* lhs,<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 const basic_string<charT, traits, Allocator>& rhs);<br>=C2=
=A0=C2=A0=C2=A0 ...<br>=C2=A0=C2=A0=C2=A0 template<class charT, class tr=
aits, class Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<=
;charT, traits, Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
operator+(charT lhs, basic_string<charT, traits, Allocator>&&=
; rhs);<br><span style=3D"color: rgb(255, 255, 255);"><span style=3D"backgr=
ound-color: rgb(56, 118, 29);">=C2=A0=C2=A0=C2=A0 template<class charT, =
class traits, class Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_s=
tring<charT, traits, Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 operator+(const basic_string<charT, traits, Allocator>&=
lhs,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string_view<charT, traits>=
rhs);<br>=C2=A0=C2=A0=C2=A0 template<class charT, class traits, class A=
llocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<charT, trait=
s, Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 operator+(ba=
sic_string<charT, traits, Allocator>&& lhs,<br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 basic_string_view<charT, traits> rhs);</span></span><=
br>=C2=A0=C2=A0=C2=A0 template<class charT, class traits, class Allocato=
r><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<charT, traits, Allo=
cator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 operator+(const bas=
ic_string<charT, traits, Allocator>& lhs,<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 const charT* rhs);<br>=C2=A0=C2=A0=C2=A0 ...<br></span><br>Add af=
ter [string::op+]/4:<br><br><span style=3D"font-family: courier new,monospa=
ce;">=C2=A0=C2=A0=C2=A0 template<class charT, class traits, class Alloca=
tor><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<charT, traits, Al=
locator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 operator+(basic_s=
tring_view<charT, traits> lhs,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const=
basic_string<charT, traits, Allocator>& rhs);</span><br>=C2=A0=
=C2=A0=C2=A0 Returns: <span style=3D"font-family: courier new,monospace;">b=
asic_string<charT, traits, Allocator>(lhs) + rhs</span>.<br><br><span=
style=3D"font-family: courier new,monospace;">=C2=A0=C2=A0=C2=A0 template&=
lt;class charT, class traits, class Allocator><br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 basic_string<charT, traits, Allocator><br>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 operator+(basic_string_view<charT, traits>=
; lhs,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<charT, traits, Allo=
cator>&& rhs);</span><br>=C2=A0=C2=A0=C2=A0 Returns: <span style=
=3D"font-family: courier new,monospace;">std::move(rhs.insert(0, lhs))</spa=
n>.<br><br>Add after [string::op+]/10:<br><br><span style=3D"font-family: c=
ourier new,monospace;">=C2=A0=C2=A0=C2=A0 template<class charT, class tr=
aits, class Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<=
;charT, traits, Allocator><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
operator+(const basic_string<charT, traits, Allocator>& lhs,<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic_string_view<charT, traits> rhs);</s=
pan><br>=C2=A0=C2=A0=C2=A0 Returns: <span style=3D"font-family: courier new=
,monospace;">lhs + basic_string<charT, traits, Allocator>(rhs)</span>=
..<br><br><span style=3D"font-family: courier new,monospace;">=C2=A0=C2=A0=
=C2=A0 template<class charT, class traits, class Allocator><br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 basic_string<charT, traits, Allocator><br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 operator+(basic_string<charT,=
traits, Allocator>&& lhs,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 basic=
_string_view<charT, traits> rhs);</span><br>=C2=A0=C2=A0=C2=A0 Return=
s: <span style=3D"font-family: courier new,monospace;">std::move(lhs.insert=
(rhs))</span>.<br><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f9db8d2d-4d7a-4582-8152-74ab370652d0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f9db8d2d-4d7a-4582-8152-74ab370652d0=
%40isocpp.org</a>.<br />
------=_Part_994_856131139.1480216456644--
------=_Part_993_122573437.1480216456644--
.
Author: janis.coders@gmail.com
Date: Mon, 10 Apr 2017 00:57:38 -0700 (PDT)
Raw View
------=_Part_1414_2121717213.1491811058762
Content-Type: multipart/alternative;
boundary="----=_Part_1415_1255695094.1491811058762"
------=_Part_1415_1255695094.1491811058762
Content-Type: text/plain; charset=UTF-8
I agree with your proposal. I was surprised when it wasn't possible to
operator+ string_view - feels like inconsistent interface.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/63107a3c-b597-4924-9046-95ce4e054cf5%40isocpp.org.
------=_Part_1415_1255695094.1491811058762
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I agree with your proposal. I was surprised when it wasn&#=
39;t possible to operator+ string_view - feels like inconsistent interface.=
<br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/63107a3c-b597-4924-9046-95ce4e054cf5%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/63107a3c-b597-4924-9046-95ce4e054cf5=
%40isocpp.org</a>.<br />
------=_Part_1415_1255695094.1491811058762--
------=_Part_1414_2121717213.1491811058762--
.
Author: olafvdspek@gmail.com
Date: Thu, 13 Apr 2017 01:24:26 -0700 (PDT)
Raw View
------=_Part_329_596422801.1492071866375
Content-Type: multipart/alternative;
boundary="----=_Part_330_346434329.1492071866376"
------=_Part_330_346434329.1492071866376
Content-Type: text/plain; charset=UTF-8
Op zondag 27 november 2016 04:14:16 UTC+1 schreef johe...@gmail.com:
>
> I can't believe that would be the only reason.
>
Why not?
I'd love to have those operators too but in the meantime you can easily
define them yourself:
https://github.com/OlafvdSpek/xbt/blob/master/misc/xbt/string_view.h
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/49f00517-4bb3-4650-93d5-97ea17be56b0%40isocpp.org.
------=_Part_330_346434329.1492071866376
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Op zondag 27 november 2016 04:14:16 UTC+1 schreef johe...@=
gmail.com:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">I c=
an't believe that would be the only reason.<br></div></blockquote><div>=
<br></div><div>Why not?</div><div><br></div><div>I'd love to have those=
operators too but in the meantime you can easily define them yourself:</di=
v><div><br></div><div>https://github.com/OlafvdSpek/xbt/blob/master/misc/xb=
t/string_view.h<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/49f00517-4bb3-4650-93d5-97ea17be56b0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/49f00517-4bb3-4650-93d5-97ea17be56b0=
%40isocpp.org</a>.<br />
------=_Part_330_346434329.1492071866376--
------=_Part_329_596422801.1492071866375--
.