[libcxx-commits] [PATCH] D110370: [libc++] Simplify std::ranges::subrange

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 27 14:12:58 PDT 2021


ldionne added inline comments.


================
Comment at: libcxx/include/__ranges/subrange.h:81
+    static constexpr bool _MustProvideSizeAtConstruction = !_StoreSize; // just to improve compiler diagnostics
+    struct _Empty { constexpr _Empty(auto) noexcept { } };
+    using _Size = conditional_t<_StoreSize, make_unsigned_t<iter_difference_t<_Iter>>, _Empty>;
----------------
Quuxplusone wrote:
> This type is not trivially default-constructible. I think you should give it a default ctor `_Empty() = default;` as well, and then
> ```
> [[no_unique_address]] _Size __size_ = _Size();
> ```
> and then your non-sized `subrange` type will be trivially default-constructible whenever the iterator+sentinel types are. And I think there should be a libcxx/ test for that, because it seems both useful //and// fragile.
I was going to say "awesome, let's do it and add a test for it". Then I tried, and noticed that `std::ranges::subrange<int*>` still wasn't trivially default constructible, since we have default member initializers per the spec (http://eel.is/c++draft/range.subrange.general).

So I'm not sure we can actually make `subrange` trivially default constructible, unless I am missing something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110370



More information about the libcxx-commits mailing list