[Development] RFC: Proposal for a semi-radical change in Qt APIs taking strings

Ziller Eike Eike.Ziller at theqtcompany.com
Thu Oct 15 08:38:33 CEST 2015


> On Oct 14, 2015, at 5:14 PM, Matthew Woehlke <mwoehlke.floss at gmail.com> wrote:
> 
> 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

So from where does 
s.indexOf(‘c’, i-2)
search?
This is similar to integer overflow, and I think utilizing that in an API leads to less readable and potentially unexpectedly behaving code.

Anyhow this seems to be only vaguely related to the things that are discussed in this thread.

Br, Eike

> 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
> 
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development

-- 
Eike Ziller, Senior Software Engineer - The Qt Company GmbH
 
The Qt Company GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B



More information about the Development mailing list