]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_map/operators/2.cc
1 // Copyright (C) 2012-2013 Free Software Foundation, Inc.
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)
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.
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/>.
18 // 23.5.4 template class unordered_map
20 // This test verifies that the value type of a unordered_map need not be
23 // { dg-options "-std=gnu++11" }
25 #include <unordered_map>
26 #include <testsuite_hooks.h>
27 #include <testsuite_rvalref.h>
28 #include <testsuite_counter_type.h>
33 explicit Mapped(const Mapped
&) = default;
36 struct DefaultConstructibleType
40 DefaultConstructibleType() : val(123)
43 DefaultConstructibleType(const DefaultConstructibleType
&) = delete;
44 DefaultConstructibleType(DefaultConstructibleType
&&) = delete;
46 DefaultConstructibleType
& operator=(int x
)
55 bool test
__attribute__((unused
)) = true;
57 using __gnu_test::rvalstruct
;
58 using __gnu_test::counter_type
;
60 std::unordered_map
<int, Mapped
> m1
;
63 std::unordered_map
<int, rvalstruct
> m2
;
64 m2
[0] = rvalstruct(13);
66 std::unordered_map
<int, DefaultConstructibleType
> m3
;
67 VERIFY( m3
[0].val
== 123 );
68 VERIFY( m3
.size() == 1 );
70 VERIFY( m3
[0].val
== 2 );
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 );
80 counter_type::reset();
83 VERIFY( counter_type::copy_count
== 1 );
84 VERIFY( counter_type::move_count
== 0 );