llvm-project
55 строк · 1.4 Кб
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// <map>
10
11// template <class Key, class T, class Compare = less<Key>,
12// class Allocator = allocator<pair<const Key, T>>>
13// class map
14
15// https://llvm.org/PR16538
16// https://llvm.org/PR16549
17
18#include <map>
19#include <utility>
20#include <cassert>
21
22#include "test_macros.h"
23
24struct Key {
25template <typename T> Key(const T&) {}
26bool operator< (const Key&) const { return false; }
27};
28
29int main(int, char**)
30{
31typedef std::map<Key, int> MapT;
32typedef MapT::iterator Iter;
33typedef std::pair<Iter, bool> IterBool;
34{
35MapT m_empty;
36MapT m_contains;
37m_contains[Key(0)] = 42;
38
39Iter it = m_empty.find(Key(0));
40assert(it == m_empty.end());
41it = m_contains.find(Key(0));
42assert(it != m_contains.end());
43}
44{
45MapT map;
46IterBool result = map.insert(std::make_pair(Key(0), 42));
47assert(result.second);
48assert(result.first->second == 42);
49IterBool result2 = map.insert(std::make_pair(Key(0), 43));
50assert(!result2.second);
51assert(map[Key(0)] == 42);
52}
53
54return 0;
55}
56