Skip to content

[libc++][C++23] P2440R1: Implement ranges::iota #109552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from

Conversation

PaulXiCao
Copy link
Contributor

The paper P2440 introduces three groups of functions: std::ranges::iota, std::ranges::shift_left, and std::ranges::shift_right.

This mr implements std::ranges::iota. For reference:

@PaulXiCao PaulXiCao requested a review from a team as a code owner September 21, 2024 21:51
@PaulXiCao PaulXiCao changed the title [libc++] P2440R1: Implement ranges::iota [libc++][C++23] P2440R1: Implement ranges::iota Sep 21, 2024
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff c28e268c32a6840d08e3a4dbc9eeb8a0f564d6c0 40a283071edad4fcfbe1f7d80accf6c48f76061a --extensions ,cpp,h -- libcxx/include/__algorithm/out_value_result.h libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges_iota.pass.cpp libcxx/include/__numeric/iota.h libcxx/include/algorithm libcxx/include/numeric libcxx/include/version libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.compile.pass.cpp libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
View the diff from clang-format here.
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 9058541824..d2fadd0b1e 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -2024,11 +2024,11 @@ template <class BidirectionalIterator, class Compare>
 
 #if _LIBCPP_STD_VER >= 23
 #  include <__algorithm/fold.h>
+#  include <__algorithm/out_value_result.h>
 #  include <__algorithm/ranges_contains_subrange.h>
 #  include <__algorithm/ranges_ends_with.h>
 #  include <__algorithm/ranges_find_last.h>
 #  include <__algorithm/ranges_starts_with.h>
-#  include <__algorithm/out_value_result.h>
 #endif // _LIBCPP_STD_VER >= 23
 
 #include <version>
diff --git a/libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp b/libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
index fa04acf4be..b7b813a0a3 100644
--- a/libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
+++ b/libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
@@ -30,8 +30,10 @@ struct B {
 // implicit conversion
 static_assert(std::is_constructible_v<std::ranges::out_value_result<B, B>, std::ranges::out_value_result<int, int>>);
 static_assert(std::is_constructible_v<std::ranges::out_value_result<B, B>, std::ranges::out_value_result<int, int>&>);
-static_assert(std::is_constructible_v<std::ranges::out_value_result<B, B>, const std::ranges::out_value_result<int, int>>);
-static_assert(std::is_constructible_v<std::ranges::out_value_result<B, B>, const std::ranges::out_value_result<int, int>&>);
+static_assert(
+    std::is_constructible_v<std::ranges::out_value_result<B, B>, const std::ranges::out_value_result<int, int>>);
+static_assert(
+    std::is_constructible_v<std::ranges::out_value_result<B, B>, const std::ranges::out_value_result<int, int>&>);
 
 struct C {
   C(int&);
@@ -39,10 +41,14 @@ struct C {
 static_assert(!std::is_constructible_v<std::ranges::out_value_result<C, C>, std::ranges::out_value_result<int, int>&>);
 
 // has to be convertible via const&
-static_assert(std::is_convertible_v<std::ranges::out_value_result<int, int>&, std::ranges::out_value_result<long, long>>);
-static_assert(std::is_convertible_v<const std::ranges::out_value_result<int, int>&, std::ranges::out_value_result<long, long>>);
-static_assert(std::is_convertible_v<std::ranges::out_value_result<int, int>&&, std::ranges::out_value_result<long, long>>);
-static_assert(std::is_convertible_v<const std::ranges::out_value_result<int, int>&&, std::ranges::out_value_result<long, long>>);
+static_assert(
+    std::is_convertible_v<std::ranges::out_value_result<int, int>&, std::ranges::out_value_result<long, long>>);
+static_assert(
+    std::is_convertible_v<const std::ranges::out_value_result<int, int>&, std::ranges::out_value_result<long, long>>);
+static_assert(
+    std::is_convertible_v<std::ranges::out_value_result<int, int>&&, std::ranges::out_value_result<long, long>>);
+static_assert(
+    std::is_convertible_v<const std::ranges::out_value_result<int, int>&&, std::ranges::out_value_result<long, long>>);
 
 // should be move constructible
 static_assert(std::is_move_constructible_v<std::ranges::out_value_result<MoveOnly, int>>);
@@ -54,8 +60,10 @@ static_assert(!std::is_copy_constructible_v<std::ranges::out_value_result<int, M
 
 struct NotConvertible {};
 // conversions should not work if there is no conversion
-static_assert(!std::is_convertible_v<std::ranges::out_value_result<NotConvertible, int>, std::ranges::out_value_result<int, int>>);
-static_assert(!std::is_convertible_v<std::ranges::out_value_result<int, NotConvertible>, std::ranges::out_value_result<int, int>>);
+static_assert(!std::is_convertible_v<std::ranges::out_value_result<NotConvertible, int>,
+                                     std::ranges::out_value_result<int, int>>);
+static_assert(!std::is_convertible_v<std::ranges::out_value_result<int, NotConvertible>,
+                                     std::ranges::out_value_result<int, int>>);
 
 template <class T>
 struct ConvertibleFrom {

@Zingam
Copy link
Contributor

Zingam commented Sep 22, 2024

@PaulXiCao I think there is already an active PR implementing ranges::iota #68494
also another one implementing ranges::shift_left: #83231

We have now a project libc++ Standard Conformance libc++ Standards Conformance (view)

I believe noone is working on cartesian_product but you should ask on Discord first.

@PaulXiCao
Copy link
Contributor Author

@Zingam Thanks for the feedback! I will close this pr and see if I can give any valueable feedback in the mentioned prs.

The linked "libc++ Standard Conformance" project seems really useful!

@PaulXiCao PaulXiCao closed this Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants