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{
25 typedef T value_type;
26 ~some_comp() noexcept(false);
27 bool operator()(const T&, const T&) const { return false; }
28};
29
30template <class T>
31struct some_hash
32{
33 typedef T value_type;
34 some_hash();
35 some_hash(const some_hash&);
36 ~some_hash() noexcept(false);
37
38 std::size_t operator()(T const&) const;
39};
40
41int main(int, char**)
42{
43 {
44 typedef std::unordered_map<MoveOnly, MoveOnly> C;
45 static_assert(std::is_nothrow_destructible<C>::value, "");
46 }
47 {
48 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
49 std::equal_to<MoveOnly>, test_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
50 static_assert(std::is_nothrow_destructible<C>::value, "");
51 }
52 {
53 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
54 std::equal_to<MoveOnly>, other_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
55 static_assert(std::is_nothrow_destructible<C>::value, "");
56 }
57#if defined(_LIBCPP_VERSION)
58 {
59 typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
60 static_assert(!std::is_nothrow_destructible<C>::value, "");
61 }
62 {
63 typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
64 some_comp<MoveOnly>> C;
65 static_assert(!std::is_nothrow_destructible<C>::value, "");
66 }
67#endif // _LIBCPP_VERSION
68
69 return 0;
70}
71

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