Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / map / operators / 2.cc
blob578a8c55b635fac1a44bb5d8ab7346f5cd1d86b5
1 // Copyright (C) 2012-2013 Free Software Foundation, Inc.
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.
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 // This test verifies that the value type of a map need not be default copyable.
20 // { dg-options "-std=c++11" }
22 #include <map>
23 #include <testsuite_hooks.h>
24 #include <testsuite_rvalref.h>
25 #include <testsuite_counter_type.h>
27 struct Mapped
29 Mapped() = default;
30 explicit Mapped(const Mapped&) = default;
33 struct DefaultConstructibleType
35 int val;
37 DefaultConstructibleType() : val(123)
40 DefaultConstructibleType(const DefaultConstructibleType&) = delete;
41 DefaultConstructibleType(DefaultConstructibleType&&) = delete;
43 DefaultConstructibleType& operator=(int x)
45 val = x;
46 return *this;
50 void test01()
52 bool test __attribute__((unused)) = true;
54 using __gnu_test::rvalstruct;
55 using __gnu_test::counter_type;
57 std::map<int, Mapped> m1;
58 m1[0] = Mapped();
60 std::map<int, rvalstruct> m2;
61 m2[0] = rvalstruct(13);
63 std::map<int, DefaultConstructibleType> m3;
64 VERIFY( m3[0].val == 123 );
65 VERIFY( m3.size() == 1 );
66 m3[0] = 2;
67 VERIFY( m3[0].val == 2 );
69 std::map<counter_type, int> m4;
70 VERIFY( m4[counter_type(1)] == 0 );
71 VERIFY( counter_type::specialize_count == 1 );
72 VERIFY( counter_type::copy_count == 0 );
73 VERIFY( counter_type::move_count == 1 );
75 counter_type k(2);
76 counter_type::reset();
78 VERIFY( m4[k] == 0 );
79 VERIFY( counter_type::copy_count == 1 );
80 VERIFY( counter_type::move_count == 0 );
83 int main()
85 test01();
86 return 0;