1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <unordered_map>
10
11// ~unordered_map() // implied noexcept;
12
13// UNSUPPORTED: c++03
14
15#include <unordered_map>
16#include <cassert>
17
18#include "test_macros.h"
19#include "MoveOnly.h"
20#include "test_allocator.h"
21
22template <class T>
23struct some_comp {
24 typedef T value_type;
25 ~some_comp() noexcept(false);
26 bool operator()(const T&, const T&) const { return false; }
27};
28
29template <class T>
30struct some_hash {
31 typedef T value_type;
32 some_hash();
33 some_hash(const some_hash&);
34 ~some_hash() noexcept(false);
35
36 std::size_t operator()(T const&) const;
37};
38
39int main(int, char**) {
40 {
41 typedef std::unordered_map<MoveOnly, MoveOnly> C;
42 static_assert(std::is_nothrow_destructible<C>::value, "");
43 }
44 {
45 typedef std::unordered_map<MoveOnly,
46 MoveOnly,
47 std::hash<MoveOnly>,
48 std::equal_to<MoveOnly>,
49 test_allocator<std::pair<const MoveOnly, MoveOnly>>>
50 C;
51 static_assert(std::is_nothrow_destructible<C>::value, "");
52 }
53 {
54 typedef std::unordered_map<MoveOnly,
55 MoveOnly,
56 std::hash<MoveOnly>,
57 std::equal_to<MoveOnly>,
58 other_allocator<std::pair<const MoveOnly, MoveOnly>>>
59 C;
60 static_assert(std::is_nothrow_destructible<C>::value, "");
61 }
62#if defined(_LIBCPP_VERSION)
63 {
64 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
65 static_assert(!std::is_nothrow_destructible<C>::value, "");
66 }
67 {
68 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>, some_comp<MoveOnly>> C;
69 static_assert(!std::is_nothrow_destructible<C>::value, "");
70 }
71#endif // _LIBCPP_VERSION
72
73 return 0;
74}
75

source code of libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/dtor_noexcept.pass.cpp