[flang] [llvm] [libc] [lldb] [clang] [compiler-rt] [libunwind] [libcxx] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2024-01-15 Thread James E T Smith via cfe-commits


@@ -1149,9 +1171,11 @@ struct Proxy {
   // Calling swap(Proxy{}, Proxy{}) would fail (pass prvalues)
 
   // Compare operators are defined for the convenience of the tests
-  friend constexpr bool operator==(const Proxy&, const Proxy&)
-requires (std::equality_comparable && !std::is_reference_v)
-  = default;
+  friend constexpr bool operator==(const Proxy& lhs, const Proxy& rhs)
+requires(std::equality_comparable && !std::is_reference_v)
+  {
+return lhs.data == rhs.data;
+  };

jamesETsmith wrote:

Thanks to an offline discussion with @Quuxplusone, I now know that these 
operators only started causing problems when I introduced the base class 
`ProxyDiffTBase` because the base subobject wasn't trivially comparable. Since 
the `operator==` for `Proxy` is used all over, when they stopped functioning 
properly a lot of tests started failing which is what prompted me to make those 
changes to begin with. At @Quuxplusone's suggestion, I've specified the 
comparison operators for the base class (and derived `Proxy` class) as default, 
undoing the changes we were talking about here and below.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [compiler-rt] [libunwind] [libc] [libcxx] [llvm] [clang] [lldb] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2024-01-09 Thread James E T Smith via cfe-commits


@@ -0,0 +1,123 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Testing std::ranges::iota
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+#include "test_iterators.h"
+#include "almost_satisfies_types.h"
+
+// Concepts to check different overloads of std::ranges::iota
+template 
+concept HasIotaIter = requires(Iter&& iter, Sent&& sent, Value&& val) {
+  std::ranges::iota(std::forward(iter), std::forward(sent), 
std::forward(val));
+};
+
+template 
+concept HasIotaRange =
+requires(Range&& range, Value&& val) { 
std::ranges::iota(std::forward(range), std::forward(val)); };
+
+constexpr void test_constraints() {
+  // Test constraints of the iterator/sentinel overload
+  // ==
+  static_assert(HasIotaIter);
+
+  // !input_or_output_iterator
+  static_assert(!HasIotaIter);
+
+  // !sentinel_for
+  static_assert(!HasIotaIter);
+  static_assert(!HasIotaIter);
+
+  // !weakly_incrementable
+  static_assert(!HasIotaIter);
+
+  // !indirectly writable 
+  static_assert(!HasIotaIter);
+
+  // Test constraints for the range overload
+  // ===
+  static_assert(HasIotaRange, int>);
+
+  // !weakly_incrementable
+  static_assert(!HasIotaRange, 
WeaklyIncrementableNotMovable>);
+
+  // !ranges::output_range
+  static_assert(!HasIotaRange, 
OutputIteratorNotIndirectlyWritable>);
+}
+
+template 
+constexpr void test_result(std::array input, int starting_value, 
std::array const expected) {
+  { // (iterator, sentinel) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+std::same_as> decltype(auto) 
result =
+std::ranges::iota(std::move(in_begin), std::move(in_end), 
starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}
+assert(std::ranges::equal(input, expected));
+  }
+
+  // The range overload adds the additional constraint that it must be an 
outputrange
+  // so skip this for the input iterators we test
+  if constexpr (!std::is_same_v> &&
+!std::is_same_v>) { // 
(range) overload

jamesETsmith wrote:

@philnik777 I found what's tripping up the `output_iterator` concept. It's 
this: 
https://github.com/jamesETsmith/llvm-project/blob/be7faa6fb11c09822a9a855c7cf1aecab4f4c773/libcxx/test/support/test_iterators.h#L652.
 Is there a special constraint for `cpp20_input_iterator` that requires the 
post-increment operator be implemented this way? 

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [llvm] [libunwind] [flang] [libc] [lldb] [compiler-rt] [clang] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread James E T Smith via cfe-commits


@@ -0,0 +1,123 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Testing std::ranges::iota
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+#include "test_iterators.h"
+#include "almost_satisfies_types.h"
+
+// Concepts to check different overloads of std::ranges::iota
+template 
+concept HasIotaIter = requires(Iter&& iter, Sent&& sent, Value&& val) {
+  std::ranges::iota(std::forward(iter), std::forward(sent), 
std::forward(val));
+};
+
+template 
+concept HasIotaRange =
+requires(Range&& range, Value&& val) { 
std::ranges::iota(std::forward(range), std::forward(val)); };
+
+constexpr void test_constraints() {
+  // Test constraints of the iterator/sentinel overload
+  // ==
+  static_assert(HasIotaIter);
+
+  // !input_or_output_iterator
+  static_assert(!HasIotaIter);
+
+  // !sentinel_for
+  static_assert(!HasIotaIter);
+  static_assert(!HasIotaIter);
+
+  // !weakly_incrementable
+  static_assert(!HasIotaIter);
+
+  // !indirectly writable 
+  static_assert(!HasIotaIter);
+
+  // Test constraints for the range overload
+  // ===
+  static_assert(HasIotaRange, int>);
+
+  // !weakly_incrementable
+  static_assert(!HasIotaRange, 
WeaklyIncrementableNotMovable>);
+
+  // !ranges::output_range
+  static_assert(!HasIotaRange, 
OutputIteratorNotIndirectlyWritable>);
+}
+
+template 
+constexpr void test_result(std::array input, int starting_value, 
std::array const expected) {
+  { // (iterator, sentinel) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+std::same_as> decltype(auto) 
result =
+std::ranges::iota(std::move(in_begin), std::move(in_end), 
starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}
+assert(std::ranges::equal(input, expected));
+  }
+
+  // The range overload adds the additional constraint that it must be an 
outputrange
+  // so skip this for the input iterators we test
+  if constexpr (!std::is_same_v> &&
+!std::is_same_v>) { // 
(range) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+auto range= std::ranges::subrange(std::move(in_begin), 
std::move(in_end));
+
+std::same_as> decltype(auto) 
result =
+std::ranges::iota(range, starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}

jamesETsmith wrote:

Should be resolved by b3f260e

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [libunwind] [flang] [llvm] [libcxx] [libc] [lldb] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,123 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Testing std::ranges::iota
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+#include "test_iterators.h"
+#include "almost_satisfies_types.h"
+
+// Concepts to check different overloads of std::ranges::iota
+template 
+concept HasIotaIter = requires(Iter&& iter, Sent&& sent, Value&& val) {
+  std::ranges::iota(std::forward(iter), std::forward(sent), 
std::forward(val));
+};
+
+template 
+concept HasIotaRange =
+requires(Range&& range, Value&& val) { 
std::ranges::iota(std::forward(range), std::forward(val)); };
+
+constexpr void test_constraints() {
+  // Test constraints of the iterator/sentinel overload
+  // ==
+  static_assert(HasIotaIter);
+
+  // !input_or_output_iterator
+  static_assert(!HasIotaIter);
+
+  // !sentinel_for
+  static_assert(!HasIotaIter);
+  static_assert(!HasIotaIter);
+
+  // !weakly_incrementable
+  static_assert(!HasIotaIter);
+
+  // !indirectly writable 
+  static_assert(!HasIotaIter);
+
+  // Test constraints for the range overload
+  // ===
+  static_assert(HasIotaRange, int>);
+
+  // !weakly_incrementable
+  static_assert(!HasIotaRange, 
WeaklyIncrementableNotMovable>);
+
+  // !ranges::output_range
+  static_assert(!HasIotaRange, 
OutputIteratorNotIndirectlyWritable>);
+}
+
+template 
+constexpr void test_result(std::array input, int starting_value, 
std::array const expected) {
+  { // (iterator, sentinel) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+std::same_as> decltype(auto) 
result =
+std::ranges::iota(std::move(in_begin), std::move(in_end), 
starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}
+assert(std::ranges::equal(input, expected));
+  }
+
+  // The range overload adds the additional constraint that it must be an 
outputrange
+  // so skip this for the input iterators we test
+  if constexpr (!std::is_same_v> &&
+!std::is_same_v>) { // 
(range) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+auto range= std::ranges::subrange(std::move(in_begin), 
std::move(in_end));
+
+std::same_as> decltype(auto) 
result =
+std::ranges::iota(range, starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}
+assert(std::ranges::equal(input, expected));
+  }
+}
+
+template >
+constexpr void test_results() {
+  // Empty
+  test_result({}, 0, {});
+  // 1-element sequence
+  test_result({1}, 0, {0});
+  // Longer sequence
+  test_result({1, 2, 3, 4, 5}, 0, {0, 1, 2, 3, 4});
+}
+
+void test_results() {
+  test_results>();
+  test_results>();
+  test_results>();
+  test_results>();
+  test_results>();
+  test_results>();
+  test_results>();
+  test_results>();
+  test_results();

philnik777 wrote:

```suggestion
  types::for_each(types::cpp20_input_iterator_list{}, [] { 
test_results(); });
  test_results>();
  test_results>();
```
You should also test with different sentinel types.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [llvm] [flang] [clang] [compiler-rt] [libc] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-12-16 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/17] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee..c6eb03f1d68e98 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 00..8baffec7b9ef4d
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 00..20311a68c2a348
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};

[flang] [libcxx] [libc] [clang] [llvm] [compiler-rt] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-11-05 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/17] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[flang] [libcxx] [libc] [clang] [llvm] [compiler-rt] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-11-05 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith edited 
https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [clang] [libcxx] [flang] [llvm] [compiler-rt] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-11-04 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/16] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[libc] [clang] [libcxx] [flang] [llvm] [compiler-rt] [clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-11-04 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/16] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-30 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/14] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-30 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/14] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-30 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/13] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread James E T Smith via cfe-commits

