default_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()
13//    noexcept(
14//        is_nothrow_default_constructible<allocator_type>::value &&
15//        is_nothrow_default_constructible<key_compare>::value &&
16//        is_nothrow_copy_constructible<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#include "../../../test_hash.h"
26
27template <class T>
28struct some_comp
29{
30    typedef T value_type;
31    some_comp();
32    some_comp(const some_comp&);
33};
34
35template <class T>
36struct some_hash
37{
38    typedef T value_type;
39    some_hash();
40    some_hash(const some_hash&);
41};
42
43int main()
44{
45#if __has_feature(cxx_noexcept)
46    {
47        typedef std::unordered_map<MoveOnly, MoveOnly> C;
48        static_assert(std::is_nothrow_default_constructible<C>::value, "");
49    }
50    {
51        typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
52                           std::equal_to<MoveOnly>, test_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
53        static_assert(std::is_nothrow_default_constructible<C>::value, "");
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        static_assert(!std::is_nothrow_default_constructible<C>::value, "");
59    }
60    {
61        typedef std::unordered_map<MoveOnly, MoveOnly, some_hash<MoveOnly>> C;
62        static_assert(!std::is_nothrow_default_constructible<C>::value, "");
63    }
64    {
65        typedef std::unordered_map<MoveOnly, MoveOnly, std::hash<MoveOnly>,
66                                                         some_comp<MoveOnly>> C;
67        static_assert(!std::is_nothrow_default_constructible<C>::value, "");
68    }
69#endif
70}
71