Skip to content

Commit

Permalink
Modules workaround for views::pairwise_transform (#4420)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej committed Feb 27, 2024
1 parent 017bc35 commit 517b783
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
14 changes: 14 additions & 0 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class _Fn, class _Ty, class _Indices>
struct _Invoke_result_with_repeated_type_impl;

Expand All @@ -8983,6 +8984,19 @@ namespace ranges {
template <class _Fn, class _Ty, size_t _Nx>
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 <class _Fn, class _Ty, size_t _Nx, class... _Types>
struct _Invoke_result_with_repeated_type_impl
: _Invoke_result_with_repeated_type_impl<_Fn, _Ty, _Nx - 1, _Ty, _Types...> {};

template <class _Fn, class _Ty, class... _Types>
struct _Invoke_result_with_repeated_type_impl<_Fn, _Ty, 0, _Types...> {
using type = invoke_result_t<_Fn, _Types...>;
};

template <class _Fn, class _Ty, size_t _Nx>
using _Invoke_result_with_repeated_type = _Invoke_result_with_repeated_type_impl<_Fn, _Ty, _Nx>::type;
#endif // ^^^ workaround ^^^

template <class _Vw, class _Fn, size_t _Nx>
concept _Adjacent_transform_constraints =
Expand Down
26 changes: 23 additions & 3 deletions tests/std/include/test_header_units_and_modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,29 @@ void test_random() {
void test_ranges() {
using namespace std;
puts("Testing <ranges>.");
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<vector>(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<vector>(arr | triplewise_plus);
const vector correct3{42, 36, 84};
assert(vec3 == correct3);
}
#endif // TEST_STANDARD >= 23
}

void test_ratio() {
Expand Down

0 comments on commit 517b783

Please sign in to comment.