[RFC] Add C++14's optional objects (20.6/n3672).
Paolo Carlini
paolo.carlini@oracle.com
Wed Sep 25 14:19:00 GMT 2013
Hi,
On 9/25/13 9:15 AM, Rüdiger Sonderfeld wrote:
> Hello,
> I've implemented std::optional<T> from C++1y (20.6/n3672). This started as an
> exercise but seeing that libstdc++ lacks optional so far, I thought this might
> be useful.
>
> The code is not complete yet. There are two main issues:
>
> 1. It seems to be impossible to initialise the aligned_storage in a constexpr
> ctor because placement new is not a constexpr. Maybe this will be fixed
> in N3652 (which GCC does not implement). I'm currently using the _M_hack
> member to initialise the storage. But this is ugly and will still prevent
> the ctor from being a real constexpr.
> Alternatively instead of using aligned_storage a union could be used. I'm
> looking into this right now.
>
> 2. Currently operator=(_Up&& __u) is picked over operator=(const optional& __o)
> or operator=(optional&& __o). I guess this can be prevented with further
> extending the enable_if. But I'm not sure if this would be conforming to
> the standard.
>
> I haven't written any documentation or ChangeLog entries yet because this is
> just an request for comments. I also haven't signed the copyright assignment
> for GCC. I have signed it for Emacs but I guess I have to sign another one.
> If there is interest in my code then I'll do it immediately.
In my opinion you should, yes. Definitely there is interest and in any
case you do it once, and you are set forever. Thus, please go ahead with
the paperwork.
Thanks!
Paolo.
More information about the Libstdc++
mailing list