Skip to content

Conversation

@miscco
Copy link
Contributor

@miscco miscco commented Jul 20, 2020

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

@miscco miscco requested a review from a team as a code owner July 20, 2020 13:23
@CaseyCarter CaseyCarter added the enhancement Something can be improved label Jul 20, 2020
@miscco
Copy link
Contributor Author

miscco commented Jul 21, 2020

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

@CaseyCarter
Copy link
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 StephanTLavavej changed the title Mordernize ranges::for_each Modernize ranges::for_each Jul 22, 2020
Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

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
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.

@StephanTLavavej StephanTLavavej added ranges C++20/23 ranges and removed ranges C++20/23 ranges labels Jul 22, 2020
@CaseyCarter CaseyCarter self-assigned this Jul 27, 2020
@CaseyCarter CaseyCarter merged commit 5ada43e into microsoft:master Jul 27, 2020
@CaseyCarter
Copy link
Contributor

Thanks for modernizing each of these algorithms.

@CaseyCarter CaseyCarter removed their assignment Jul 27, 2020
@miscco miscco deleted the ranges_for_each branch July 27, 2020 18:48
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