jamesETsmith wrote:

The strategy using `ProxyDiffTBase` is implemented in 88e271a. Initially, it 
caused a bunch of errors elsewhere because the compiler generated `==` and 
`<=>` member functions would cause checks like 
`std::totally_ordered_with, Proxy&>` to fail (see 
https://godbolt.org/z/nqMn1jhYx). To address that I just implemented those 
functions, I hope that's ok.

I noticed that `test_iterators.h` isn't formatted (at least not with 
clang-format 17) so I opted not to format that file after making changes to 
keep the diffs clearer. I can format that as soon as we're done tinkering in it.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/11] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread via cfe-commits

philnik777 wrote:

You should make the operators conditionally available based on whether the 
underlying type has them. The rest looks good.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread James E T Smith via cfe-commits

jamesETsmith wrote:

@philnik777, I think you're right that `Proxy` is missing a few member 
functions (and type aliases). Here's a minimal example of my additions to it: 
https://godbolt.org/z/8T9eqjjEj. If that seems reasonable, I'll update 
`test_iterators.h`.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-27 Thread via cfe-commits

philnik777 wrote:

Why does the proxy not satisfy `weakly_incrementable`? Is it maybe just missing 
some member functions?

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-26 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith edited 
https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-26 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/10] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-26 Thread James E T Smith via cfe-commits

