[Development] Move ctors for q_declare_shared types

Thiago Macieira thiago.macieira at intel.com
Fri Jun 26 22:34:50 CEST 2015


On Friday 26 June 2015 22:20:11 Marc Mutz wrote:
> > I tried to implement emplace, but didn't find much value because Qt
> > containers require the type contained to be default constructible and will
> > make copies in the future anyway.
> 
> QList does not require the type to be default-constructible. I think only
> QVector and QVarLengthArray do.

I misspoke. I meant copyable. So move-only types are not possible in Qt 
containers, which removes the biggest user of emplace().

> > As for allocators, I've been doing C++ for 20 years and I have never once
> > ever used one. So that's a P6 "less than not important" task in my view.
> 
> I did:
>   https://github.com/GPGTools/pinentry/blob/master/secmem/secmem%2B%2B.h
> 
> Used here:
>   https://github.com/GPGTools/pinentry/blob/master/qt4/secstring.h

Another reason it's P6 is precisely because the standard containers have it.

> And with C++11/14 stateful allocators, I expect allocators to gain
> popularity: e.g. QVarLengthArray can be superseded by something like
> 
>     char pool[4096];
>     pool_allocator<T> alloc(pool);
>     std::vector<T, pool_allocator<T>> vec(alloc);
>     // ...

That's not what QVarLengthArray is for. The point is that it can exceed the 
automatic-storage pool by going dynamic when the data set size is larger than 
the common case.

> which would allow local-memory maps, too:
>     std::map<K, V, std::less<>, pool_allocator<std::pair<const K, V>>>
>       map(alloc);
> 
> Yes, that's what template aliases were invented for :)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66671

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




More information about the Development mailing list