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 // UNSUPPORTED: c++03, c++11, c++14, c++17 10 11 #include <cassert> 12 #include <map> 13 14 // <map> 15 16 // bool contains(const key_type& x) const; 17 18 template <typename T, typename P, typename B, typename... Pairs> 19 void test(B bad, Pairs... args) { 20 T map; 21 P pairs[] = {args...}; 22 23 for (auto& p : pairs) map.insert(p); 24 for (auto& p : pairs) assert(map.contains(p.first)); 25 26 assert(!map.contains(bad)); 27 } 28 29 struct E { int a = 1; double b = 1; char c = 1; }; 30 31 int main(int, char**) 32 { 33 { 34 test<std::map<char, int>, std::pair<char, int> >( 35 'e', std::make_pair('a', 10), std::make_pair('b', 11), 36 std::make_pair('c', 12), std::make_pair('d', 13)); 37 38 test<std::map<char, char>, std::pair<char, char> >( 39 'e', std::make_pair('a', 'a'), std::make_pair('b', 'a'), 40 std::make_pair('c', 'a'), std::make_pair('d', 'b')); 41 42 test<std::map<int, E>, std::pair<int, E> >( 43 -1, std::make_pair(1, E{}), std::make_pair(2, E{}), 44 std::make_pair(3, E{}), std::make_pair(4, E{})); 45 } 46 { 47 test<std::multimap<char, int>, std::pair<char, int> >( 48 'e', std::make_pair('a', 10), std::make_pair('b', 11), 49 std::make_pair('c', 12), std::make_pair('d', 13)); 50 51 test<std::multimap<char, char>, std::pair<char, char> >( 52 'e', std::make_pair('a', 'a'), std::make_pair('b', 'a'), 53 std::make_pair('c', 'a'), std::make_pair('d', 'b')); 54 55 test<std::multimap<int, E>, std::pair<int, E> >( 56 -1, std::make_pair(1, E{}), std::make_pair(2, E{}), 57 std::make_pair(3, E{}), std::make_pair(4, E{})); 58 } 59 60 return 0; 61 } 62