From 123ed3729f79d61df2e04aee10ca3f4ccedde5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kr=C3=BCgler?= Date: Sat, 25 Nov 2023 20:07:03 +0100 Subject: [PATCH] New issue from Hewill Kang: "ranges::to's copy branch is underconstrained" --- xml/issue4018.xml | 90 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 xml/issue4018.xml diff --git a/xml/issue4018.xml b/xml/issue4018.xml new file mode 100644 index 0000000000..161ad585b6 --- /dev/null +++ b/xml/issue4018.xml @@ -0,0 +1,90 @@ + + + + +<tt>ranges::to</tt>'s copy branch is underconstrained +
+Hewill Kang +25 Nov 2023 +99 + + +

+Unlike other branches that return a prvalue C, this branch's C is returned by elidable move, +indicating that C needs to be move constructible (demo): +

+
+#include <ranges>
+#include <vector>
+
+struct nonmovable {
+  nonmovable() = default;
+  nonmovable(const nonmovable&) = delete;
+  nonmovable& operator=(const nonmovable&) = delete;
+};
+
+template<class T>
+struct nonmovable_vector : std::vector<T>, nonmovable { };
+
+int main() {
+  int arr[] = {42};
+  auto v = std::ranges::to<nonmovable_vector<int>>(arr); // hard error
+}
+
+
+ + +

+This wording is relative to . +

+ +
    + +
  1. Modify as indicated:

    + +
    +
    +template<class C, input_range R, class... Args> requires (!view<C>)
    +  constexpr C to(R&& r, Args&&... args);
    +
    +
    +

    +-1- Mandates: C is a cv-unqualified class type. +

    +

    +-2- Returns: An object of type C constructed from the elements of r in the following manner: +

    +
      +
    1. (2.1) — If C does not satisfy input_range or +convertible_to<range_reference_t<R>, range_value_t<C>> is true:

      +
        +
      1. (2.1.1) — […]

      2. +
      3. (2.1.2) — […]

      4. +
      5. (2.1.3) — […]

      6. +
      7. (2.1.4) — Otherwise, if

        +
          +
        1. (2.1.4.?) — move_constructible<C> is true,

        2. +
        3. (2.1.4.1) — constructible_from<C, Args...> is true, and

        4. +
        5. (2.1.4.2) — container-insertable<C, range_reference_t<R>> is true:

          +
          +C c(std::forward<Args>(args)...);
          +if constexpr (sized_range<R> && reservable-container<C>)
          +  c.reserve(static_cast<range_size_t<C>>(ranges::size(r)));
          +ranges::copy(r, container-inserter<range_reference_t<R>>(c));
          +
        6. +
        +
      8. +
      9. (2.1.5) — Otherwise, the program is ill-formed.

      10. +
    2. +
    3. (2.2) — […]

    4. +
    5. (2.3) — Otherwise, the program is ill-formed.

    6. +
    + +
    +
    +
  2. + +
+
+ +