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

Ola Røer Thorsen ola at silentwings.no
Tue May 7 16:08:46 CEST 2019


> Could you make an example where the casts are needed? Maybe the code can
> be rearranged in a way that the casts are NOT needed in the first place.
>
>
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.

Cheers,
Ola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190507/1e3aab77/attachment.html>


More information about the Interest mailing list