summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2017-11-22 06:02:27 +0000
committerMarshall Clow <mclow.lists@gmail.com>2017-11-22 06:02:27 +0000
commit67e20f21d4148298622b16e6447e8e42b226671e (patch)
tree46b8970b696a3423d28f5d320453241bdad6e005 /test
parent9af08238a783f8e4f419f51a1dd483002cafd093 (diff)
Add some tests for operations on const associative containers. Part of LWG#2542
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@318818 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/std/containers/associative/map/map.cons/compare.pass.cpp6
-rw-r--r--test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp6
-rw-r--r--test/std/containers/associative/multiset/equal_range.pass.cpp4
-rw-r--r--test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp7
-rw-r--r--test/std/containers/associative/set/set.cons/compare.pass.cpp9
-rw-r--r--test/std/containers/test_compare.h9
6 files changed, 32 insertions, 9 deletions
diff --git a/test/std/containers/associative/map/map.cons/compare.pass.cpp b/test/std/containers/associative/map/map.cons/compare.pass.cpp
index 5d8d5e252..326ce74fc 100644
--- a/test/std/containers/associative/map/map.cons/compare.pass.cpp
+++ b/test/std/containers/associative/map/map.cons/compare.pass.cpp
@@ -13,6 +13,8 @@
// explicit map(const key_compare& comp);
+// key_compare key_comp() const;
+
#include <map>
#include <cassert>
@@ -23,7 +25,7 @@ int main()
{
{
typedef test_compare<std::less<int> > C;
- std::map<int, double, C> m(C(3));
+ const std::map<int, double, C> m(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
@@ -31,7 +33,7 @@ int main()
#if TEST_STD_VER >= 11
{
typedef test_compare<std::less<int> > C;
- std::map<int, double, C, min_allocator<std::pair<const int, double>>> m(C(3));
+ const std::map<int, double, C, min_allocator<std::pair<const int, double>>> m(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
diff --git a/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp
index 59a972f45..02fde1a53 100644
--- a/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp
+++ b/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp
@@ -13,6 +13,8 @@
// explicit multimap(const key_compare& comp);
+// key_compare key_comp() const;
+
#include <map>
#include <cassert>
@@ -23,7 +25,7 @@ int main()
{
{
typedef test_compare<std::less<int> > C;
- std::multimap<int, double, C> m(C(3));
+ const std::multimap<int, double, C> m(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
@@ -31,7 +33,7 @@ int main()
#if TEST_STD_VER >= 11
{
typedef test_compare<std::less<int> > C;
- std::multimap<int, double, C, min_allocator<std::pair<const int, double>>> m(C(3));
+ const std::multimap<int, double, C, min_allocator<std::pair<const int, double>>> m(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
diff --git a/test/std/containers/associative/multiset/equal_range.pass.cpp b/test/std/containers/associative/multiset/equal_range.pass.cpp
index 1a3beebcf..c9f469ba3 100644
--- a/test/std/containers/associative/multiset/equal_range.pass.cpp
+++ b/test/std/containers/associative/multiset/equal_range.pass.cpp
@@ -77,7 +77,7 @@ int main()
9,
9
};
- M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
+ const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
R r = m.equal_range(4);
assert(r.first == next(m.begin(), 0));
assert(r.second == next(m.begin(), 0));
@@ -156,7 +156,7 @@ int main()
9,
9
};
- M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
+ const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
R r = m.equal_range(4);
assert(r.first == next(m.begin(), 0));
assert(r.second == next(m.begin(), 0));
diff --git a/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp
index 84038ca1e..26ca80120 100644
--- a/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp
+++ b/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp
@@ -12,6 +12,10 @@
// class multiset
// explicit multiset(const value_compare& comp);
+// value_compare and key_compare are the same type for set/multiset
+
+// key_compare key_comp() const;
+// value_compare value_comp() const;
#include <set>
#include <cassert>
@@ -21,8 +25,9 @@
int main()
{
typedef test_compare<std::less<int> > C;
- std::multiset<int, C> m(C(3));
+ const std::multiset<int, C> m(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
+ assert(m.value_comp() == C(3));
}
diff --git a/test/std/containers/associative/set/set.cons/compare.pass.cpp b/test/std/containers/associative/set/set.cons/compare.pass.cpp
index af94c7067..0dac363ca 100644
--- a/test/std/containers/associative/set/set.cons/compare.pass.cpp
+++ b/test/std/containers/associative/set/set.cons/compare.pass.cpp
@@ -11,7 +11,11 @@
// class set
-// explicit set(const value_compare& comp);
+// explicit set(const value_compare& comp) const;
+// value_compare and key_compare are the same type for set/multiset
+
+// key_compare key_comp() const;
+// value_compare value_comp() const;
#include <set>
#include <cassert>
@@ -21,8 +25,9 @@
int main()
{
typedef test_compare<std::less<int> > C;
- std::set<int, C> m(C(3));
+ const std::set<int, C> m(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
+ assert(m.value_comp() == C(3));
}
diff --git a/test/std/containers/test_compare.h b/test/std/containers/test_compare.h
index 9c5479917..35f4640f1 100644
--- a/test/std/containers/test_compare.h
+++ b/test/std/containers/test_compare.h
@@ -33,4 +33,13 @@ public:
{return data_ == c.data_;}
};
+
+template <class C>
+class non_const_compare
+{
+// operator() deliberately not marked as 'const'
+ bool operator()(const C& x,const C&y) { return x < y; }
+};
+
+
#endif // TEST_COMPARE_H