This patch implements the C++20-style contains() for DenseMap,
MapVector, and StringMap.
With this patch, every set and map container type that has count()
also has contains().
Paths
| Differential D145895
[ADT] Implement {DenseMap,MapVector,StringMap}::contains ClosedPublic Authored by kazu on Mar 12 2023, 10:23 PM.
Details Summary This patch implements the C++20-style contains() for DenseMap, With this patch, every set and map container type that has count()
Diff Detail
Event TimelineComment Actions LGTM. Separately, it would be cool if we could make llvm::is_contained use the contains member when available, instead of doing a linear scan. It seems like a bit of a foot gun to me to have 2 functions with almost identical names but vastly different performance characteristics. This revision is now accepted and ready to land.Mar 13 2023, 8:04 AM Closed by commit rG21700677cb44: [ADT] Implement {DenseMap,MapVector,StringMap}::contains (authored by kazu). · Explain WhyMar 13 2023, 9:13 AM This revision was automatically updated to reflect the committed changes. Comment Actions
Thanks for the reivew! I might just migrate those to $set.contains() or $map.contains(). In theory, it's possible to write a template that calls llvm::is_contained so that it can work with either an array or a set, but I don't know how common that is. With some template tricks, we could implement a check for the contains() method. If so, we could do static_assert(!sizeof(T*), "Use contains() instead.") or something, at least in our working source tree, maybe not in production.
Revision Contents
Diff 504701 llvm/include/llvm/ADT/DenseMap.h
llvm/include/llvm/ADT/MapVector.h
llvm/include/llvm/ADT/StringMap.h
llvm/unittests/ADT/DenseMapTest.cpp
llvm/unittests/ADT/MapVectorTest.cpp
llvm/unittests/ADT/StringMapTest.cpp
|