| 1 | // { dg-do run { target c++11 } } |
| 2 | |
| 3 | // Copyright (C) 2010-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | // |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU General Public License along |
| 17 | // with this library; see the file COPYING3. If not see |
| 18 | // <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // range insert |
| 21 | |
| 22 | #include <string> |
| 23 | #include <iterator> |
| 24 | #include <algorithm> |
| 25 | #include <unordered_map> |
| 26 | #include <testsuite_hooks.h> |
| 27 | |
| 28 | void test01() |
| 29 | { |
| 30 | typedef std::unordered_multimap<std::string, int> Map; |
| 31 | typedef std::pair<const std::string, int> Pair; |
| 32 | |
| 33 | Map m; |
| 34 | VERIFY(m.empty()); |
| 35 | |
| 36 | Pair A[5] = |
| 37 | { |
| 38 | Pair("red", 5), |
| 39 | Pair("green", 9), |
| 40 | Pair("blue", 3), |
| 41 | Pair("cyan", 8), |
| 42 | Pair("magenta", 7) |
| 43 | }; |
| 44 | |
| 45 | m.insert(A+0, A+5); |
| 46 | VERIFY(m.size() == 5); |
| 47 | VERIFY(std::distance(m.begin(), m.end()) == 5); |
| 48 | |
| 49 | for (int i = 0; i < 5; ++i) |
| 50 | VERIFY(std::find(m.begin(), m.end(), A[i]) != m.end()); |
| 51 | } |
| 52 | |
| 53 | void test02() |
| 54 | { |
| 55 | typedef std::unordered_multimap<std::string, int> Map; |
| 56 | typedef std::pair<const std::string, int> Pair; |
| 57 | |
| 58 | Map m; |
| 59 | VERIFY(m.empty()); |
| 60 | |
| 61 | Pair A[9] = |
| 62 | { |
| 63 | Pair("red", 5), |
| 64 | Pair("green", 9), |
| 65 | Pair("red", 19), |
| 66 | Pair("blue", 3), |
| 67 | Pair("blue", 60), |
| 68 | Pair("cyan", 8), |
| 69 | Pair("magenta", 7), |
| 70 | Pair("blue", 99), |
| 71 | Pair("green", 33) |
| 72 | }; |
| 73 | |
| 74 | m.insert(A+0, A+9); |
| 75 | VERIFY(m.size() == 9); |
| 76 | VERIFY(std::distance(m.begin(), m.end()) == 9); |
| 77 | |
| 78 | for (int i = 0; i < 9; ++i) |
| 79 | VERIFY(std::find(m.begin(), m.end(), A[i]) != m.end()); |
| 80 | } |
| 81 | |
| 82 | int main() |
| 83 | { |
| 84 | test01(); |
| 85 | test02(); |
| 86 | return 0; |
| 87 | } |