15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
95a83710eSEric Fiselier // <map>
105a83710eSEric Fiselier
115a83710eSEric Fiselier // template <class Key, class T, class Compare = less<Key>,
125a83710eSEric Fiselier // class Allocator = allocator<pair<const Key, T>>>
135a83710eSEric Fiselier // class map
145a83710eSEric Fiselier
15*3c62198cSLouis Dionne // https://llvm.org/PR16538
16*3c62198cSLouis Dionne // https://llvm.org/PR16549
175a83710eSEric Fiselier
185a83710eSEric Fiselier #include <map>
192decfad7SEric Fiselier #include <utility>
202decfad7SEric Fiselier #include <cassert>
215a83710eSEric Fiselier
227fc6a556SMarshall Clow #include "test_macros.h"
237fc6a556SMarshall Clow
245a83710eSEric Fiselier struct Key {
KeyKey255a83710eSEric Fiselier template <typename T> Key(const T&) {}
operator <Key265a83710eSEric Fiselier bool operator< (const Key&) const { return false; }
275a83710eSEric Fiselier };
285a83710eSEric Fiselier
main(int,char **)292df59c50SJF Bastien int main(int, char**)
305a83710eSEric Fiselier {
312decfad7SEric Fiselier typedef std::map<Key, int> MapT;
322decfad7SEric Fiselier typedef MapT::iterator Iter;
332decfad7SEric Fiselier typedef std::pair<Iter, bool> IterBool;
342decfad7SEric Fiselier {
352decfad7SEric Fiselier MapT m_empty;
362decfad7SEric Fiselier MapT m_contains;
372decfad7SEric Fiselier m_contains[Key(0)] = 42;
382decfad7SEric Fiselier
392decfad7SEric Fiselier Iter it = m_empty.find(Key(0));
402decfad7SEric Fiselier assert(it == m_empty.end());
412decfad7SEric Fiselier it = m_contains.find(Key(0));
422decfad7SEric Fiselier assert(it != m_contains.end());
432decfad7SEric Fiselier }
442decfad7SEric Fiselier {
452decfad7SEric Fiselier MapT map;
462decfad7SEric Fiselier IterBool result = map.insert(std::make_pair(Key(0), 42));
472decfad7SEric Fiselier assert(result.second);
4891929f64SMarshall Clow assert(result.first->second == 42);
492decfad7SEric Fiselier IterBool result2 = map.insert(std::make_pair(Key(0), 43));
502decfad7SEric Fiselier assert(!result2.second);
512decfad7SEric Fiselier assert(map[Key(0)] == 42);
522decfad7SEric Fiselier }
532df59c50SJF Bastien
542df59c50SJF Bastien return 0;
555a83710eSEric Fiselier }
56