[Interest] QScopedPointer and c++11 move semantics

Kitsune Ral Kitsune.Ral at protonmail.ch
Sat Dec 31 04:41:14 CET 2016


The most concise, I guess, is:
static const auto laterDeleter = std::mem_fn(&QObject::deleteLater);
std::unique_ptr<QObject, decltype(laterDeleter)> a(nullptr, laterDeleter);

In C++17, if I don't mistake, you won't ned explicit type specifier in the template, so it shortens to:
std::unique_ptr<QObject> a(nullptr, std::mem_fn(&QObject::deleteLater));



--
Kitsune Ral



-------- Original Message --------
Subject: Re: [Interest] QScopedPointer and c++11 move semantics
Local Time: 31-an de decembro, 2016 5:05 A.T.M.
UTC Time: 30-an de decembro, 2016 20:05
From: alervdvcw at gmail.com
To: Konstantin Tokarev <annulen at yandex.ru>, Giuseppe D'Angelo <giuseppe.dangelo at kdab.com>, interest at qt-project.org <interest at qt-project.org>

c++ has gone too far with its templates...


On 12/30/2016 11:03 PM, Alexander Dyagilev wrote:
> This does not work either:
>
> std::unique_ptr<SomeQObject, decltype(&QObject::deleteLater)> var(
> pointer, &QObject::deleteLater);
>
>
> On 12/30/2016 10:58 PM, Alexander Dyagilev wrote:
>>
>> On 12/30/2016 10:55 PM, Konstantin Tokarev wrote:
>>>
>>> 30.12.2016, 22:45, "Alexander Dyagilev" <alervdvcw at gmail.com>:
>>>> QScopedPointer var(new QObject, &QObject::deleteLater) - compiles
>>>> fine.
>>>>
>>>> std::unique_ptr var(new QObject, &QObject::deleteLater) - does not
>>>> compile.
>>>>
>>>> Is there an easy way I miss?
>>> std::mem_fun(&QObject::deleteLater) should work
>>
>> It does not work, unfortunately (not compiles).
>>
>

_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20161230/3700b3dc/attachment.html>


More information about the Interest mailing list