[Development] QVector rvalue overloads for convenience functions?

Allan Sandfeld Jensen kde at carewolf.com
Mon Mar 5 18:59:50 CET 2018


On Montag, 5. März 2018 10:00:35 CET André Somers wrote:
> On 03/03/2018 21:25, Allan Sandfeld Jensen wrote:
> > On Samstag, 3. März 2018 21:11:18 CET Mandeep Sandhu wrote:
> >> On Sat, Mar 3, 2018 at 11:46 AM, Christian Ehrlicher
> >> <Ch.Ehrlicher at gmx.de>
> >> 
> >> wrote:
> >>> Hi,
> >>> 
> >>> recently rvalue overloads for QVector::append(T), push_back(T) and
> >>> others
> >>> were added to QVector. But not for the convenience functions like
> >>> operator<<(T) or operator +=(T). Is this an oversight
> >> 
> >> Why would an rvalue overload (by that I assume you mean move semantics)
> >> apply to the += operator? You're not discarding the existing object, just
> >> adding values from whats pointed to by the other  reference.
> >> 
> >> As for the << operator, it _might_ be an oversight, I'm not sure. Someone
> >> else can chime in.
> > 
> > Both of them could make sense assuming we are talking about the single
> > value variants.
> 
> Just wondering: why limit this to single value variants? I'd think that
> it would be equally useful for the variants taking a container?
> 
While it is possible for it to be usefull, you first need to write the rvalue-
append for that, and due to how the Qt containers are designed they may be 
implicitly shared in which case it rvalue append won't be able to avoid 
copying instead of moving. The same design also kind of encourages using Qt 
containers in ways where the ref-count will be higher than 1 and thus moving 
is not possible/meaningful.

' Allan





More information about the Development mailing list