string + string_view operator

604 vues
Accéder directement au premier message non lu

Olaf van der Spek

non lue,
3 janv. 2017, 05:40:0903/01/2017
à 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

non lue,
3 janv. 2017, 11:03:0203/01/2017
à 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

non lue,
3 janv. 2017, 12:15:0703/01/2017
à ISO C++ Standard - Future Proposals

Nicol Bolas

non lue,
3 janv. 2017, 12:30:1703/01/2017
à 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

non lue,
3 janv. 2017, 12:51:5403/01/2017
à 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

non lue,
29 avr. 2017, 18:38:1129/04/2017
à 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

non lue,
24 mai 2017, 05:19:0824/05/2017
à 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. 
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message