C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 19 Oct 2023 22:40:26 -0700
On Thursday, 19 October 2023 16:13:49 PDT Yexuan Xiao via Std-Proposals wrote:
> 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); });>
> }

Just a quick note in case someone finds these emails while searching for
transformations to uppercase: the code above is broken and must not be used.
It was used for illustration purposes of something using iterators from a
string.

To the OP: I assume 'c', despite what the variable name might suggest, is not
a char, but a substring. Otherwise, you could use std::find and std::end.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-10-20 05:40:28