This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Implement ranges::for_each{, _n}
ClosedPublic

Authored by philnik on Apr 23 2022, 9:25 AM.

Details

Reviewers
Mordante
var-const
Group Reviewers
Restricted Project
Commits
rG80045e9afa2f: [libc++] Implement ranges::for_each{, _n}

Diff Detail

Event Timeline

philnik created this revision.Apr 23 2022, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2022, 9:25 AM
Herald added a subscriber: mgorny. · View Herald Transcript
philnik requested review of this revision.Apr 23 2022, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2022, 9:25 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
var-const requested changes to this revision.Apr 27 2022, 8:15 PM

Looking pretty good, just a few comments.

libcxx/include/__algorithm/ranges_for_each_n.h
52

Nit: move __func as well?

libcxx/include/algorithm
984

Please update the synopsis as well.

libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
12

Please add the synopsis.

32

Please also check the indirectly_unary_invocable constraint.

46

Please also check with an empty range.

50

Nit: decltype(auto).

58

Can you also check that it works when the functor is move-only (since the standard mandates that for_each_result should initialize the functor by moving)?

This revision now requires changes to proceed.Apr 27 2022, 8:15 PM
var-const added inline comments.Apr 27 2022, 8:16 PM
libcxx/include/algorithm
984

(note that you'll probably need to add for_each_result to the synopsis)

philnik marked 8 inline comments as done.May 1 2022, 6:27 AM
philnik added inline comments.
libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
58

A functor can't be move-only. It's mandated that it's copy-constructible by indirectly_unary_invocable.

philnik updated this revision to Diff 426297.May 1 2022, 6:27 AM
philnik marked an inline comment as done.
  • Rebased
  • Address comments
var-const accepted this revision.May 2 2022, 2:25 PM
var-const added inline comments.
libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
58

Thanks for explaining.

101

Nit: s/emptry/empty/.

This revision is now accepted and ready to land.May 2 2022, 2:25 PM

LGTM, thanks!

This revision was automatically updated to reflect the committed changes.
philnik marked an inline comment as done.