[libcxx] r185665 - Simplify comparators of [unordered_][multi]map. This fixes http://llvm.org/bugs/show_bug.cgi?id=16538

Howard Hinnant hhinnant at apple.com
Thu Jul 4 12:46:35 PDT 2013


Author: hhinnant
Date: Thu Jul  4 14:46:35 2013
New Revision: 185665

URL: http://llvm.org/viewvc/llvm-project?rev=185665&view=rev
Log:
Simplify comparators of [unordered_][multi]map.  This fixes http://llvm.org/bugs/show_bug.cgi?id=16538

Added:
    libcxx/trunk/test/containers/associative/map/compare.pass.cpp
    libcxx/trunk/test/containers/unord/unord.map/compare.pass.cpp
Modified:
    libcxx/trunk/include/map
    libcxx/trunk/include/unordered_map

Modified: libcxx/trunk/include/map
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/map?rev=185665&r1=185664&r2=185665&view=diff
==============================================================================
--- libcxx/trunk/include/map (original)
+++ libcxx/trunk/include/map Thu Jul  4 14:46:35 2013
@@ -389,7 +389,6 @@ template <class _Key, class _Tp, class _
 class __map_value_compare
     : private _Compare
 {
-    typedef pair<typename std::remove_const<_Key>::type, _Tp> _Pp;
     typedef pair<const _Key, _Tp> _CP;
 public:
     _LIBCPP_INLINE_VISIBILITY
@@ -406,29 +405,11 @@ public:
     bool operator()(const _CP& __x, const _CP& __y) const
         {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _CP& __x, const _Pp& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _CP& __x, const _Key& __y) const
         {return static_cast<const _Compare&>(*this)(__x.first, __y);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _CP& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Pp& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Key& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _CP& __y) const
         {return static_cast<const _Compare&>(*this)(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Pp& __y) const
-        {return static_cast<const _Compare&>(*this)(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Key& __y) const
-        {return static_cast<const _Compare&>(*this)(__x, __y);}
 };
 
 template <class _Key, class _Tp, class _Compare>
@@ -436,7 +417,6 @@ class __map_value_compare<_Key, _Tp, _Co
 {
     _Compare comp;
 
-    typedef pair<typename std::remove_const<_Key>::type, _Tp> _Pp;
     typedef pair<const _Key, _Tp> _CP;
 
 public:
@@ -455,29 +435,11 @@ public:
     bool operator()(const _CP& __x, const _CP& __y) const
         {return comp(__x.first, __y.first);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _CP& __x, const _Pp& __y) const
-        {return comp(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _CP& __x, const _Key& __y) const
         {return comp(__x.first, __y);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _CP& __y) const
-        {return comp(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Pp& __y) const
-        {return comp(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Key& __y) const
-        {return comp(__x.first, __y);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _CP& __y) const
         {return comp(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Pp& __y) const
-        {return comp(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Key& __y) const
-        {return comp(__x, __y);}
 };
 
 template <class _Allocator>

Modified: libcxx/trunk/include/unordered_map
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/unordered_map?rev=185665&r1=185664&r2=185665&view=diff
==============================================================================
--- libcxx/trunk/include/unordered_map (original)
+++ libcxx/trunk/include/unordered_map Thu Jul  4 14:46:35 2013
@@ -333,7 +333,6 @@ template <class _Key, class _Tp, class _
 class __unordered_map_hasher
     : private _Hash
 {
-    typedef pair<typename remove_const<_Key>::type, _Tp> _Pp;
     typedef pair<const _Key, _Tp> _Cp;
 public:
     _LIBCPP_INLINE_VISIBILITY
@@ -347,9 +346,6 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     const _Hash& hash_function() const _NOEXCEPT {return *this;}
     _LIBCPP_INLINE_VISIBILITY
-    size_t operator()(const _Pp& __x) const
-        {return static_cast<const _Hash&>(*this)(__x.first);}
-    _LIBCPP_INLINE_VISIBILITY
     size_t operator()(const _Cp& __x) const
         {return static_cast<const _Hash&>(*this)(__x.first);}
     _LIBCPP_INLINE_VISIBILITY
@@ -362,7 +358,6 @@ class __unordered_map_hasher<_Key, _Tp,
 {
     _Hash __hash_;
 
-    typedef pair<typename remove_const<_Key>::type, _Tp> _Pp;
     typedef pair<const _Key, _Tp> _Cp;
 public:
     _LIBCPP_INLINE_VISIBILITY
@@ -376,9 +371,6 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
     _LIBCPP_INLINE_VISIBILITY
-    size_t operator()(const _Pp& __x) const
-        {return __hash_(__x.first);}
-    _LIBCPP_INLINE_VISIBILITY
     size_t operator()(const _Cp& __x) const
         {return __hash_(__x.first);}
     _LIBCPP_INLINE_VISIBILITY
@@ -394,7 +386,6 @@ template <class _Key, class _Tp, class _
 class __unordered_map_equal
     : private _Pred
 {
-    typedef pair<typename remove_const<_Key>::type, _Tp> _Pp;
     typedef pair<const _Key, _Tp> _Cp;
 public:
     _LIBCPP_INLINE_VISIBILITY
@@ -408,32 +399,14 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     const _Pred& key_eq() const _NOEXCEPT {return *this;}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Pp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Cp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Key& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Cp& __x, const _Pp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _Cp& __y) const
         {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _Key& __y) const
         {return static_cast<const _Pred&>(*this)(__x.first, __y);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Pp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _Cp& __y) const
         {return static_cast<const _Pred&>(*this)(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Key& __y) const
-        {return static_cast<const _Pred&>(*this)(__x, __y);}
 };
 
 template <class _Key, class _Tp, class _Pred>
@@ -441,7 +414,6 @@ class __unordered_map_equal<_Key, _Tp, _
 {
     _Pred __pred_;
 
-    typedef pair<typename remove_const<_Key>::type, _Tp> _Pp;
     typedef pair<const _Key, _Tp> _Cp;
 public:
     _LIBCPP_INLINE_VISIBILITY
@@ -455,32 +427,14 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Pp& __y) const
-        {return __pred_(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Cp& __y) const
-        {return __pred_(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Key& __y) const
-        {return __pred_(__x.first, __y);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Cp& __x, const _Pp& __y) const
-        {return __pred_(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _Cp& __y) const
         {return __pred_(__x.first, __y.first);}
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _Key& __y) const
         {return __pred_(__x.first, __y);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Pp& __y) const
-        {return __pred_(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _Cp& __y) const
         {return __pred_(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Key& __y) const
-        {return __pred_(__x, __y);}
 };
 
 template <class _Alloc>

Added: libcxx/trunk/test/containers/associative/map/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/associative/map/compare.pass.cpp?rev=185665&view=auto
==============================================================================
--- libcxx/trunk/test/containers/associative/map/compare.pass.cpp (added)
+++ libcxx/trunk/test/containers/associative/map/compare.pass.cpp Thu Jul  4 14:46:35 2013
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// template <class Key, class T, class Compare = less<Key>,
+//           class Allocator = allocator<pair<const Key, T>>>
+// class map
+
+// http://llvm.org/bugs/show_bug.cgi?id=16538
+
+#include <map>
+
+struct Key {
+  template <typename T> Key(const T&) {}
+  bool operator< (const Key&) const { return false; }
+};
+
+int
+main()
+{
+    std::map<Key, int>::iterator it = std::map<Key, int>().find(Key(0));
+}

Added: libcxx/trunk/test/containers/unord/unord.map/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/unord/unord.map/compare.pass.cpp?rev=185665&view=auto
==============================================================================
--- libcxx/trunk/test/containers/unord/unord.map/compare.pass.cpp (added)
+++ libcxx/trunk/test/containers/unord/unord.map/compare.pass.cpp Thu Jul  4 14:46:35 2013
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+//           class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// http://llvm.org/bugs/show_bug.cgi?id=16538
+
+#include <unordered_map>
+
+struct Key {
+  template <typename T> Key(const T&) {}
+  bool operator== (const Key&) const { return true; }
+};
+
+namespace std
+{
+    template <>
+    struct hash<Key>
+    {
+        size_t operator()(Key const &) const {return 0;}
+    };
+}
+
+int
+main()
+{
+    std::unordered_map<Key, int>::iterator it =
+        std::unordered_map<Key, int>().find(Key(0));
+}





More information about the cfe-commits mailing list