blob: 26ac7af7d908d6bdb893825bd664d904b1883bf2 [file] [log] [blame]
Howard Hinnante008d4e2013-07-04 19:46:35 +00001//===----------------------------------------------------------------------===//
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 Hinnant9b128e02013-07-05 18:06:00 +000017// http://llvm.org/bugs/show_bug.cgi?id=16549
Howard Hinnante008d4e2013-07-04 19:46:35 +000018
19#include <map>
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000020#include <utility>
21#include <cassert>
Howard Hinnante008d4e2013-07-04 19:46:35 +000022
23struct Key {
24 template <typename T> Key(const T&) {}
25 bool operator< (const Key&) const { return false; }
26};
27
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000028int main()
Howard Hinnante008d4e2013-07-04 19:46:35 +000029{
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000030 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 Albert1d4a1ed2016-05-25 22:36:09 -070047 assert(result.first->second = 42);
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000048 IterBool result2 = map.insert(std::make_pair(Key(0), 43));
49 assert(!result2.second);
50 assert(map[Key(0)] == 42);
51 }
Howard Hinnante008d4e2013-07-04 19:46:35 +000052}