jamesETsmith wrote:

@philnik777, I've added tests for `ranges::iota` to several of the 
`ranges_robust_against_*` tests where I thought it was appropriate. Below is a 
breakdown (mostly for my own tracking) of what I've done and what I'm still 
sorting through (`ranges_robust_against_proxy_iterators`). If you see anything 
that I missed or got wrong, just let me know.

- libcxx/test/std/algorithms
  - [X] 
libcxx/test/std/algorithms/ranges_result_alias_declarations.compile.pass.cpp
  - [X] libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp
  - [ ] 
libcxx/test/std/algorithms/ranges_robust_against_differing_projections.pass.cpp
- I don't think we need this one, since we don't use projections
  - [ ] 
libcxx/test/std/algorithms/ranges_robust_against_nonbool_predicates.pass.cpp
- I don't think we need this one since we don't use predicates
  - [ ] 
libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp
- I don't think we need this one because we don't use invoke
  - [ ] 
libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp
- This one is giving me trouble bc because 'Proxy' does not satisfy 
'weakly_incrementable'
- libcxx/test/libcxx/
  - [ ] 
libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
- I don't think we need this since we don't use comparators
  - [ ] 
libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
- I don't think we need this since we don't use projections


https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-25 Thread via cfe-commits

philnik777 wrote:

