1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include "test_macros.h"
#include "min_allocator.h"
using namespace std;
// [container.node.overview] Table 83.
template <class K, class T, class C1, class C2, class H1, class H2, class E1, class E2, class A_set, class A_map>
struct node_compatibility_table
{
static constexpr bool value =
is_same_v<typename map<K, T, C1, A_map>::node_type, typename map<K, T, C2, A_map>::node_type> &&
is_same_v<typename map<K, T, C1, A_map>::node_type, typename multimap<K, T, C2, A_map>::node_type> &&
is_same_v<typename set<K, C1, A_set>::node_type, typename set<K, C2, A_set>::node_type> &&
is_same_v<typename set<K, C1, A_set>::node_type, typename multiset<K, C2, A_set>::node_type> &&
is_same_v<typename unordered_map<K, T, H1, E1, A_map>::node_type, typename unordered_map<K, T, H2, E2, A_map>::node_type> &&
is_same_v<typename unordered_map<K, T, H1, E1, A_map>::node_type, typename unordered_multimap<K, T, H2, E2, A_map>::node_type> &&
is_same_v<typename unordered_set<K, H1, E1, A_set>::node_type, typename unordered_set<K, H2, E2, A_set>::node_type> &&
is_same_v<typename unordered_set<K, H1, E1, A_set>::node_type, typename unordered_multiset<K, H2, E2, A_set>::node_type>;
};
template <class T> struct my_hash
{
using argument_type = T;
using result_type = size_t;
my_hash() = default;
size_t operator()(const T&) const {return 0;}
};
template <class T> struct my_compare
{
my_compare() = default;
bool operator()(const T&, const T&) const {return true;}
};
template <class T> struct my_equal
{
my_equal() = default;
bool operator()(const T&, const T&) const {return true;}
};
struct Static
{
Static() = default;
Static(const Static&) = delete;
Static(Static&&) = delete;
Static& operator=(const Static&) = delete;
Static& operator=(Static&&) = delete;
};
namespace std
{
template <> struct hash<Static>
{
using argument_type = Static;
using result_type = size_t;
hash() = default;
size_t operator()(const Static&) const;
};
}
static_assert(node_compatibility_table<
int, int, std::less<int>, std::less<int>, std::hash<int>,
std::hash<int>, std::equal_to<int>, std::equal_to<int>,
std::allocator<int>,
std::allocator<std::pair<const int, int>>>::value,
"");
static_assert(
node_compatibility_table<int, int, std::less<int>, my_compare<int>,
std::hash<int>, my_hash<int>, std::equal_to<int>,
my_equal<int>, allocator<int>,
allocator<std::pair<const int, int>>>::value,
"");
static_assert(node_compatibility_table<
Static, int, my_compare<Static>, std::less<Static>,
my_hash<Static>, std::hash<Static>, my_equal<Static>,
std::equal_to<Static>, min_allocator<Static>,
min_allocator<std::pair<const Static, int>>>::value,
"");
template <class Container>
void test_node_handle_operations()
{
Container c;
typename Container::node_type nt1, nt2 = c.extract(c.emplace().first);
assert(nt2.get_allocator() == c.get_allocator());
assert(!nt2.empty());
assert(nt1.empty());
std::swap(nt1, nt2);
assert(nt1.get_allocator() == c.get_allocator());
assert(nt2.empty());
}
template <class Container>
void test_node_handle_operations_multi()
{
Container c;
typename Container::node_type nt1, nt2 = c.extract(c.emplace());
assert(nt2.get_allocator() == c.get_allocator());
assert(!nt2.empty());
assert(nt1.empty());
std::swap(nt1, nt2);
assert(nt1.get_allocator() == c.get_allocator());
assert(nt2.empty());
}
template <class> void test_typedef() {}
template <class Container>
void test_insert_return_type()
{
test_typedef<typename Container::insert_return_type>();
}
int main(int, char**)
{
test_node_handle_operations<std::map<int, int>>();
test_node_handle_operations_multi<std::multimap<int, int>>();
test_node_handle_operations<std::set<int>>();
test_node_handle_operations_multi<std::multiset<int>>();
test_node_handle_operations<std::unordered_map<int, int>>();
test_node_handle_operations_multi<std::unordered_multimap<int, int>>();
test_node_handle_operations<std::unordered_set<int>>();
test_node_handle_operations_multi<std::unordered_multiset<int>>();
test_insert_return_type<std::map<int, int>>();
test_insert_return_type<std::set<int>>();
test_insert_return_type<std::unordered_map<int, int>>();
test_insert_return_type<std::unordered_set<int>>();
return 0;
}
|