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

Jeff Bailey via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jul 20 23:45:56 PDT 2022


jeffbailey marked 2 inline comments as done.
jeffbailey added inline comments.


================
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.
----------------
gchatelet wrote:
> 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.
I'm not sure where to put static_asserts in here.  I think if it's not copy constructable/assignable or not destructable, compilation will simply fail right now.  I couldn't think of what static_asserts to put in beyond this.

Feedback is always welcome, thanks!


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