C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Use optional<T> as though it were T

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 28 Jun 2023 07:29:03 -0700
On Wednesday, 28 June 2023 03:14:01 PDT Frederick Virchanza Gotham via Std-
Proposals wrote:
> On Wed, Jun 28, 2023 at 10:57 AM Jonathan Wakely via Std-Proposals
>
> <std-proposals_at_[hidden]> wrote:
> > And what has all this code got to do with std -proposals?
>
> My proposal is that the code could be replaced with something like:
>
> std::delayed_construction<T> g_obj;

Have you looked at Q_GLOBAL_STATIC? It's been around for nearly 20 years and
has solved many of those problems.

https://doc.qt.io/qt-6/qglobalstatic.html#Q_GLOBAL_STATIC

If you just want delayed construction without staticness, see these two proof
of concept commits:
https://codereview.qt-project.org/c/qt/qtbase/+/474885
https://codereview.qt-project.org/c/qt/qtbase/+/474650

Examples of usage in the unit tests.

> In this thread, we are discussing how this new feature could be
> implemented, and if there is a worthwhile implementation.


-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-06-28 14:29:05