[libcxx] r318818 - Add some tests for operations on const associative containers. Part of LWG#2542
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 21 22:02:27 PST 2017
Author: marshall
Date: Tue Nov 21 22:02:27 2017
New Revision: 318818
URL: http://llvm.org/viewvc/llvm-project?rev=318818&view=rev
Log:
Add some tests for operations on const associative containers. Part of LWG#2542
Modified:
libcxx/trunk/test/std/containers/associative/map/map.cons/compare.pass.cpp
libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp
libcxx/trunk/test/std/containers/associative/multiset/equal_range.pass.cpp
libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp
libcxx/trunk/test/std/containers/associative/set/set.cons/compare.pass.cpp
libcxx/trunk/test/std/containers/test_compare.h
Modified: libcxx/trunk/test/std/containers/associative/map/map.cons/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/map/map.cons/compare.pass.cpp?rev=318818&r1=318817&r2=318818&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/associative/map/map.cons/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/associative/map/map.cons/compare.pass.cpp Tue Nov 21 22:02:27 2017
@@ -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));
Modified: libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp?rev=318818&r1=318817&r2=318818&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp Tue Nov 21 22:02:27 2017
@@ -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));
Modified: libcxx/trunk/test/std/containers/associative/multiset/equal_range.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/multiset/equal_range.pass.cpp?rev=318818&r1=318817&r2=318818&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/associative/multiset/equal_range.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/associative/multiset/equal_range.pass.cpp Tue Nov 21 22:02:27 2017
@@ -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));
Modified: libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp?rev=318818&r1=318817&r2=318818&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp Tue Nov 21 22:02:27 2017
@@ -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));
}
Modified: libcxx/trunk/test/std/containers/associative/set/set.cons/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/set/set.cons/compare.pass.cpp?rev=318818&r1=318817&r2=318818&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/associative/set/set.cons/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/associative/set/set.cons/compare.pass.cpp Tue Nov 21 22:02:27 2017
@@ -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));
}
Modified: libcxx/trunk/test/std/containers/test_compare.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/test_compare.h?rev=318818&r1=318817&r2=318818&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/test_compare.h (original)
+++ libcxx/trunk/test/std/containers/test_compare.h Tue Nov 21 22:02:27 2017
@@ -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
More information about the cfe-commits
mailing list