brintos

brintos / llvm-project-archived public Read only

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