diff --git a/stl/inc/ranges b/stl/inc/ranges index 8fffa82ac9..7d85b73846 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -8972,6 +8972,7 @@ namespace ranges { concept _Regular_invocable_with_repeated_type = _Regular_invocable_with_repeated_type_impl<_Fn, _Ty, make_index_sequence<_Nx>>; +#if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-1975579 template struct _Invoke_result_with_repeated_type_impl; @@ -8983,6 +8984,19 @@ namespace ranges { template using _Invoke_result_with_repeated_type = _Invoke_result_with_repeated_type_impl<_Fn, _Ty, make_index_sequence<_Nx>>::type; +#else // ^^^ no workaround / workaround vvv + template + struct _Invoke_result_with_repeated_type_impl + : _Invoke_result_with_repeated_type_impl<_Fn, _Ty, _Nx - 1, _Ty, _Types...> {}; + + template + struct _Invoke_result_with_repeated_type_impl<_Fn, _Ty, 0, _Types...> { + using type = invoke_result_t<_Fn, _Types...>; + }; + + template + using _Invoke_result_with_repeated_type = _Invoke_result_with_repeated_type_impl<_Fn, _Ty, _Nx>::type; +#endif // ^^^ workaround ^^^ template concept _Adjacent_transform_constraints = diff --git a/tests/std/include/test_header_units_and_modules.hpp b/tests/std/include/test_header_units_and_modules.hpp index b7db048fc3..25576a13c3 100644 --- a/tests/std/include/test_header_units_and_modules.hpp +++ b/tests/std/include/test_header_units_and_modules.hpp @@ -596,9 +596,29 @@ void test_random() { void test_ranges() { using namespace std; puts("Testing ."); - constexpr int arr[]{11, 0, 22, 0, 33, 0, 44, 0, 55}; - assert(ranges::distance(views::filter(arr, [](int x) { return x == 0; })) == 4); - static_assert(ranges::distance(views::filter(arr, [](int x) { return x != 0; })) == 5); + + { + constexpr int arr[]{11, 0, 22, 0, 33, 0, 44, 0, 55}; + assert(ranges::distance(views::filter(arr, [](int x) { return x == 0; })) == 4); + static_assert(ranges::distance(views::filter(arr, [](int x) { return x != 0; })) == 5); + } + +#if TEST_STANDARD >= 23 + // Also test GH-4404 "unrecoverable error importing module 'std' with std::ranges::views::pairwise_transform" + { + constexpr array arr{10, 2, 30, 4, 50}; + + constexpr auto pairwise_plus = views::pairwise_transform(plus{}); + const auto vec2 = ranges::to(arr | pairwise_plus); + const vector correct2{12, 32, 34, 54}; + assert(vec2 == correct2); + + constexpr auto triplewise_plus = views::adjacent_transform<3>([](int x, int y, int z) { return x + y + z; }); + const auto vec3 = ranges::to(arr | triplewise_plus); + const vector correct3{42, 36, 84}; + assert(vec3 == correct3); + } +#endif // TEST_STANDARD >= 23 } void test_ratio() {