C++ Logo

std-proposals

Advanced search

Re: [std-proposals] String Slicing Draft Proposal

From: Zhihao Yuan <zy_at_[hidden]>
Date: Thu, 14 Mar 2024 19:56:21 +0000
You can see that the goal of the three-parameter
slice is somewhat different from that of slice(A, B).
For example, if I want the resulting string to be
in vector<char>, I'll have to initiate another copy.

Once https://wg21.link/p1899 is adopted, stepped
slicing can be done in one-line:


  s.slice(start, end) | views::stride(step) | ranges::to<std::string>()
  // or ranges::to<std::basic_string>

Doesn't look too long, and arguably more explicit.

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________
On Thursday, March 14th, 2024 at 1:59 AM, Rhidian De Wit via Std-Proposals <std-proposals_at_[hidden]> wrote:
> Hi!
> You're completely right of course, overloading wouldn't work in that case.
> I had implemented these functions and tested them for myself, but I didn't implement the = 1 in the overloaded slice() function.
> I'll remove the default argument to fix the overloading, and implement a check where it has to be 1 at the very least.
> 
> Thanks a lot!
> 
> 
> Op do 14 mrt 2024 om 08:54 schreef Pavel Vazharov <freakpv_at_[hidden]>:
> 
> > Hi there,
> > How are these two supposed to be distinguished by the compiler if the 3rd parameter is defaulted.
> > /* 1. */ basic_string_view basic_string::slice(size_t start, size_t end);
> > /* 2. */ basic_string basic_string::slice(size_t start, size_t end, size_t step = 1);
> > 
> > I mean, I don't see how the function overloading will work in this case.
> > const auto str = initial_str.slice(3, 5); // which of the above two is called?
> > 
> > Regards,
> > Pavel.
> > 
> > On Thu, Mar 14, 2024 at 9:49 AM Rhidian De Wit via Std-Proposals <std-proposals_at_[hidden]> wrote:
> > 
> > > Hi all,
> > > With some helpful suggestions, I'd like to present my draft proposal for the inclusion of several new utility functions to be added to std::basic_string.
> > > 
> > > Please reach out if you have any questions, concerns or feedback!
> > > 
> > > Sincerely,
> > > 
> > > --
> > > Rhidian De Wit
> > > Software Engineer - Barco
> > > 
> > > --
> > > Std-Proposals mailing list
> > > Std-Proposals_at_[hidden]
> > > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> 
> 
> 
> --
> Rhidian De Wit
> Software Engineer - Barco

Received on 2024-03-14 19:56:38