C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Iterators for basic_string and basic_string_view find functions

From: Yexuan Xiao <bizwen_at_[hidden]>
Date: Fri, 20 Oct 2023 14:28:54 +0000
The constructor, assign, insert, append, erase, and replace for basic_string all have versions that take iterator pairs. Only find uniquely uses indices. Why can’t you see them?

________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Jason McKesson via Std-Proposals <std-proposals_at_[hidden]>
Sent: Friday, October 20, 2023 22:03
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Jason McKesson <jmckesson_at_[hidden]>
Subject: Re: [std-proposals] Iterators for basic_string and basic_string_view find functions

On Thu, Oct 19, 2023 at 7:13 PM Yexuan Xiao via Std-Proposals
<std-proposals_at_lists.isocpp.org> wrote:
>
> I propose to add a new set of find functions for basic_string and basic_string_view, which take and return iterators instead of indices. These functions will have the same name as the existing ones, but with an “x” prefix.
>
> Before:
>
> if (auto start = s.find(c); start != std::string::npos)
> {
> std::transform(s.begin() + start, s.begin() + start + c.size(), s.begin() + start, [](unsigned char c) { return std::toupper(c); });
> }
>
> After:
>
> if (auto start = s.xfind(c); start != s.end()) {
> std::transform(start, start + c.size(), start, [](unsigned char c){ return std::toupper(c); });
> }
>
> The full content using Bikeshed is here: https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapi.csswg.org%2Fbikeshed%2F%3Furl%3Dhttps%3A%2F%2Fstorage.nykz.org%2Fproposals%2Fiterators-for-string.bs%26force%3D1&data=05%7C01%7C%7Cc0c0119772f640dd974208dbd175701d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638334074566719974%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=ZwvKPr0MyJiO7seGVb8FZZI6dCI%2FWQfV6J7ugLxo4uQ%3D&reserved=0<https://api.csswg.org/bikeshed/?url=https://storage.nykz.org/proposals/iterators-for-string.bs&force=1>

As it currently stands, the `basic_string` API is pretty clear. Member
functions use *indicies*; if you want to do some operation on the
string using iterators, we have standard algorithms for those
operations.

We shouldn't treat algorithms like a last resort; they're a first
class feature of all ranges.
--
Std-Proposals mailing list
Std-Proposals_at_lists.isocpp.org
https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isocpp.org%2Fmailman%2Flistinfo.cgi%2Fstd-proposals&data=05%7C01%7C%7Cc0c0119772f640dd974208dbd175701d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638334074566719974%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=qTg19NGC2UjfRkOcvrOHyDyH4QivDFEu%2Btaf7xLnCK0%3D&reserved=0<https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals>

Received on 2023-10-20 14:29:01