[libc-commits] [PATCH] D131610: [libc][NFC] add arrow operator to optional

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Aug 10 13:27:55 PDT 2022


michaelrj added inline comments.


================
Comment at: libc/src/__support/CPP/optional.h:78
+
+  constexpr const T *operator->() const { return &Storage.StoredValue; }
 };
----------------
sivachandra wrote:
> For consistency with `operator*`, make it `const &` and add a non-const `&` flavor also.
If I change this to be a reference, then to use the `->` operator the contained object must also support the `->` operator. Here's the error message when I try it: 
`error: member reference type 'const __llvm_libc::cpp::StringView' is not a pointer`

I think it's more useful to leave it as is, so that it works as expected without additional effort.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131610



More information about the libc-commits mailing list