This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Use x.empty() instead of llvm::empty(x) (NFC)
ClosedPublic

Authored by kazu on Sep 11 2022, 1:12 PM.

Details

Summary

I'm planning to deprecate and eventually remove llvm::empty.

I thought about replacing llvm::empty(x) with std::empty(x), but it
turns out that all uses can be converted to x.empty(). That is, no
use requires the ability of std::empty to accept C arrays and
std::initializer_list.

Diff Detail

Event Timeline

kazu created this revision.Sep 11 2022, 1:12 PM
Herald added a project: Restricted Project. · View Herald Transcript
kazu requested review of this revision.Sep 11 2022, 1:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 11 2022, 1:12 PM
foad added a comment.Sep 12 2022, 12:58 AM

AMDGPU part LGTM, thanks!

dblaikie accepted this revision.Sep 12 2022, 9:40 AM

hmm, I think I remember llvm::empty was added, maybe before llvm::iterator_range got an empty operation of its own? And in theory range-based-for loops only require begin/end, so it's sort of nice that empty could be used with that same requirement, but if, practically speaking, all our ranges have empty on them - yeah, guess this is an OK way forward.

This revision is now accepted and ready to land.Sep 12 2022, 9:40 AM
kazu added a comment.Sep 12 2022, 11:27 AM

hmm, I think I remember llvm::empty was added, maybe before llvm::iterator_range got an empty operation of its own? And in theory range-based-for loops only require begin/end, so it's sort of nice that empty could be used with that same requirement, but if, practically speaking, all our ranges have empty on them - yeah, guess this is an OK way forward.

Thank you for the review, David!

Yes, llvm::empty indeed predates llvm::iterator_range::empty by about a year.

9fd397b423ba442808957e65e3ad25a07cd203e4 added llvm::empty on October 31, 2018.

fdaa74217420729140f1786ea037ac445a724c8e added llvm::iterator_range::empty on October 7, 2019.

FWIW, the only instance of llvm::empty(x) in our repository that couldn't be converted to x.empty() was involving std::initializer_list, but I've already converted that to x.size() in a fairly natural way in af91e2b9dba6a754e62862e14629af0d240d82bc.

MaskRay accepted this revision.Sep 12 2022, 12:53 PM
This revision was automatically updated to reflect the committed changes.