Date: Fri, 31 May 2019 03:55:56 +0000
This seems useful. However, the motivation seems not to be strong enough, because
1. Although some other languages may have such functionality, I think C++ should not copy everything without a deep thinking and clear motivation.
2. Even it could simplify the “find != npos” pattern, I do not find this pattern widely existing in engineering.
3. If we take one step backward, even if it is a useful pattern, we may turn to regex for more readability and extendibility rather than “find != npos”.
4. The name has already been used in other facilities like “set” or “map” with completely different semantics, which may confuse the beginners and decrease “teachability”.
Therefore, I would suggest investigating more on the motivation. For the fourth comment above, I think “includes” could be a better name than “contains”.
Regards,
Mingxin Wang
From: Std-Proposals <std-proposals-bounces_at_[hidden]> On Behalf Of Wim Leflere via Std-Proposals
Sent: Wednesday, May 29, 2019 3:27 PM
To: std-proposals_at_[hidden]
Cc: Wim Leflere <wim.leflere_at_[hidden]>
Subject: Re: [std-proposals] String contains member function
It has a similar rationale as the starts_with/ends_with paper, which doesn't mention the performance benefit and was accepted.
Performance shouldn't be the only benchmark to extend the standard I think.
Improving code readability and teachability for beginners and people coming from other languages is also a good rationale to extend the standard.
Op ma 27 mei 2019 om 21:56 schreef Matthew Woehlke <mwoehlke.floss_at_[hidden]<mailto:mwoehlke.floss_at_[hidden]>>:
On 27/05/2019 14.30, Wim Leflere via Std-Proposals wrote:
> After seeing that 'starts_with' and 'ends_with' were added to std::string
> in C++20 (P0457), I was wondering why 'contains' was still missing as a
> std::string member function.
> So I wrote a proposal (starting from P0457) to add it.
>
> Please find the draft of the proposal here:
> https://github.com/WimLeflere/cpp-papers/blob/master/string_contains_function.md<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FWimLeflere%2Fcpp-papers%2Fblob%2Fmaster%2Fstring_contains_function.md&data=02%7C01%7Cmingxwa%40microsoft.com%7C5008ef2a882844d10fb408d6e407232d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636947116638306195&sdata=eo7%2FOOfz11ZJxbJXKNShYjObPkyCwrCrs2jhG6KlgPE%3D&reserved=0>
>
> I am looking forward to your valuable comments.
The rationale vs. string::find is... weak. Both starts_with and
ends_with have a clear performance benefit in addition to improved
semantics. Even for <container>::contains (vs. count) that is the case.
For string::contains, this isn't the case; the rationale is *purely*
aesthetic.
Mind, I like consistent, easy to use API's, but I wouldn't hold your
breath...
--
Matthew
1. Although some other languages may have such functionality, I think C++ should not copy everything without a deep thinking and clear motivation.
2. Even it could simplify the “find != npos” pattern, I do not find this pattern widely existing in engineering.
3. If we take one step backward, even if it is a useful pattern, we may turn to regex for more readability and extendibility rather than “find != npos”.
4. The name has already been used in other facilities like “set” or “map” with completely different semantics, which may confuse the beginners and decrease “teachability”.
Therefore, I would suggest investigating more on the motivation. For the fourth comment above, I think “includes” could be a better name than “contains”.
Regards,
Mingxin Wang
From: Std-Proposals <std-proposals-bounces_at_[hidden]> On Behalf Of Wim Leflere via Std-Proposals
Sent: Wednesday, May 29, 2019 3:27 PM
To: std-proposals_at_[hidden]
Cc: Wim Leflere <wim.leflere_at_[hidden]>
Subject: Re: [std-proposals] String contains member function
It has a similar rationale as the starts_with/ends_with paper, which doesn't mention the performance benefit and was accepted.
Performance shouldn't be the only benchmark to extend the standard I think.
Improving code readability and teachability for beginners and people coming from other languages is also a good rationale to extend the standard.
Op ma 27 mei 2019 om 21:56 schreef Matthew Woehlke <mwoehlke.floss_at_[hidden]<mailto:mwoehlke.floss_at_[hidden]>>:
On 27/05/2019 14.30, Wim Leflere via Std-Proposals wrote:
> After seeing that 'starts_with' and 'ends_with' were added to std::string
> in C++20 (P0457), I was wondering why 'contains' was still missing as a
> std::string member function.
> So I wrote a proposal (starting from P0457) to add it.
>
> Please find the draft of the proposal here:
> https://github.com/WimLeflere/cpp-papers/blob/master/string_contains_function.md<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FWimLeflere%2Fcpp-papers%2Fblob%2Fmaster%2Fstring_contains_function.md&data=02%7C01%7Cmingxwa%40microsoft.com%7C5008ef2a882844d10fb408d6e407232d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636947116638306195&sdata=eo7%2FOOfz11ZJxbJXKNShYjObPkyCwrCrs2jhG6KlgPE%3D&reserved=0>
>
> I am looking forward to your valuable comments.
The rationale vs. string::find is... weak. Both starts_with and
ends_with have a clear performance benefit in addition to improved
semantics. Even for <container>::contains (vs. count) that is the case.
For string::contains, this isn't the case; the rationale is *purely*
aesthetic.
Mind, I like consistent, easy to use API's, but I wouldn't hold your
breath...
--
Matthew
Received on 2019-05-30 22:57:45