[Development] Making QScopedPointer scoped (again)

Alexandr Akulich akulichalexander at gmail.com
Wed Sep 4 14:45:45 CEST 2013


Hi all.

Im totally agree with Stephen, because such change definitely complicate
source reading.
When one read "ScopedPointer", then one naturally expect that stored object
will be deleted.

My 2 cents.


On Tue, Sep 3, 2013 at 2:02 PM, Stephen Kelly <stephen.kelly at kdab.com>wrote:

>
> Hi there,
>
> Commit 5b9006bbdba7dcab01b8e640554a7d7a4b64f76b in qtbase added move
> capability to QScopedPointer.
>
> That means that in Qt 5.2, if you use C++11, you can do this:
>
>  int main(int argc, char **argv)
>  {
>    QScopedPointer<int> p_out;
>    {
>      QScopedPointer<int> p(new int);
>      p_out = std::move(p);
>    }
>  }
>
> However, if you want to move a QScopedPointer like that, then you don't
> want a
> QScopedPointer at all, but a std::unique_ptr instead.
>
> It also means that you can put a QScopedPointer in your API:
>
>  QScopedPointer<int> returnScopedPointer()
>  {
>    QScopedPointer<int> p(new int);
>    return p;
>  }
>
>  int main(int argc, char **argv)
>  {
>    QScopedPointer<int> p = returnScopedPointer();
>  }
>
>
> Again, this is what std::unique_ptr is for. We should not try to turn
> QScopedPointer into an attempt at a NIH std::unique_ptr. Where people have
> a
> need for a std::unique_ptr, they should use it. We should not adapt
> QScopedPointer to fit the need instead.
>
> 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.
>
> Please approve:
>
>  https://codereview.qt-project.org/#change,64428
>
> Thanks,
>
> --
> Join us in October at Qt Developer Days 2013 - https://devdays.kdab.com
>
> Stephen Kelly <stephen.kelly at kdab.com> | Software Engineer
> KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
> www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
> KDAB - Qt Experts - Platform-Independent Software Solutions
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130904/d1fec7a4/attachment.html>


More information about the Development mailing list