[PATCH] D53726: [ADT] Add initializer_list constructor, equality tests for DenseMap/DenseSet.

Lang Hames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 25 12:43:12 PDT 2018


lhames created this revision.
lhames added reviewers: dblaikie, chandlerc, mclow.lists, dberris.
Herald added subscribers: kristina, dexonsmith.

Adds an initializer_list constructor to DenseMap and fixes a bug in the
initializer_list constructor for DenseSet (it previously crashed on
initializer_lists whose lengths were not a power of two).

Also adds equality and inequality operators for DenseMap and DenseSet.

These changes make it easier to migrate existing code that uses std::map and
std::set (which support initializer_list construction and equality comparison)
to DenseMap and DenseSet.

[ADT] Fix equality operators to account for the unstable iteration order of DenseMap/DenseSet.

Also removes the initializer_list power-of-two bug fix that was split out in to
https://reviews.llvm.org/D53260.


Repository:
  rL LLVM

https://reviews.llvm.org/D53726

Files:
  include/llvm/ADT/DenseMap.h


Index: include/llvm/ADT/DenseMap.h
===================================================================
--- include/llvm/ADT/DenseMap.h
+++ include/llvm/ADT/DenseMap.h
@@ -40,7 +40,23 @@
 template <typename KeyT, typename ValueT>
 struct DenseMapPair : public std::pair<KeyT, ValueT> {
 
-  using std::pair<KeyT, ValueT>::pair;
+  // FIXME: Switch to inheriting constructors when we drop support for older
+  //        clang versions.
+  // NOTE: This default constructor is declared with '{}' rather than
+  //       '= default' to work around a bug in clang-800.
+  DenseMapPair() {}
+
+  template <typename AltKeyT, typename AltValueT>
+  DenseMapPair(AltKeyT &&AltKey, AltValueT &&AltValue,
+               typename std::enable_if<std::is_convertible<AltKeyT, KeyT>::value &&
+                              std::is_convertible<AltValueT, ValueT>::value>::type* = 0)
+    : std::pair<KeyT, ValueT>(std::forward<AltKeyT>(AltKey),
+                              std::forward<AltValueT>(AltValue)) {}
+
+  template <typename AltPairT>
+  DenseMapPair(AltPairT &&AltPair,
+               typename std::enable_if<std::is_convertible<AltPairT, std::pair<KeyT, ValueT>>::value>::type* = 0)
+    : std::pair<KeyT, ValueT>(std::forward<AltPairT>(AltPair)) {}
 
   KeyT &getFirst() { return std::pair<KeyT, ValueT>::first; }
   const KeyT &getFirst() const { return std::pair<KeyT, ValueT>::first; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53726.171171.patch
Type: text/x-patch
Size: 1392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181025/758700d5/attachment.bin>


More information about the llvm-commits mailing list