]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_map/operators/2.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_map / operators / 2.cc
CommitLineData
aa118a03 1// Copyright (C) 2012-2014 Free Software Foundation, Inc.
181a5a13
FD
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// 23.5.4 template class unordered_map
19
20// This test verifies that the value type of a unordered_map need not be
21// default copyable.
22
23// { dg-options "-std=gnu++11" }
24
25#include <unordered_map>
26#include <testsuite_hooks.h>
27#include <testsuite_rvalref.h>
28#include <testsuite_counter_type.h>
29
30struct Mapped
31{
32 Mapped() = default;
33 explicit Mapped(const Mapped&) = default;
34};
35
36struct DefaultConstructibleType
37{
38 int val;
39
40 DefaultConstructibleType() : val(123)
41 {}
42
43 DefaultConstructibleType(const DefaultConstructibleType&) = delete;
44 DefaultConstructibleType(DefaultConstructibleType&&) = delete;
45
46 DefaultConstructibleType& operator=(int x)
47 {
48 val = x;
49 return *this;
50 }
51};
52
53void test01()
54{
55 bool test __attribute__((unused)) = true;
56
57 using __gnu_test::rvalstruct;
58 using __gnu_test::counter_type;
59
60 std::unordered_map<int, Mapped> m1;
61 m1[0] = Mapped();
62
63 std::unordered_map<int, rvalstruct> m2;
64 m2[0] = rvalstruct(13);
65
66 std::unordered_map<int, DefaultConstructibleType> m3;
67 VERIFY( m3[0].val == 123 );
68 VERIFY( m3.size() == 1 );
69 m3[0] = 2;
70 VERIFY( m3[0].val == 2 );
71
72 std::unordered_map<counter_type, int,
73 __gnu_test::counter_type_hasher> m4;
74 VERIFY( m4[counter_type(1)] == 0 );
75 VERIFY( counter_type::specialize_count == 1 );
76 VERIFY( counter_type::copy_count == 0 );
77 VERIFY( counter_type::move_count == 1 );
78
79 counter_type k(2);
80 counter_type::reset();
81
82 VERIFY( m4[k] == 0 );
83 VERIFY( counter_type::copy_count == 1 );
84 VERIFY( counter_type::move_count == 0 );
85}
86
87int main()
88{
89 test01();
90 return 0;
91}