C++ Logo

std-proposals

Advanced search

Re: [std-proposals] String Slicing Draft Proposal

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Mon, 18 Mar 2024 15:14:32 +0100
Syntax-wise it would be nearer to Python.   However it would be further from 2-dimensional arrays.   Alternative - I am not sure myself about it: You could also consider adding a word, e.g. my_string[range_from_to{5, 10}], my_string[range_from_length{5, 10}];   -----Ursprüngliche Nachricht----- Von:Breno Guimarães via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Mo 18.03.2024 14:16 Betreff:Re: [std-proposals] String Slicing Draft Proposal An:std-proposals_at_[hidden]; CC:Breno Guimarães <brenorg_at_[hidden]>; Rhidian De Wit <rhidiandewit_at_[hidden]>; Hi,  Since C++23, it's now possible to use multi indexing: https://en.cppreference.com/w/cpp/language/operators#Array_subscript_operator So it would come naturally to add the overload: constexpr basic_string_view basic_string::operator[](size_t start, size_t end) const; That would allow the syntax to be very close to python: if (my_string[5,10] == "something") { ... }  Has that been considered?  Best REgards, Breno G.  

Received on 2024-03-18 14:14:34