1 // Copyright (C) 2018-2025 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 // { dg-do run { target c++11 } }
20 #include <unordered_map>
21 #include <testsuite_hooks.h>
27 mutable int conversions
= 0;
29 operator std::pair
<const int, int>() const {
30 if (++conversions
> 1)
36 std::unordered_map
<int, int> m
;
38 VERIFY( m
.size() == 1 );
39 m
.insert(m
.begin(), X());
40 VERIFY( m
.size() == 1 );
49 operator std::pair
<const int, int>() && {
50 if (++conversions
> 1)
56 std::unordered_map
<int, int> m
;
58 VERIFY( m
.size() == 1 );
59 m
.insert(m
.begin(), Y());
60 VERIFY( m
.size() == 1 );
65 bool operator==(const Key
& r
) const { return key
== r
.key
; }
69 template<> struct hash
<Key
> {
70 size_t operator()(const Key
& k
) const { return std::hash
<int>()(k
.key
); }
75 operator std::pair
<const Key
, int>() const { return { { z
}, 0 }; }
85 Alloc(const Alloc
<U
>&) { }
89 T
* allocate(std::size_t n
) { return std::allocator
<T
>().allocate(n
); }
91 void deallocate(T
* p
, std::size_t n
) { std::allocator
<T
>().deallocate(p
, n
); }
94 void construct(U
* p
, const Z
& z
) { ::new (p
) U
{ { z
.z
+1 }, 0}; }
97 bool operator==(const Alloc
<U
>&) { return true; }
100 bool operator!=(const Alloc
<U
>&) { return false; }
106 std::unordered_map
<Key
, int, std::hash
<Key
>, std::equal_to
<Key
>,
107 Alloc
<std::pair
<const Key
, int>>> m
;
110 VERIFY( m
.size() == 1 );
113 VERIFY( m
.size() == 2 );