[libcxx-commits] [libcxx] [libc++][ranges] `elements_view`: `get()` forward declarations - tests (PR #82323)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 26 00:04:34 PST 2024
https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/82323
>From 1d5814f01c0e501aef34ea29651721dc42f1db14 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 20 Feb 2024 10:51:01 +0200
Subject: [PATCH 1/3] [libc++][ranges] elements_view get() forward declarations
- tests
---
.../sequences/array/array.tuple/get.pass.cpp | 22 +++++++++++++++
.../complex.number/complex.tuple/get.pass.cpp | 2 +-
.../tuple.elem/get_non_const.pass.cpp | 27 ++++++++++++++++---
.../pairs/pair.astuple/get_non_const.pass.cpp | 24 ++++++++++++++++-
4 files changed, 70 insertions(+), 5 deletions(-)
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
index 04bb1313996df3..bd0e522068c697 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
@@ -12,6 +12,9 @@
#include <array>
#include <cassert>
+#include <concepts>
+#include <ranges>
+#include <vector>
#include "test_macros.h"
@@ -58,6 +61,25 @@ TEST_CONSTEXPR_CXX14 bool tests()
assert(std::get<2>(tempArray(1, 2, 3)) == 3);
}
+#if TEST_STD_VER >= 20
+ // `get()` allows using `array` with ranges
+ {
+ std::array<int, 2> arr[]{{27, 28}, {82, 94}};
+
+ std::same_as<std::vector<int>> decltype(auto) nums0{
+ arr | std::views::elements<0> | std::ranges::to<std::vector<int>>()};
+ assert(nums0.size() == 2);
+ assert(nums0[0] == 27);
+ assert(nums0[1] == 82);
+
+ std::same_as<std::vector<int>> decltype(auto) nums1{
+ arr | std::views::elements<1> | std::ranges::to<std::vector<int>>()};
+ assert(nums1.size() == 2);
+ assert(nums1[0] == 28);
+ assert(nums1[1] == 94);
+ }
+#endif
+
return true;
}
diff --git a/libcxx/test/std/numerics/complex.number/complex.tuple/get.pass.cpp b/libcxx/test/std/numerics/complex.number/complex.tuple/get.pass.cpp
index bd514a672cdcc8..c09457f08daa73 100644
--- a/libcxx/test/std/numerics/complex.number/complex.tuple/get.pass.cpp
+++ b/libcxx/test/std/numerics/complex.number/complex.tuple/get.pass.cpp
@@ -111,7 +111,7 @@ constexpr void test() {
std::same_as<std::vector<T>> decltype(auto) imags{
arr | std::views::elements<1> | std::ranges::to<std::vector<T>>()};
- assert(reals.size() == 2);
+ assert(imags.size() == 2);
assert(imags[0] == T{28});
assert(imags[1] == T{94});
}
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp
index e32b2fe57b0188..52697cb5aaa655 100644
--- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp
@@ -16,9 +16,12 @@
// UNSUPPORTED: c++03
-#include <tuple>
-#include <string>
#include <cassert>
+#include <concepts>
+#include <ranges>
+#include <string>
+#include <tuple>
+#include <vector>
#include "test_macros.h"
@@ -81,6 +84,24 @@ int main(int, char**)
}
#endif
+#if TEST_STD_VER >= 20
+ // `get()` allows using `tuple` with ranges
+ {
+ std::tuple<int, std::string> arr[]{{27, "hkt"}, {28, "zmt"}};
+
+ std::same_as<std::vector<int>> decltype(auto) numbers{
+ arr | std::views::elements<0> | std::ranges::to<std::vector<int>>()};
+ assert(numbers.size() == 2);
+ assert(numbers[0] == 27);
+ assert(numbers[1] == 28);
+
+ std::same_as<std::vector<std::string>> decltype(auto) strings{
+ arr | std::views::elements<1> | std::ranges::to<std::vector<std::string>>()};
+ assert(strings.size() == 2);
+ assert(strings[0] == "hkt");
+ assert(strings[1] == "zmt");
+ }
+#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
index 6119cd5c8ce970..2374dbdee2d830 100644
--- a/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
+++ b/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
@@ -14,8 +14,12 @@
// typename tuple_element<I, std::pair<T1, T2> >::type&
// get(pair<T1, T2>&);
-#include <utility>
#include <cassert>
+#include <concepts>
+#include <ranges>
+#include <string>
+#include <vector>
+#include <utility>
#include "test_macros.h"
@@ -49,6 +53,24 @@ int main(int, char**)
}
#endif
+#if TEST_STD_VER >= 20
+ // `get()` allows using `pair` with ranges
+ {
+ std::pair<int, std::string> arr[]{{27, "hkt"}, {28, "zmt"}};
+
+ std::same_as<std::vector<int>> decltype(auto) numbers{
+ arr | std::views::elements<0> | std::ranges::to<std::vector<int>>()};
+ assert(numbers.size() == 2);
+ assert(numbers[0] == 27);
+ assert(numbers[1] == 28);
+
+ std::same_as<std::vector<std::string>> decltype(auto) strings{
+ arr | std::views::elements<1> | std::ranges::to<std::vector<std::string>>()};
+ assert(strings.size() == 2);
+ assert(strings[0] == "hkt");
+ assert(strings[1] == "zmt");
+ }
+#endif
return 0;
}
>From 891db925d82c12072b955b44041245cd340d6ae9 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 20 Feb 2024 11:00:26 +0200
Subject: [PATCH 2/3] Fix formatting
---
.../utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
index 2374dbdee2d830..b688e3c70eac8e 100644
--- a/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
+++ b/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
@@ -72,5 +72,5 @@ int main(int, char**)
}
#endif
- return 0;
+ return 0;
}
>From f77912f2856a2355b0311102be3c5f793a6b95de Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Mon, 26 Feb 2024 10:03:49 +0200
Subject: [PATCH 3/3] Fixes
---
libcxx/include/__ranges/elements_view.h | 1 -
.../std/containers/sequences/array/array.tuple/get.pass.cpp | 2 +-
.../tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp | 2 +-
.../utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp | 2 +-
4 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__ranges/elements_view.h b/libcxx/include/__ranges/elements_view.h
index f159f53dc0a832..3f35e93b307128 100644
--- a/libcxx/include/__ranges/elements_view.h
+++ b/libcxx/include/__ranges/elements_view.h
@@ -16,7 +16,6 @@
#include <__concepts/derived_from.h>
#include <__concepts/equality_comparable.h>
#include <__config>
-#include <__fwd/complex.h>
#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__ranges/access.h>
diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
index bd0e522068c697..ecc469cd9a6ee6 100644
--- a/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp
@@ -61,7 +61,7 @@ TEST_CONSTEXPR_CXX14 bool tests()
assert(std::get<2>(tempArray(1, 2, 3)) == 3);
}
-#if TEST_STD_VER >= 20
+#if TEST_STD_VER >= 23
// `get()` allows using `array` with ranges
{
std::array<int, 2> arr[]{{27, 28}, {82, 94}};
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp
index 52697cb5aaa655..0990a7939b9910 100644
--- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp
@@ -84,7 +84,7 @@ int main(int, char**)
}
#endif
-#if TEST_STD_VER >= 20
+#if TEST_STD_VER >= 23
// `get()` allows using `tuple` with ranges
{
std::tuple<int, std::string> arr[]{{27, "hkt"}, {28, "zmt"}};
diff --git a/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
index b688e3c70eac8e..5dfd5523a765cc 100644
--- a/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
+++ b/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
@@ -53,7 +53,7 @@ int main(int, char**)
}
#endif
-#if TEST_STD_VER >= 20
+#if TEST_STD_VER >= 23
// `get()` allows using `pair` with ranges
{
std::pair<int, std::string> arr[]{{27, "hkt"}, {28, "zmt"}};
More information about the libcxx-commits
mailing list