This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Allow SmallPtrSet to be used with a std::insert_iterator
ClosedPublic

Authored by aaron.ballman on Feb 5 2021, 6:34 AM.

Details

Summary

Currently, the SmallPtrSet type allows inserting elements but it does not support inserting elements with a positional hint. The lack of this signature means that you cannot use SmallPtrSet with std::insert_iterator or std::inserter(), which makes some code constructs more awkward. For example, it would be nice to be able to write:

llvm::copy_if(Buffer, std::inserter(SomeSmallPtrSet, SomeSmallPtrSet.begin()), [](...) { return whatever(); });

The positional hint is unused by SmallPtrSet and the call is equivalent to calling insert() without a hint.

Diff Detail

Event Timeline

aaron.ballman created this revision.Feb 5 2021, 6:34 AM
aaron.ballman requested review of this revision.Feb 5 2021, 6:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2021, 6:34 AM
dblaikie accepted this revision.Feb 5 2021, 12:37 PM
dblaikie added inline comments.
llvm/unittests/ADT/SmallPtrSetTest.cpp
405

I'd probably/prefer to make a direct call to the API, rather than testing it through a bunch of other container machinery. More isolated testing, clearer failures (not layers of template goo inside the standard library), etc.

(& my minor preference is towards using member begin/end unless the fully generic ADL call is needed (in which case you need llvm::adl_* functions or the raw using+unqualified call))

This revision is now accepted and ready to land.Feb 5 2021, 12:37 PM

Updating based on review feedback.

llvm/unittests/ADT/SmallPtrSetTest.cpp
405

Does the new test look better to you?

dblaikie added inline comments.Feb 5 2021, 1:09 PM
llvm/unittests/ADT/SmallPtrSetTest.cpp
405

Sure thing!

aaron.ballman closed this revision.Feb 5 2021, 1:13 PM

Thanks for the review! I've commit in ec04e2850adc044d84c840d7c48ebe3291ec47f7