[Development] RFC: Proposal for a semi-radical change in Qt APIs taking strings
Matthew Woehlke
mwoehlke.floss at gmail.com
Wed Oct 14 17:14:58 CEST 2015
On 2015-10-14 10:30, André Somers wrote:
> Op 14-10-2015 om 15:59 schreef Matthew Woehlke:
>> STL should change. In Qt and Python, you can use negative indices to
>> refer to a distance (length) relative to the end (length) of the string.
>> In STL you can't do that, which is a significant limitation by
>> comparison. Please don't drop this useful functionality!
>
> I'm not so sure anymore. Do you really think that for instance passing
> in a negative _from_ in QString::indexOf to search from the back of the
> string is intuitive API? I don't.
Huh? Of course it is.
s.indexOf('c', 5); // find 'c', forward, starting at offset 5
s.indexOf('c', -5); // find 'c', forward, starting at offset N-5
A negative offset -K is exactly the same as N + 1 - K (N = length of
string). It just saves having to write that out yourself. It *doesn't*
change the behavior of the function. (I think you are confusing
tail-relative offset with reverse operation, which is totally different
and orthogonal.)
Even STL supports this, partially, for -1; string::npos is generally
equivalent to -1 in Qt.
Bah. Okay, apparently Qt actually *doesn't* support tail-relative, but
just treats n<0 like string::npos. That could be improved for Qt 6
though, but only if n is signed.
--
Matthew
More information about the Development
mailing list