1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <unordered_map>
11
12// void swap(unordered_map& c)
13//     noexcept(!allocator_type::propagate_on_container_swap::value ||
14//              __is_nothrow_swappable<allocator_type>::value);
15
16// This tests a conforming extension
17
18#include <unordered_map>
19#include <cassert>
20
21#include "../../../MoveOnly.h"
22#include "test_allocator.h"
23
24template <class T>
25struct some_comp
26{
27    typedef T value_type;
28
29    some_comp() {}
30    some_comp(const some_comp&) {}
31};
32
33template <class T>
34struct some_hash
35{
36    typedef T value_type;
37    some_hash() {}
38    some_hash(const some_hash&);
39};
40
41int main()
42{
43#if __has_feature(cxx_noexcept)
44    {
45        typedef std::unordered_map<MoveOnly, MoveOnly> C;
46        C c1, c2;
47        static_assert(noexcept(swap(c1, c2)), "");
48    }
49    {
50        typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
51                           std::equal_to<MoveOnly>, test_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
52        C c1, c2;
53        static_assert(noexcept(swap(c1, c2)), "");
54    }
55    {
56        typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
57                          std::equal_to<MoveOnly>, other_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
58        C c1, c2;
59        static_assert(noexcept(swap(c1, c2)), "");
60    }
61    {
62        typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
63        C c1, c2;
64        static_assert(!noexcept(swap(c1, c2)), "");
65    }
66    {
67        typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
68                                                         some_comp<MoveOnly>> C;
69        C c1, c2;
70        static_assert(!noexcept(swap(c1, c2)), "");
71    }
72#endif
73}
74