move_assign_noexcept.pass.cpp revision 39213641f4dbaa2f412bd6cceb57f81edcae95f9
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// unordered_map& operator=(unordered_map&& c)
13//     noexcept(
14//          allocator_type::propagate_on_container_move_assignment::value &&
15//          is_nothrow_move_assignable<allocator_type>::value &&
16//          is_nothrow_move_assignable<key_compare>::value);
17
18// This tests a conforming extension
19
20#include <unordered_map>
21#include <cassert>
22
23#include "../../../MoveOnly.h"
24#include "../../../test_allocator.h"
25
26template <class T>
27struct some_comp
28{
29    typedef T value_type;
30    some_comp& operator=(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    some_hash& operator=(const some_hash&);
40};
41
42int main()
43{
44#if __has_feature(cxx_noexcept)
45    {
46        typedef std::unordered_map<MoveOnly, MoveOnly> C;
47        static_assert(std::is_nothrow_move_assignable<C>::value, "");
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        static_assert(!std::is_nothrow_move_assignable<C>::value, "");
53    }
54    {
55        typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
56                          std::equal_to<MoveOnly>, other_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
57        static_assert(std::is_nothrow_move_assignable<C>::value, "");
58    }
59    {
60        typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
61        static_assert(!std::is_nothrow_move_assignable<C>::value, "");
62    }
63    {
64        typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
65                                                         some_comp<MoveOnly>> C;
66        static_assert(!std::is_nothrow_move_assignable<C>::value, "");
67    }
68#endif
69}
70