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

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Tue May 7 15:31:39 CEST 2019

On 07/05/2019 14:42, Jason H wrote:
>> Those will likely change to qsizetype in Qt 6. Which is still signed.
> This is disappointing. I'll only get half of the indexable space... can I get something in return? Having a negative index mechanism, like in Python, would be a way to alleviate some of the pain. Otherwise can you explain the rationale for not using signed?

I guess you meant "not using unsigned" here?

Half of the memory space is the theoretical maximum you get anyhow, no 
matter the signedness of the index, right?

(You need to be able to take the pointer difference between any two 
positions in an array (including the one-past-the-end). Given that 
ptrdiff_t is the same size of a pointer, and has to be signed, that 
means that the biggest contiguous block of memory you can index is half 
of the address space. What am I not seeing?)

About the rationale of using signed indices, see the link earlier in the 
thread to the previous discussion.

Side notes: 1) the the change to qsizetype as an index type has not 
happened yet, anyhow. It's still a huge question if it's doable in the 
first place.

2) if you need containers bigger than 2^31 elements (assuming QVector 
gets fixed) then you can use the STL containers _today_.

3) there's only a handful of Qt APIs that take/return Qt containers. A 
goal for the Qt 5/6 transition would be make them container-agnostic 
(e.g. using output iterators), so not to tie anyone to use Qt containers.

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: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190507/d2964012/attachment.bin>

More information about the Interest mailing list