libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

compare.pass.cpp (1234B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <unordered_map>
     11 
     12 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
     13 //           class Alloc = allocator<pair<const Key, T>>>
     14 // class unordered_map
     15 
     16 // https://bugs.llvm.org/show_bug.cgi?id=16538
     17 // https://bugs.llvm.org/show_bug.cgi?id=16549
     18 
     19 #include <unordered_map>
     20 #include <cassert>
     21 
     22 struct Key {
     23   template <typename T> Key(const T&) {}
     24   bool operator== (const Key&) const { return true; }
     25 };
     26 
     27 namespace std
     28 {
     29     template <>
     30     struct hash<Key>
     31     {
     32         size_t operator()(Key const &) const {return 0;}
     33     };
     34 }
     35 
     36 int main()
     37 {
     38     typedef std::unordered_map<Key, int> MapT;
     39     typedef MapT::iterator Iter;
     40     MapT map;
     41     Iter it = map.find(Key(0));
     42     assert(it == map.end());
     43     std::pair<Iter, bool> result = map.insert(std::make_pair(Key(0), 42));
     44     assert(result.second);
     45     assert(result.first->second == 42);
     46 }