This is an archive of the discontinued LLVM Phabricator instance.

Add and make use of llvm::for_each
ClosedPublic

Authored by aaron.ballman on Oct 27 2017, 1:06 PM.

Details

Summary

This patch introduces a range-based adapter for std::for_each(), similar to other extensions to <algorithm>. It's intended to be used as a replacement for std::for_each() when the full range is easily available, thus making the code easier to understand. It could also be used as a replacement for range-based for loops, though it may be less of a win there.

It also switches cases within LLVM to use the new facilities.

Diff Detail

Event Timeline

aaron.ballman created this revision.Oct 27 2017, 1:06 PM

Now, with more delicious patch context!

echristo edited edge metadata.Oct 27 2017, 1:34 PM

That looks pretty usable for someone as bad at C++ as I am so I'm in favor.

Ultimately I delegate to dblaikie though.

-eric

grimar added a subscriber: grimar.Oct 30 2017, 2:11 AM
dblaikie accepted this revision.Nov 2 2017, 3:04 PM

I still feel like for_each might as well change to range-based-for. Some of these examples are admittedly a bit awkward as range-based-for & I doubt there's going to be a big proliferation of for_each from people who don't know range-for is there, so doesn't seem like there's much harm/risk to having this for the few cases it can be handy for. (:

This revision is now accepted and ready to land.Nov 2 2017, 3:04 PM
aaron.ballman closed this revision.Nov 3 2017, 1:02 PM

Thanks for the review! I've commit in r317356.