summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/containers
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-02-20 05:28:30 +0000
committerEric Fiselier <eric@efcs.ca>2016-02-20 05:28:30 +0000
commit089a7cc5dea665f4088ed6b587e2f6ea058d7581 (patch)
tree31f84aed9c61ccae7c04658cf8622e907b69d0d7 /libcxx/test/std/containers
parent74caaf27d8ea8f82f6020d51a2df7d92a3b558e7 (diff)
downloadbcm5719-llvm-089a7cc5dea665f4088ed6b587e2f6ea058d7581.tar.gz
bcm5719-llvm-089a7cc5dea665f4088ed6b587e2f6ea058d7581.zip
Cleanup node-type handling in the associative containers.
This patch is very similar to r260431. This patch is the first in a series of patches that's meant to better support map. map has a special "value_type" that differs from pair<const Key, Value>. In order to meet the EmplaceConstructible and CopyInsertable requirements we need to teach __tree about this special value_type. This patch creates a "__tree_node_types" traits class that contains all of the typedefs needed by the associative containers and their iterators. These typedefs include ones for each node type and node pointer type, as well as special typedefs for "map"'s value type. Although the associative containers already supported incomplete types, this patch makes it official by adding tests. This patch will be followed up shortly with various cleanups within __tree and fixes for various map bugs and problems. llvm-svn: 261416
Diffstat (limited to 'libcxx/test/std/containers')
-rw-r--r--libcxx/test/std/containers/associative/iterator_types.pass.cpp131
-rw-r--r--libcxx/test/std/containers/associative/map/incomplete_type.pass.cpp29
-rw-r--r--libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp29
-rw-r--r--libcxx/test/std/containers/associative/multiset/incomplete_type.pass.cpp29
-rw-r--r--libcxx/test/std/containers/associative/set/incomplete_type.pass.cpp29
5 files changed, 247 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/associative/iterator_types.pass.cpp b/libcxx/test/std/containers/associative/iterator_types.pass.cpp
new file mode 100644
index 00000000000..2026219d86c
--- /dev/null
+++ b/libcxx/test/std/containers/associative/iterator_types.pass.cpp
@@ -0,0 +1,131 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <map>
+#include <set>
+#include <type_traits>
+
+#include "test_macros.h"
+#include "min_allocator.h"
+#include "test_allocator.h"
+
+
+template <class Map, class ValueTp, class PtrT, class CPtrT>
+void testMap() {
+ typedef typename Map::difference_type Diff;
+ {
+ typedef typename Map::iterator It;
+ static_assert((std::is_same<typename It::value_type, ValueTp>::value), "");
+ static_assert((std::is_same<typename It::reference, ValueTp&>::value), "");
+ static_assert((std::is_same<typename It::pointer, PtrT>::value), "");
+ static_assert((std::is_same<typename It::difference_type, Diff>::value), "");
+ }
+ {
+ typedef typename Map::const_iterator It;
+ static_assert((std::is_same<typename It::value_type, ValueTp>::value), "");
+ static_assert((std::is_same<typename It::reference, ValueTp const&>::value), "");
+ static_assert((std::is_same<typename It::pointer, CPtrT>::value), "");
+ static_assert((std::is_same<typename It::difference_type, Diff>::value), "");
+ }
+}
+
+
+template <class Set, class ValueTp, class CPtrT>
+void testSet() {
+ static_assert((std::is_same<typename Set::iterator,
+ typename Set::const_iterator>::value), "");
+ typedef typename Set::difference_type Diff;
+ {
+ typedef typename Set::iterator It;
+ static_assert((std::is_same<typename It::value_type, ValueTp>::value), "");
+ static_assert((std::is_same<typename It::reference, ValueTp const&>::value), "");
+ static_assert((std::is_same<typename It::pointer, CPtrT>::value), "");
+ static_assert((std::is_same<typename It::difference_type, Diff>::value), "");
+
+ }
+}
+
+int main() {
+ {
+ typedef std::map<int, int> Map;
+ typedef std::pair<const int, int> ValueTp;
+ testMap<Map, ValueTp, ValueTp*, ValueTp const*>();
+ }
+ {
+ typedef std::pair<const int, int> ValueTp;
+ typedef test_allocator<ValueTp> Alloc;
+ typedef std::map<int, int, std::less<int>, Alloc> Map;
+ testMap<Map, ValueTp, ValueTp*, ValueTp const*>();
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef std::pair<const int, int> ValueTp;
+ typedef min_allocator<ValueTp> Alloc;
+ typedef std::map<int, int, std::less<int>, Alloc> Map;
+ testMap<Map, ValueTp, min_pointer<ValueTp>, min_pointer<const ValueTp>>();
+ }
+#endif
+ {
+ typedef std::multimap<int, int> Map;
+ typedef std::pair<const int, int> ValueTp;
+ testMap<Map, ValueTp, ValueTp*, ValueTp const*>();
+ }
+ {
+ typedef std::pair<const int, int> ValueTp;
+ typedef test_allocator<ValueTp> Alloc;
+ typedef std::multimap<int, int, std::less<int>, Alloc> Map;
+ testMap<Map, ValueTp, ValueTp*, ValueTp const*>();
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef std::pair<const int, int> ValueTp;
+ typedef min_allocator<ValueTp> Alloc;
+ typedef std::multimap<int, int, std::less<int>, Alloc> Map;
+ testMap<Map, ValueTp, min_pointer<ValueTp>, min_pointer<const ValueTp>>();
+ }
+#endif
+ {
+ typedef int ValueTp;
+ typedef std::set<ValueTp> Set;
+ testSet<Set, ValueTp, ValueTp const*>();
+ }
+ {
+ typedef int ValueTp;
+ typedef test_allocator<ValueTp> Alloc;
+ typedef std::set<ValueTp, std::less<ValueTp>, Alloc> Set;
+ testSet<Set, ValueTp, ValueTp const*>();
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef int ValueTp;
+ typedef min_allocator<ValueTp> Alloc;
+ typedef std::set<ValueTp, std::less<ValueTp>, Alloc> Set;
+ testSet<Set, ValueTp, min_pointer<const ValueTp>>();
+ }
+#endif
+ {
+ typedef int ValueTp;
+ typedef std::multiset<ValueTp> Set;
+ testSet<Set, ValueTp, ValueTp const*>();
+ }
+ {
+ typedef int ValueTp;
+ typedef test_allocator<ValueTp> Alloc;
+ typedef std::multiset<ValueTp, std::less<ValueTp>, Alloc> Set;
+ testSet<Set, ValueTp, ValueTp const*>();
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef int ValueTp;
+ typedef min_allocator<ValueTp> Alloc;
+ typedef std::multiset<ValueTp, std::less<ValueTp>, Alloc> Set;
+ testSet<Set, ValueTp, min_pointer<const ValueTp>>();
+ }
+#endif
+}
diff --git a/libcxx/test/std/containers/associative/map/incomplete_type.pass.cpp b/libcxx/test/std/containers/associative/map/incomplete_type.pass.cpp
new file mode 100644
index 00000000000..84c2451ce08
--- /dev/null
+++ b/libcxx/test/std/containers/associative/map/incomplete_type.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// Check that std::map and it's iterators can be instantiated with an incomplete
+// type.
+
+#include <map>
+
+struct A {
+ typedef std::map<A, A> Map;
+ int data;
+ Map m;
+ Map::iterator it;
+ Map::const_iterator cit;
+};
+
+inline bool operator==(A const& L, A const& R) { return &L == &R; }
+inline bool operator<(A const& L, A const& R) { return L.data < R.data; }
+int main() {
+ A a;
+}
diff --git a/libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp b/libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp
new file mode 100644
index 00000000000..c461eb38139
--- /dev/null
+++ b/libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// Check that std::multimap and it's iterators can be instantiated with an incomplete
+// type.
+
+#include <map>
+
+struct A {
+ typedef std::multimap<A, A> Map;
+ int data;
+ Map m;
+ Map::iterator it;
+ Map::const_iterator cit;
+};
+
+inline bool operator==(A const& L, A const& R) { return &L == &R; }
+inline bool operator<(A const& L, A const& R) { return L.data < R.data; }
+int main() {
+ A a;
+}
diff --git a/libcxx/test/std/containers/associative/multiset/incomplete_type.pass.cpp b/libcxx/test/std/containers/associative/multiset/incomplete_type.pass.cpp
new file mode 100644
index 00000000000..0355e18f9f2
--- /dev/null
+++ b/libcxx/test/std/containers/associative/multiset/incomplete_type.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+
+// Check that std::multiset and it's iterators can be instantiated with an incomplete
+// type.
+
+#include <set>
+
+struct A {
+ typedef std::multiset<A> Set;
+ int data;
+ Set m;
+ Set::iterator it;
+ Set::const_iterator cit;
+};
+
+inline bool operator==(A const& L, A const& R) { return &L == &R; }
+inline bool operator<(A const& L, A const& R) { return L.data < R.data; }
+int main() {
+ A a;
+}
diff --git a/libcxx/test/std/containers/associative/set/incomplete_type.pass.cpp b/libcxx/test/std/containers/associative/set/incomplete_type.pass.cpp
new file mode 100644
index 00000000000..d3a1d6638d7
--- /dev/null
+++ b/libcxx/test/std/containers/associative/set/incomplete_type.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+
+// Check that std::set and it's iterators can be instantiated with an incomplete
+// type.
+
+#include <set>
+
+struct A {
+ typedef std::set<A> Set;
+ int data;
+ Set m;
+ Set::iterator it;
+ Set::const_iterator cit;
+};
+
+inline bool operator==(A const& L, A const& R) { return &L == &R; }
+inline bool operator<(A const& L, A const& R) { return L.data < R.data; }
+int main() {
+ A a;
+}
OpenPOWER on IntegriCloud