brintos

brintos / llvm-project-archived public Read only

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