C++ Logo

std-proposals

Advanced search

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

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Sun, 25 Jun 2023 14:42:00 +0200
Il 25/06/23 13:53, Frederick Virchanza Gotham via Std-Proposals ha scritto:
> Of course this would mean that you need to edit the code everywhere so
> that you have "g_obj->" instead of "g_obj.", unless of course you were
> to do:
>
> optional<T> g_optional_obj;
> T &g_obj = *g_optional_obj.operator->();
>
> Strictly speaking this is undefined behaviour but it will work fine so
> long as you make sure to 'emplace' the object before using 'g_obj'.

Say again?

https://github.com/llvm-mirror/libcxx/blob/master/include/optional#L879

-- 
Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2023-06-25 12:42:03