[Interest] Operator QMap<uint, uint>[] is casting to int?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Tue May 7 19:07:09 CEST 2019


Hi,

Il 07/05/19 16:08, Ola Røer Thorsen ha scritto:
> QByteArray bytes; // chosen because some api needs it later
> std::vector<char> other_bytes; // maybe returned from some 3rd party library
> ...
> if (static_cast<std::size_t>(bytes.size()) >= other_bytes.size()) {
>      ...
> }
> 
> I guess i could write stuff like
> 
> const std::size_t byteSize = bytes.size();
> if (byteSize >= other_bytes.size())
> 
> but then I rather prefer static_cast. Note that I'm not saying we should 
> change everything in Qt to unsigned int, I think that might break a lot 
> of existing application code out there. Just saying that sometimes a 
> static_cast is needed.

I see, and it's indeed mostly annoying. Again, out of curiosity, is the 
API forcing you to use a QByteArray coming from Qt itself?

Thanks,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190507/e2564384/attachment.bin>


More information about the Interest mailing list