| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <unordered_map> |
| 10 | |
| 11 | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 12 | // class Alloc = allocator<pair<const Key, T>>> |
| 13 | // class unordered_map |
| 14 | |
| 15 | // https://llvm.org/PR16538 |
| 16 | // https://llvm.org/PR16549 |
| 17 | |
| 18 | #include <unordered_map> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | struct Key { |
| 24 | template <typename T> |
| 25 | Key(const T&) {} |
| 26 | bool operator==(const Key&) const { return true; } |
| 27 | }; |
| 28 | |
| 29 | template <> |
| 30 | struct std::hash<Key> { |
| 31 | std::size_t operator()(Key const&) const { return 0; } |
| 32 | }; |
| 33 | |
| 34 | int main(int, char**) { |
| 35 | typedef std::unordered_map<Key, int> MapT; |
| 36 | typedef MapT::iterator Iter; |
| 37 | MapT map; |
| 38 | Iter it = map.find(Key(0)); |
| 39 | assert(it == map.end()); |
| 40 | std::pair<Iter, bool> result = map.insert(std::make_pair(Key(0), 42)); |
| 41 | assert(result.second); |
| 42 | assert(result.first->second == 42); |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |