Date: Wed, 29 Nov 2023 13:17:04 +0100
Given the use case:
optional< future<bool> > var;
It is ok to just call var.release() or to reassign it to a new future - a
destructor will be called, but the shared state is kept until the promise
(or async or packaged_task) is destroyed.
int main()
{
using namespace std::chrono_literals;
std::promise<bool> p;
std::optional<std::future<bool>> of = p.get_future();
std::thread t([&p]
{
std::this_thread::sleep_for(5000ms);
p.set_value(true);
});
of.reset();
t.join();
}
On Wed, Nov 29, 2023 at 12:13 PM Giuseppe D'Angelo via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Il 29/11/23 11:46, Breno GuimarĂ£es via Std-Proposals ha scritto:
> > I don't think that's UB. Not calling the destructor is not UB.
>
> I was referring to the memset. But indeed I can't seem to find a
> provision that you can't just overwrite bytes of an arbitrary object
> using it. Interesting pub quiz question...
>
> Thanks,
> --
> Giuseppe D'Angelo
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
optional< future<bool> > var;
It is ok to just call var.release() or to reassign it to a new future - a
destructor will be called, but the shared state is kept until the promise
(or async or packaged_task) is destroyed.
int main()
{
using namespace std::chrono_literals;
std::promise<bool> p;
std::optional<std::future<bool>> of = p.get_future();
std::thread t([&p]
{
std::this_thread::sleep_for(5000ms);
p.set_value(true);
});
of.reset();
t.join();
}
On Wed, Nov 29, 2023 at 12:13 PM Giuseppe D'Angelo via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Il 29/11/23 11:46, Breno GuimarĂ£es via Std-Proposals ha scritto:
> > I don't think that's UB. Not calling the destructor is not UB.
>
> I was referring to the memset. But indeed I can't seem to find a
> provision that you can't just overwrite bytes of an arbitrary object
> using it. Interesting pub quiz question...
>
> Thanks,
> --
> Giuseppe D'Angelo
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2023-11-29 12:17:17