Skip to content

Implement ranges::replace - #983

Merged
Stephan T. Lavavej (StephanTLavavej) merged 8 commits into
microsoft:masterfrom
miscco:ranges_replace
Jul 11, 2020
Merged

Stephan T. Lavavej (StephanTLavavej) merged 8 commits into
microsoft:masterfrom
miscco:ranges_replace

Conversation

@miscco

Copy link
Copy Markdown
Contributor

This implements the ranges::replace algorithm.

Casey Carter (@CaseyCarter): This does not yet compile as the algorithm has some additional constraints that are not fulfilled by the generic with_input_range

The question is whether we want to specialize some with_comparable_range in the algorithm support header or simply special case it in the test. As that will most likely happen with other algorithms too I would like find a fitting solution that fits best for all algorithms.

Also the wording is really strange. IT says that the algorithm shall return last which could actually be a sentinel. I believe it is indeed meant to return respective iterator but icky wording

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does not yet compile as the algorithm has some additional constraints that are not fulfilled by the generic with_input_range

Since this is passing now, I suspect you've realized that testing ranges with proxy references requires you to stick fairly closely to ints or pairs, or be prepared to add operations to test::proxy_reference.

also the wording is really strange. It says that the algorithm shall return last which could actually be a sentinel. I believe it is indeed meant to return respective iterator but icky wording.

See [algorithms.requirements]/13, and read [algorithms.requirements]/12 while you're there. WG21 specifies algorithms in a DSL that resembles but is not C++ ;)

Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
@miscco

Copy link
Copy Markdown
Contributor Author

One style question for the maintainers.

Do you prefer individual algorithm PRs like this here or should I open a single PR for e.g. all ranges::replace* algorithms?

@StephanTLavavej

Copy link
Copy Markdown
Member

I think it's generally easier to review an entire family of algorithms in a single PR, since following a consistent pattern makes reviewing similar algorithms easier - then we just need to watch out for inconsistencies and (somewhat harder) watch out for places that should be different - neither of which is helped by splitting algorithms across PRs.

Other maintainers may feel differently. It's not critically important for me.

@CaseyCarter Casey Carter (CaseyCarter) mentioned this pull request Jul 7, 2020
@miscco

Copy link
Copy Markdown
Contributor Author

To ease review and reduce thenumber of concurrent PRs I have merged the other two remaining ranges::replace algorithms into this PR

Comment thread tests/std/tests/P0896R4_ranges_alg_replace_copy_if/test.cpp Outdated
* Extract `with_output_iterators` from `with_writable_iterators` and implement `test_in_outerator` to instantiate with `input_range` and `output_iterator` types.

* Pull `ranges::equal` out of `instantiator::call` in both `replace_copy` and `replace_copy_if` tests to avoid `/analyze` exhausting the compiler heap.
Comment thread tests/std/include/range_algorithm_support.hpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will push changes to fix comment typos, otherwise looks great!

Comment thread stl/inc/algorithm
Comment thread stl/inc/algorithm
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit f357e2c into microsoft:master Jul 11, 2020
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks Michael Schellenberger Costa (@miscco)! You're irreplaceable. 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cxx20 C++20 feature ranges C++20/23 ranges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants