]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/78595.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / multimap / modifiers / insert / 78595.cc
CommitLineData
8d9254fc 1// Copyright (C) 2018-2020 Free Software Foundation, Inc.
bc62e155
JW
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// { dg-do run { target c++11 } }
19
20#include <map>
21#include <testsuite_hooks.h>
22
23void
24test01()
25{
26 struct X {
27 mutable int conversions = 0;
28
29 operator std::pair<const int, int>() const {
30 if (++conversions > 1)
31 throw 1;
32 return {};
33 }
34 };
35
36 std::multimap<int, int> m;
37 m.insert(X());
38 VERIFY( m.size() == 1 );
39 m.insert(m.begin(), X());
40 VERIFY( m.size() == 2 );
41
42}
43void
44test02()
45{
46 struct Y {
47 int conversions = 0;
48
49 operator std::pair<const int, int>() && {
50 if (++conversions > 1)
51 throw 1;
52 return {};
53 }
54 };
55
56 std::multimap<int, int> m;
57 m.insert(Y());
58 VERIFY( m.size() == 1 );
59 m.insert(m.begin(), Y());
60 VERIFY( m.size() == 2 );
61}
62
63struct Key {
64 int key;
65 bool operator<(const Key& r) const { return key < r.key; }
66};
67
68struct Z {
69 operator std::pair<const Key, int>() const { return { { z }, 0 }; }
70 int z;
71};
72
73template<typename T>
74struct Alloc
75{
76 Alloc() = default;
77
78 template<typename U>
79 Alloc(const Alloc<U>&) { }
80
81 using value_type = T;
82
83 T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); }
84
85 void deallocate(T* p, std::size_t n) { std::allocator<T>().deallocate(p, n); }
86
87 template<typename U>
88 void construct(U* p, const Z& z) { ::new (p) U{ { z.z+1 }, 0}; }
89
90 template<typename U>
91 bool operator==(const Alloc<U>&) { return true; }
92
93 template<typename U>
94 bool operator!=(const Alloc<U>&) { return false; }
95};
96
97void
98test03()
99{
100 std::multimap<Key, int, std::less<Key>, Alloc<std::pair<const Key, int>>> m;
101 m.insert(Z{});
102 m.insert(Z{});
103 VERIFY( m.size() == 2 );
104 m.insert(Z{});
105 m.insert(Z{1});
106 VERIFY( m.size() == 4 );
107}
108
109int
110main()
111{
112 test01();
113 test02();
114 test03();
115}