[libcxx-commits] [PATCH] D102135: [libcxx][ranges] adds _`copyable-box`_

Tim Song via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 24 08:21:37 PDT 2021


tcanens added a comment.

In D102135#2837041 <https://reviews.llvm.org/D102135#2837041>, @ldionne wrote:

> At first, I didn't understand the purpose of this type. Now I think I do - it's to turn something that is copy-constructible (but maybe not copy assignable) into something that is both copy-constructible and copy-assignable. It does that by using an optional and basically doing destroy-then-copy-construct in the assignment operator.

Yep, aka "`transform_view` has to work for captureful lambdas".

>   __copyable_box& operator=(__copyable_box const& __other) noexcept(to-be-figured-out) {
>     if constexpr (copyable<_Tp>) {
>       __val_ = __other.__val_;
>     } else { // is_nothrow_xxx is satisfied
>       _VSTD::destroy_at(&__val_);
>       _VSTD::construct_at(&__val_, other.__val_);
>     }
>     return *this;
>   }

This should be two overloads so that it can be trivial when possible - which also happens to make the `noexcept` trivial to write .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102135



More information about the libcxx-commits mailing list