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.
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@lists.isocpp.org> 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!
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.
--
Rhidian De Wit
Software Engineer - Barco