]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_single_move.cc
Update Copyright years for files modified in 2011 and/or 2012.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multiset / insert / multiset_single_move.cc
CommitLineData
802d83c3 1// { dg-options "-std=gnu++0x" }
2
3// 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com>
4//
71e45bc2 5// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
802d83c3 6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
10// Free Software Foundation; either version 3, or (at your option)
11// any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License along
19// with this library; see the file COPYING3. If not see
20// <http://www.gnu.org/licenses/>.
21
22// Single-element insert
23
24#include <iterator>
25#include <unordered_set>
26#include <testsuite_hooks.h>
27#include <testsuite_rvalref.h>
28
cd8960cc 29namespace
30{
31 template <typename _Tp>
32 std::size_t
33 get_nb_bucket_elems(const std::unordered_multiset<_Tp>& us)
34 {
35 std::size_t nb = 0;
36 for (std::size_t b = 0; b != us.bucket_count(); ++b)
37 nb += us.bucket_size(b);
38 return nb;
39 }
40}
41
802d83c3 42void test01()
43{
44 bool test __attribute__((unused)) = true;
45 using __gnu_test::rvalstruct;
46
47 typedef std::unordered_multiset<rvalstruct> Set;
48 Set s;
49 VERIFY( s.empty() );
50
51 Set::iterator i = s.insert(rvalstruct(1));
52 VERIFY( s.size() == 1 );
cd8960cc 53 VERIFY( get_nb_bucket_elems(s) == 1 );
802d83c3 54 VERIFY( std::distance(s.begin(), s.end()) == 1 );
55 VERIFY( i == s.begin() );
56 VERIFY( (*i).val == 1 );
57}
58
59void test02()
60{
61 bool test __attribute__((unused)) = true;
62 using __gnu_test::rvalstruct;
63
64 typedef std::unordered_multiset<rvalstruct> Set;
65 Set s;
66 VERIFY( s.empty() );
67
68 s.insert(rvalstruct(2));
69 Set::iterator i = s.insert(rvalstruct(2));
70 VERIFY( s.size() == 2 );
cd8960cc 71 VERIFY( get_nb_bucket_elems(s) == 2 );
802d83c3 72 VERIFY( std::distance(s.begin(), s.end()) == 2 );
73 VERIFY( (*i).val == 2 );
74
75 Set::iterator i2 = s.begin();
76 ++i2;
77 VERIFY( i == s.begin() || i == i2 );
78 VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 );
79}
80
81int main()
82{
83 test01();
84 test02();
85 return 0;
86}