Skip to content

Modernize ranges::for_each - #1060

Merged
Casey Carter (CaseyCarter) merged 4 commits into
microsoft:masterfrom
miscco:ranges_for_each
Jul 27, 2020
Merged

Modernize ranges::for_each#1060
Casey Carter (CaseyCarter) merged 4 commits into
microsoft:masterfrom
miscco:ranges_for_each

Conversation

@miscco

Copy link
Copy Markdown
Contributor

This modernizes ranges::for_each and ranges::for_each_n to the current state of the art

@CaseyCarter Casey Carter (CaseyCarter) added the enhancement Something can be improved label Jul 20, 2020
Comment thread tests/std/tests/P0896R4_ranges_alg_for_each/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_for_each/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_for_each_n/test.cpp Outdated
@miscco

Michael Schellenberger Costa (miscco) commented Jul 21, 2020

Copy link
Copy Markdown
Contributor Author

Urgh I think adding constexpr changes the type of the lambda.

@CaseyCarter

Copy link
Copy Markdown
Contributor

Urgh I think adding constexpr changes the type of the lambda.

Yes: constexpr makes objects implicitly const; throwing a remove_const_t</**/> around decltype(lambda) should fix it.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) changed the title Mordernize ranges::for_each Modernize ranges::for_each Jul 22, 2020

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.

One comment nitpick, otherwise looks great!

assert(ranges::equal(expected, input));

int some_value = 1729;
result.fun(some_value);

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.

I observe that this test verifies that result.fun is invocable, but not that it actually contains the state accumulated by being invoked on each element. (An incorrect implementation could return a copy of the original callable object.) No change requested.

Comment thread tests/std/tests/P0896R4_ranges_alg_for_each_n/test.cpp Outdated
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added ranges C++20/23 ranges and removed ranges C++20/23 ranges labels Jul 22, 2020
@CaseyCarter
Casey Carter (CaseyCarter) merged commit 5ada43e into microsoft:master Jul 27, 2020
@CaseyCarter

Copy link
Copy Markdown
Contributor

Thanks for modernizing each of these algorithms.

@CaseyCarter Casey Carter (CaseyCarter) removed their assignment Jul 27, 2020
@miscco
Michael Schellenberger Costa (miscco) deleted the ranges_for_each branch July 27, 2020 18:48
Casey Carter (CaseyCarter) pushed a commit to CaseyCarter/STL that referenced this pull request Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved ranges C++20/23 ranges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants