[libc-commits] [PATCH] D129920: [libc] Trivial implementation of std::optional

Guillaume Chatelet via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jul 20 00:49:33 PDT 2022


gchatelet accepted this revision.
gchatelet added a comment.
This revision is now accepted and ready to land.

Please add the requirements on T for Optional as documentation and then this is good to go.



================
Comment at: libc/src/__support/CPP/Optional.h:21-24
+// This is very simple implementation of the std::optional class.  There are a
+// number of guarantees in the standard that are not made here.
+//
+// This class will be extended as needed in future.
----------------
sivachandra wrote:
> gchatelet wrote:
> > I would list the requirements for `T` here, AFAICT:
> >  - default constructible
> >  - copy constructible
> >  - copy assignable
> >  - destructible
> I think Guilllaume is just asking you to list them for now. IIUC, except for the default constructible requirement, they are already enforced?
Yes exactly it's just to document the expectations and indeed "default constructible" might not  be required (because of the `union`)
Ideally this would be checked upfront in the class body with some `static_assert`s and CPP traits. The aim here is to make the failing requirements obvious.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129920/new/

https://reviews.llvm.org/D129920



More information about the libc-commits mailing list