string + string_view operator

619 views
Skip to first unread message

Olaf van der Spek

unread,
Jan 3, 2017, 5:40:09 AM1/3/17
to ISO C++ Standard - Future Proposals
Hi,

const char* c;
std::string s;
std::string_view sv;

s + s; // valid
s + c; // valid
c + s; // valid
s += sv; // valid
s + sv; // invalid
sv + s; // invalid
sv + sv; // invalid

Tested on VS2017 RC..
I didn't track string_view status but it seems we're missing a few operators. Have they been proposed already? Is this intentional?

Gr,
Olaf

Bo Persson

unread,
Jan 3, 2017, 11:03:02 AM1/3/17
to std-pr...@isocpp.org
Haven't seen any proposals for that. Considering that we already have 12
overloads for operator+, perhaps people are reluctant to add even more?


Bo Persson



lnal...@gmail.com

unread,
Jan 3, 2017, 12:15:07 PM1/3/17
to ISO C++ Standard - Future Proposals

Nicol Bolas

unread,
Jan 3, 2017, 12:30:17 PM1/3/17
to ISO C++ Standard - Future Proposals, lnal...@gmail.com

That post gives a good reason for why not to have such an overload: to eventually support lazy evaluation. If you implement non-lazy operations now, then they will be non-lazy... forever.

That being said, you could still provoke non-lazy evaluation in cases where you're only combining `string_view`. So if you want lazy-evaluation, you would construct a `string_view` from the `std::string`. This would also allow any string that can be converted into a `string_view` to support lazy evaluation (so long as it also supports construction from the lazy evaluation results).

Olaf van der Spek

unread,
Jan 3, 2017, 12:51:54 PM1/3/17
to std-pr...@isocpp.org, Laurent Navarro
Luckily the operators can be defined by the user but it's still an
annoying gap in the current standard.



--
Olaf

Jakob Riedle

unread,
Apr 29, 2017, 6:38:11 PM4/29/17
to ISO C++ Standard - Future Proposals, lnal...@gmail.com, olafv...@gmail.com
If you implement non-lazy operations now, then they will be non-lazy... forever.

Has there been any proposal that adds lazy evaluation to string concatenations?

--
Jakob

ol...@join.cc

unread,
May 24, 2017, 5:19:08 AM5/24/17
to ISO C++ Standard - Future Proposals, lnal...@gmail.com, olafv...@gmail.com
Op zondag 30 april 2017 00:38:11 UTC+2 schreef Jakob Riedle:
If you implement non-lazy operations now, then they will be non-lazy... forever.

Has there been any proposal that adds lazy evaluation to string concatenations?

I don't think so. 
Reply all
Reply to author
Forward
0 new messages