[Development] QtCS 2017 QtCore sessions

Thiago Macieira thiago.macieira at intel.com
Wed Nov 1 22:27:07 CET 2017


On quarta-feira, 1 de novembro de 2017 13:15:11 PDT André Somers wrote:
> That doesn't make sense. Of course it allows for that.
> 
> You'd give indexOf a flag like Qt::searchTowardsBeginning (default being
> Qt::searchTowardsEnd) to determine the direction to search in. Or do you
> mean that you want the result also to be counted from the end? 

You're confusing lastIndexOf() which searchs backwards from the end with 
indexOf() searching forwards from a position near the end.

> If all
> API's take the index counted from the begining there would not be much
> use for that. You either calculate it yourself by substracting the
> result from length(), or you add another flag and do something like
> std::optional<qsize> indexOf(needle, startIndex,
> Qt::searchTowardsBeginning | Qt::asCountedFromEnd) .

Yeah, we won't do that. The QString, QByteArray and QVector can't be bigger 
than the maximum size representable in qssize_t anyway. So we don't *need* the 
extra bit.

Since we don't need the extra bit, we will stick to signed because of its 
benefits:
 1) overflow can be caught with sanitisers
 2) doesn't cause sign conversion warnings when converted to other signed 
   values
 3) the instruction from the committee is to use signed unless you explicitly 
   need modulo-2 overflow
 4) the standard library, if ever rewritten, will use signed counters

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list