C++ Logo

std-proposals

Advanced search

Re: String contains member function

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Fri, 31 May 2019 07:06:27 -0500
On Thu, May 30, 2019 at 10:56 PM Mingxin Wang via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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
>

How do map::contains() and set::contains() have "completely different
semantics" than the proposed string::contains()? They seem exactly the same
to me. It's even the same motivation - wanting to avoid the boilerplate of
map.find(x) != map.end() is the same as wanting to avoid the boilerplate of
str.find(x) != npos.

Barry

Received on 2019-05-31 07:08:27