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 #include <unordered_map> 11 #include <unordered_set> 12 #include <type_traits> 13 14 #include "test_macros.h" 15 #include "min_allocator.h" 16 #include "test_allocator.h" 17 18 19 template <class Map, class ValueTp, class PtrT, class CPtrT> 20 void testUnorderedMap() { 21 typedef typename Map::difference_type Diff; 22 { 23 typedef typename Map::iterator It; 24 static_assert((std::is_same<typename It::value_type, ValueTp>::value), ""); 25 static_assert((std::is_same<typename It::reference, ValueTp&>::value), ""); 26 static_assert((std::is_same<typename It::pointer, PtrT>::value), ""); 27 static_assert((std::is_same<typename It::difference_type, Diff>::value), ""); 28 } 29 { 30 typedef typename Map::const_iterator It; 31 static_assert((std::is_same<typename It::value_type, ValueTp>::value), ""); 32 static_assert((std::is_same<typename It::reference, ValueTp const&>::value), ""); 33 static_assert((std::is_same<typename It::pointer, CPtrT>::value), ""); 34 static_assert((std::is_same<typename It::difference_type, Diff>::value), ""); 35 } 36 { 37 typedef typename Map::local_iterator It; 38 static_assert((std::is_same<typename It::value_type, ValueTp>::value), ""); 39 static_assert((std::is_same<typename It::reference, ValueTp&>::value), ""); 40 static_assert((std::is_same<typename It::pointer, PtrT>::value), ""); 41 static_assert((std::is_same<typename It::difference_type, Diff>::value), ""); 42 } 43 { 44 typedef typename Map::const_local_iterator It; 45 static_assert((std::is_same<typename It::value_type, ValueTp>::value), ""); 46 static_assert((std::is_same<typename It::reference, ValueTp const&>::value), ""); 47 static_assert((std::is_same<typename It::pointer, CPtrT>::value), ""); 48 static_assert((std::is_same<typename It::difference_type, Diff>::value), ""); 49 } 50 } 51 52 53 template <class Set, class ValueTp, class CPtrT> 54 void testUnorderedSet() { 55 static_assert((std::is_same<typename Set::iterator, 56 typename Set::const_iterator>::value), ""); 57 static_assert((std::is_same<typename Set::local_iterator, 58 typename Set::const_local_iterator>::value), ""); 59 typedef typename Set::difference_type Diff; 60 { 61 typedef typename Set::iterator It; 62 static_assert((std::is_same<typename It::value_type, ValueTp>::value), ""); 63 static_assert((std::is_same<typename It::reference, ValueTp const&>::value), ""); 64 static_assert((std::is_same<typename It::pointer, CPtrT>::value), ""); 65 static_assert((std::is_same<typename It::difference_type, Diff>::value), ""); 66 67 } 68 { 69 typedef typename Set::local_iterator It; 70 static_assert((std::is_same<typename It::value_type, ValueTp>::value), ""); 71 static_assert((std::is_same<typename It::reference, ValueTp const&>::value), ""); 72 static_assert((std::is_same<typename It::pointer, CPtrT>::value), ""); 73 static_assert((std::is_same<typename It::difference_type, Diff>::value), ""); 74 } 75 } 76 77 int main() { 78 { 79 typedef std::unordered_map<int, int> Map; 80 typedef std::pair<const int, int> ValueTp; 81 testUnorderedMap<Map, ValueTp, ValueTp*, ValueTp const*>(); 82 } 83 { 84 typedef std::pair<const int, int> ValueTp; 85 typedef test_allocator<ValueTp> Alloc; 86 typedef std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, Alloc> Map; 87 testUnorderedMap<Map, ValueTp, ValueTp*, ValueTp const*>(); 88 } 89 #if TEST_STD_VER >= 11 90 { 91 typedef std::pair<const int, int> ValueTp; 92 typedef min_allocator<ValueTp> Alloc; 93 typedef std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, Alloc> Map; 94 testUnorderedMap<Map, ValueTp, min_pointer<ValueTp>, min_pointer<const ValueTp>>(); 95 } 96 #endif 97 { 98 typedef std::unordered_multimap<int, int> Map; 99 typedef std::pair<const int, int> ValueTp; 100 testUnorderedMap<Map, ValueTp, ValueTp*, ValueTp const*>(); 101 } 102 { 103 typedef std::pair<const int, int> ValueTp; 104 typedef test_allocator<ValueTp> Alloc; 105 typedef std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, Alloc> Map; 106 testUnorderedMap<Map, ValueTp, ValueTp*, ValueTp const*>(); 107 } 108 #if TEST_STD_VER >= 11 109 { 110 typedef std::pair<const int, int> ValueTp; 111 typedef min_allocator<ValueTp> Alloc; 112 typedef std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, Alloc> Map; 113 testUnorderedMap<Map, ValueTp, min_pointer<ValueTp>, min_pointer<const ValueTp>>(); 114 } 115 #endif 116 { 117 typedef int ValueTp; 118 typedef std::unordered_set<ValueTp> Set; 119 testUnorderedSet<Set, ValueTp, ValueTp const*>(); 120 } 121 { 122 typedef int ValueTp; 123 typedef test_allocator<ValueTp> Alloc; 124 typedef std::unordered_set<ValueTp, std::hash<ValueTp>, std::equal_to<ValueTp>, Alloc> Set; 125 testUnorderedSet<Set, ValueTp, ValueTp const*>(); 126 } 127 #if TEST_STD_VER >= 11 128 { 129 typedef int ValueTp; 130 typedef min_allocator<ValueTp> Alloc; 131 typedef std::unordered_set<ValueTp, std::hash<ValueTp>, std::equal_to<ValueTp>, Alloc> Set; 132 testUnorderedSet<Set, ValueTp, min_pointer<const ValueTp>>(); 133 } 134 #endif 135 { 136 typedef int ValueTp; 137 typedef std::unordered_multiset<ValueTp> Set; 138 testUnorderedSet<Set, ValueTp, ValueTp const*>(); 139 } 140 { 141 typedef int ValueTp; 142 typedef test_allocator<ValueTp> Alloc; 143 typedef std::unordered_multiset<ValueTp, std::hash<ValueTp>, std::equal_to<ValueTp>, Alloc> Set; 144 testUnorderedSet<Set, ValueTp, ValueTp const*>(); 145 } 146 #if TEST_STD_VER >= 11 147 { 148 typedef int ValueTp; 149 typedef min_allocator<ValueTp> Alloc; 150 typedef std::unordered_multiset<ValueTp, std::hash<ValueTp>, std::equal_to<ValueTp>, Alloc> Set; 151 testUnorderedSet<Set, ValueTp, min_pointer<const ValueTp>>(); 152 } 153 #endif 154 } 155