Skip to content

Conversation

@miscco
Copy link
Contributor

@miscco miscco commented Jul 4, 2020

This implements ranges_copy. There is some bug my brain autocorrect away. Will look at it later in the evening

@miscco miscco requested a review from a team as a code owner July 4, 2020 05:35
@StephanTLavavej StephanTLavavej added the cxx20 C++20 feature label Jul 4, 2020
Read wrapped_input{input};

auto result =
replace_copy(wrapped_input.begin(), wrapped_input.end(), Write{output}, 47, P{47, 1}, get_second);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler error is:

C:\agent\_work\1\s\tests\std\tests\P0896R4_ranges_alg_replace_copy\test.cpp(35,17): error: no matching function for call to object of type 'const std::ranges::_Replace_copy_fn'
                replace_copy(wrapped_input.begin(), wrapped_input.end(), Write{output}, 47, P{47, 1}, get_second);
                ^~~~~~~~~~~~
C:/agent/_work/1/s/tests/std/include\range_algorithm_support.hpp(603,32): note: in instantiation of function template specialization 'instantiator::call<test::range<std::input_iterator_tag, const std::pair<int, int>, test::Sized::no, test::CanDifference::no, test::Common::no, test::CanCompare::no, test::ProxyRef::no>, test::iterator<std::input_iterator_tag, std::pair<int, int>, test::CanDifference::no, test::CanCompare::no, test::ProxyRef::no, test::IsWrapped::yes> >' requested here
        Continuation::template call<Args...,
                               ^
C:/agent/_work/1/s/tests/std/include\range_algorithm_support.hpp(770,32): note: in instantiation of function template specialization 'with_writable_iterators<instantiator, std::pair<int, int> >::call<test::range<std::input_iterator_tag, const std::pair<int, int>, test::Sized::no, test::CanDifference::no, test::Common::no, test::CanCompare::no, test::ProxyRef::no> >' requested here
        Continuation::template call<Args...,
                               ^
C:/agent/_work/1/s/tests/std/include\range_algorithm_support.hpp(945,83): note: in instantiation of function template specialization 'with_input_ranges<with_writable_iterators<instantiator, std::pair<int, int> >, const std::pair<int, int> >::call<>' requested here
    with_input_ranges<with_writable_iterators<Instantiator, Element2>, Element1>::call();
                                                                                  ^
C:\agent\_work\1\s\tests\std\tests\P0896R4_ranges_alg_replace_copy\test.cpp(55,20): note: in instantiation of function template specialization 'test_in_write<instantiator, const std::pair<int, int>, std::pair<int, int> >' requested here
    STATIC_ASSERT((test_in_write<instantiator, P const, P>(), true));
                   ^
D:\build\x64\out\inc\algorithm(3080,50): note: candidate template ignored: constraints not satisfied [with _It = test::iterator<std::input_iterator_tag, const std::pair<int, int>, test::CanDifference::no, test::CanCompare::no, test::ProxyRef::no, test::IsWrapped::yes>, _Se = test::sentinel<const std::pair<int, int>, test::IsWrapped::yes>, _Ty1 = int, _Ty2 = std::pair<int, int>, _Out = test::iterator<std::input_iterator_tag, std::pair<int, int>, test::CanDifference::no, test::CanCompare::no, test::ProxyRef::no, test::IsWrapped::yes>, _Pj = get_nth_fn<1>]
        constexpr replace_copy_result<_It, _Out> operator()(
                                                 ^
D:\build\x64\out\inc\algorithm(3076,86): note: because 'output_iterator<test::iterator<std::input_iterator_tag, std::pair<int, int>, test::CanDifference::no, test::CanCompare::no, test::ProxyRef::no, test::IsWrapped::yes>, const std::pair<int, int> &>' evaluated to false
        template <input_iterator _It, sentinel_for<_It> _Se, class _Ty1, class _Ty2, output_iterator<const _Ty2&> _Out,
                                                                                     ^
D:\build\x64\out\inc\xutility(844,9): note: because '*__i++ = static_cast<_Ty &&>(__t)' would be invalid: indirection requires pointer operand ('void' invalid)
        *__i++ = static_cast<_Ty&&>(__t);
        ^

The template machinery here is almost beyond my comprehension, but I observe that (1) your test differs from the other tests currently using test_in_write in that its instantiator actually verifies the indirectly_writable concept, and (2) with_writable_iterators appears to pass iterator<input, MEOW> which doesn't seem correct:

Continuation::template call<Args...,
iterator<input, Element, CanDifference::no, CanCompare::no, ProxyRef::no>>();
Continuation::template call<Args...,
iterator<input, Element, CanDifference::no, CanCompare::no, ProxyRef::yes>>();

I'm not sure if this analysis is correct.

@miscco miscco force-pushed the ranges_replace_copy branch from 5a09b11 to 56a320c Compare July 4, 2020 17:05
@miscco
Copy link
Contributor Author

miscco commented Jul 6, 2020

I am wondering whether the output_iterator<const _Ty2&> _Out really makes sense. Especially given that all other algorithms (including copy) only require weakly_incrementable _Out.

@CaseyCarter can you remember why these two (and the remove_copy_*) are different?

@CaseyCarter CaseyCarter mentioned this pull request Jul 7, 2020
@miscco
Copy link
Contributor Author

miscco commented Jul 8, 2020

Dropping in favor of #983

@miscco miscco closed this Jul 8, 2020
@miscco miscco deleted the ranges_replace_copy branch July 8, 2020 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cxx20 C++20 feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants