C++ Logo

std-proposals

Advanced search

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

From: Yexuan Xiao <bizwen_at_[hidden]>
Date: Thu, 19 Oct 2023 23:13:49 +0000
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://api.csswg.org/bikeshed/?url=https://storage.nykz.org/proposals/iterators-for-string.bs&force=1

Received on 2023-10-19 23:13:55