| 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 |
// Single-element insert |
| 21 |
|
| 22 |
#include <string> |
| 23 |
#include <iterator> |
| 24 |
#include <unordered_set> |
| 25 |
#include <testsuite_hooks.h> |
| 26 |
|
| 27 |
namespace |
| 28 |
{ |
| 29 |
std::size_t |
| 30 |
get_nb_bucket_elems(const std::unordered_multiset<std::string>& us) |
| 31 |
{ |
| 32 |
std::size_t nb = 0; |
| 33 |
for (std::size_t b = 0; b != us.bucket_count(); ++b) |
| 34 |
nb += us.bucket_size(b); |
| 35 |
return nb; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
void test01() |
| 41 |
{ |
| 42 |
typedef std::unordered_multiset<std::string> Set; |
| 43 |
Set s; |
| 44 |
VERIFY(s.empty()); |
| 45 |
|
| 46 |
Set::iterator i = s.insert("abcde"); |
| 47 |
VERIFY( s.size() == 1 ); |
| 48 |
VERIFY( get_nb_bucket_elems(s) == 1 ); |
| 49 |
VERIFY(std::distance(s.begin(), s.end()) == 1); |
| 50 |
VERIFY(i == s.begin()); |
| 51 |
VERIFY(*i == "abcde"); |
| 52 |
} |
| 53 |
|
| 54 |
void test02() |
| 55 |
{ |
| 56 |
typedef std::unordered_multiset<std::string> Set; |
| 57 |
Set s; |
| 58 |
VERIFY(s.empty()); |
| 59 |
|
| 60 |
s.insert("abcde"); |
| 61 |
Set::iterator i = s.insert("abcde"); |
| 62 |
VERIFY(s.size() == 2); |
| 63 |
VERIFY( get_nb_bucket_elems(s) == 2 ); |
| 64 |
VERIFY(std::distance(s.begin(), s.end()) == 2); |
| 65 |
VERIFY(*i == "abcde"); |
| 66 |
|
| 67 |
Set::iterator i2 = s.begin(); |
| 68 |
++i2; |
| 69 |
VERIFY(i == s.begin() || i == i2); |
| 70 |
VERIFY(*(s.begin()) == "abcde" && *i2 == "abcde"); |
| 71 |
} |
| 72 |
|
| 73 |
int main() |
| 74 |
{ |
| 75 |
test01(); |
| 76 |
test02(); |
| 77 |
return 0; |
| 78 |
} |