Yes, it should be the `ranges_robust_against_*` tests in both `test/libcxx` and 
`test/std`.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-25 Thread via cfe-commits


@@ -0,0 +1,54 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+#include <__utility/as_const.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {

philnik777 wrote:

`static operator()` has been introduced in C++23, so we can't (currently) use 
it for C++20 algorithms. Otherwise we would also use it there. The simple 
reason to use it is that we don't care about the object and the `static` 
version has slightly better code gen (https://godbolt.org/z/8E1f77q6f).

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-24 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith edited 
https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-24 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 1/7] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), 

[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-24 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith edited 
https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-24 Thread James E T Smith via cfe-commits


@@ -0,0 +1,54 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+#include <__utility/as_const.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {

jamesETsmith wrote:

@philnik777, I'm happy to make these changes, but could you explain why 
`static` is more appropriate than `const` here?

As an alternative, after I've added the helper function, I could make that 
static and leave the public functions as `const` like it says in the original 
paper. I stumbled on this strategy (it's used by `ranges::for_each` and 
`ranges::generate` at least) while looking at how other libcxx helper functions 
were structured.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-24 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith edited 
https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-10 Thread James E T Smith via cfe-commits

jamesETsmith wrote:

Thanks for taking a look @philnik777! I'll try to address your comments in the 
next couple of days and let you know if I have any questions.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-09 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith edited 
https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-07 Thread via cfe-commits


@@ -0,0 +1,124 @@
+//===--===//
+//

philnik777 wrote:

Unrelated: Please update the `robust_against_*` tests.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-07 Thread via cfe-commits


@@ -46,7 +46,7 @@
 "`P2255R2 `__","LWG","A type trait to detect 
reference binding to temporary","February 2022","",""
 "`P2273R3 `__","LWG","Making ``std::unique_ptr`` 
constexpr","February 2022","|Complete|","16.0"
 "`P2387R3 `__","LWG","Pipe support for user-defined 
range adaptors","February 2022","","","|ranges|"
-"`P2440R1 `__","LWG","``ranges::iota``, 
``ranges::shift_left`` and ``ranges::shift_right``","February 
2022","","","|ranges|"
+"`P2440R1 `__","LWG","``ranges::iota``, 
``ranges::shift_left`` and ``ranges::shift_right``","February 2022","|In 
progress|","","|ranges|"

philnik777 wrote:

Please also update `libcxx/docs/RangesAlgorithms.csv`.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-07 Thread via cfe-commits

https://github.com/philnik777 edited 
https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-07 Thread via cfe-commits


@@ -0,0 +1,124 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, C++20
+
+//  template 
+//struct out_value_result;
+
+#include 
+#include 
+#include 
+
+#include "MoveOnly.h"
+
+//
+// Helper structs
+//
+
+// only explicit construction
+struct IterTypeExplicit {
+  explicit IterTypeExplicit(int*);
+};
+
+// implicit construction
+struct IterTypeImplicit {
+  IterTypeImplicit(int*);
+};
+
+struct IterTypeImplicitRef {
+  IterTypeImplicitRef(int&);
+};
+
+struct NotConvertible {};
+
+template 
+struct ConvertibleFrom {
+  constexpr ConvertibleFrom(T c) : content{c} {}
+  T content;
+};
+
+//
+constexpr void test_constraints() {
+  // requires convertible_to && 
convertible_to
+  static_assert(
+  std::is_constructible_v, 
std::ranges::out_value_result>);
+
+  // test failure when implicit conversion isn't allowed
+  
static_assert(!std::is_constructible_v,
+ std::ranges::out_value_result>);
+
+  // test success when implicit conversion is allowed, checking combinations 
of value, reference, and const
+  
static_assert(std::is_constructible_v,
+std::ranges::out_value_result>);
+  
static_assert(std::is_constructible_v,
+std::ranges::out_value_result const>);
+  
static_assert(std::is_constructible_v,
+std::ranges::out_value_result&>);
+  
static_assert(std::is_constructible_v,
+std::ranges::out_value_result const&>);
+
+  
static_assert(!std::is_constructible_v,
+ std::ranges::out_value_result&>);
+
+  // has to be convertible via const&
+  static_assert(
+  std::is_convertible_v&, 
std::ranges::out_value_result>);
+  static_assert(
+  std::is_convertible_v&, 
std::ranges::out_value_result>);
+  static_assert(
+  std::is_convertible_v&&, 
std::ranges::out_value_result>);
+  static_assert(std::is_convertible_v&&,
+  std::ranges::out_value_result>);
+
+  // should be move constructible
+  
static_assert(std::is_move_constructible_v>);
+  
static_assert(std::is_move_constructible_v>);
+
+  // conversions should not work if there is no conversion
+  
static_assert(!std::is_convertible_v,
+   std::ranges::out_value_result>);
+  static_assert(!std::is_convertible_v,
+   
std::ranges::out_value_result>);
+}
+
+// Test results
+constexpr bool test() {
+  {
+std::ranges::out_value_result res{10, 1};
+assert(res.out == 10);
+assert(res.value == 1);
+std::ranges::out_value_result, 
ConvertibleFrom> res2 = res;
+assert(res2.out.content == 10);
+assert(res2.value.content == 1);
+  }
+  {
+std::ranges::out_value_result res{MoveOnly{}, 10};
+assert(res.out.get() == 1);
+assert(res.value == 10);
+auto res2 = std::move(res);
+assert(res.out.get() == 0);
+assert(res.value == 10);
+assert(res2.out.get() == 1);
+assert(res2.value == 10);
+  }
+  {
+auto [out, val] = std::ranges::out_value_result{1, 2};
+assert(out == 1);
+assert(val == 2);
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test_constraints();
+  test();
+  static_assert(test());
+  return 0;
+}

philnik777 wrote:

Newline!

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-07 Thread via cfe-commits


@@ -0,0 +1,54 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+#include <__utility/as_const.h>
+

philnik777 wrote:

```suggestion
#include <__utility/move.h>
```

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-07 Thread via cfe-commits


@@ -0,0 +1,124 @@
+//===--===//

philnik777 wrote:

I've started working on this in https://reviews.llvm.org/D121436 (and didn't 
really work on it because nobody knew what it was for). You should probably 
make sure that any comments there are addressed here and add any additional 
tests from there.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-07 Thread via cfe-commits

https://github.com/philnik777 requested changes to this pull request.

I haven't looked at the tests yet. The implementation itself looks mostly good.

https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc++] Implement ranges::iota (PR #68494)

2023-10-07 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith created 
https://github.com/llvm/llvm-project/pull/68494

# Overview

As a disclaimer, this is my first PR to LLVM and while I've tried to ensure 
I've followed the LLVM and libc++ contributing guidelines, there's probably a 
good chance I missed something. If I have, just let me know and I'll try to 
correct it as soon as I can.

This PR implements `std::ranges::iota` and `std::ranges::out_value_result` 
outlined in 
[P2440r1](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2440r1.html).

As outlined in the paper above, I've:
- Implemented `out_value_result` and added to ``
- Added `out_value_result`, `iota_result`, and two overloads of `iota`  to 
`std::ranges` in ``
- Updated the version macro `__cpp_lib_ranges_iota` in ``

I've also added tests for `ranges::iota` and `ranges::out_value_result`. 
Lastly, I added those structs to the appropriate module files.

# TODOs
- [ ] Updating the range [status 
doc](https://github.com/jamesETsmith/llvm-project/blob/main/libcxx/docs/Status/RangesMajorFeatures.csv)
 
- [ ] I'm open to implementing the rest of P2440r1 (`ranges::shift_left` and 
`ranges::shift_right`) if that's ok, I just wanted to get feedback on 
`ranges::iota` first
- [ ] I've been having trouble building the modules locally and want to make 
sure that's working properly

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 1/6] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++