Howard Hinnant | e008d4e | 2013-07-04 19:46:35 +0000 | [diff] [blame] | 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 | // <map> |
| 11 | |
| 12 | // template <class Key, class T, class Compare = less<Key>, |
| 13 | // class Allocator = allocator<pair<const Key, T>>> |
| 14 | // class map |
| 15 | |
| 16 | // http://llvm.org/bugs/show_bug.cgi?id=16538 |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 17 | // http://llvm.org/bugs/show_bug.cgi?id=16549 |
Howard Hinnant | e008d4e | 2013-07-04 19:46:35 +0000 | [diff] [blame] | 18 | |
| 19 | #include <map> |
Eric Fiselier | 02bb4bd | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 20 | #include <utility> |
| 21 | #include <cassert> |
Howard Hinnant | e008d4e | 2013-07-04 19:46:35 +0000 | [diff] [blame] | 22 | |
| 23 | struct Key { |
| 24 | template <typename T> Key(const T&) {} |
| 25 | bool operator< (const Key&) const { return false; } |
| 26 | }; |
| 27 | |
Eric Fiselier | 02bb4bd | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 28 | int main() |
Howard Hinnant | e008d4e | 2013-07-04 19:46:35 +0000 | [diff] [blame] | 29 | { |
Eric Fiselier | 02bb4bd | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 30 | typedef std::map<Key, int> MapT; |
| 31 | typedef MapT::iterator Iter; |
| 32 | typedef std::pair<Iter, bool> IterBool; |
| 33 | { |
| 34 | MapT m_empty; |
| 35 | MapT m_contains; |
| 36 | m_contains[Key(0)] = 42; |
| 37 | |
| 38 | Iter it = m_empty.find(Key(0)); |
| 39 | assert(it == m_empty.end()); |
| 40 | it = m_contains.find(Key(0)); |
| 41 | assert(it != m_contains.end()); |
| 42 | } |
| 43 | { |
| 44 | MapT map; |
| 45 | IterBool result = map.insert(std::make_pair(Key(0), 42)); |
| 46 | assert(result.second); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 47 | assert(result.first->second = 42); |
Eric Fiselier | 02bb4bd | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 48 | IterBool result2 = map.insert(std::make_pair(Key(0), 43)); |
| 49 | assert(!result2.second); |
| 50 | assert(map[Key(0)] == 42); |
| 51 | } |
Howard Hinnant | e008d4e | 2013-07-04 19:46:35 +0000 | [diff] [blame] | 52 | } |