]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/unord/unord.map/unord.map.cnstr/move_noexcept.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / unord / unord.map / unord.map.cnstr / move_noexcept.pass.cpp
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(unordered_map&&)
13 //        noexcept(is_nothrow_move_constructible<allocator_type>::value &&
14 //                 is_nothrow_move_constructible<key_compare>::value);
15
16 // This tests a conforming extension
17
18 // UNSUPPORTED: c++98, c++03
19
20 #include <unordered_map>
21 #include <cassert>
22
23 #include "test_macros.h"
24 #include "MoveOnly.h"
25 #include "test_allocator.h"
26
27 template <class T>
28 struct some_comp
29 {
30     typedef T value_type;
31     some_comp(const some_comp&);
32     bool operator()(const T&, const T&) const { return false; }
33 };
34
35 template <class T>
36 struct some_hash
37 {
38     typedef T value_type;
39     some_hash();
40     some_hash(const some_hash&);
41 };
42
43 int main()
44 {
45     {
46         typedef std::unordered_map<MoveOnly, MoveOnly> C;
47         LIBCPP_STATIC_ASSERT(std::is_nothrow_move_constructible<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         LIBCPP_STATIC_ASSERT(std::is_nothrow_move_constructible<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         LIBCPP_STATIC_ASSERT(std::is_nothrow_move_constructible<C>::value, "");
58     }
59     {
60         typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
61         static_assert(!std::is_nothrow_move_constructible<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_constructible<C>::value, "");
67     }
68 }