[Development] Making QScopedPointer scoped (again)

Peter Kümmel syntheticpp at gmx.net
Wed Sep 4 09:06:03 CEST 2013


On 03.09.2013 22:12, Oswald Buddenhagen wrote:
> On Tue, Sep 03, 2013 at 09:20:20PM +0200, Peter Kümmel wrote:
>>>> Adding a move contructor to QScopedPointer makes no sense, because moving
>>>> means 'escaping the scope', which breaks the fundamental point of
>>>> QScopedPointer. QScopedPointer is different to std::unique_ptr and should
>>>> remain so.
>>
>> I have to agree with Steven. After allowing moving, the semantic is
>> different to the naming: after this change we could write in the docs
>>
>>       "QScopedPointer sometimes deletes when it leaves the scope."
>>
>> Which makes it obvious that "QScopedPointer" is the wrong name for such a behavior.
>>
> actually, it is
>
>      "A non-null QScopedPointer deletes when it leaves the scope."
>
> which sounds quite reasonable to me.
>

QScopedPointer<int> returnScopedPointer()
{
     QScopedPointer<int> p(new int);
     return p;
}

Does 'p' look like a null QScopedPointer? I don't think so.
It only becomes null behind the scenes.

Peter




More information about the Development mailing list