From 67e20f21d4148298622b16e6447e8e42b226671e Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 22 Nov 2017 06:02:27 +0000 Subject: 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 --- test/std/containers/associative/map/map.cons/compare.pass.cpp | 6 ++++-- .../associative/multimap/multimap.cons/compare.pass.cpp | 6 ++++-- test/std/containers/associative/multiset/equal_range.pass.cpp | 4 ++-- .../associative/multiset/multiset.cons/compare.pass.cpp | 7 ++++++- test/std/containers/associative/set/set.cons/compare.pass.cpp | 9 +++++++-- test/std/containers/test_compare.h | 9 +++++++++ 6 files changed, 32 insertions(+), 9 deletions(-) (limited to 'test') 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 #include @@ -23,7 +25,7 @@ int main() { { typedef test_compare > C; - std::map m(C(3)); + const std::map 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 > C; - std::map>> m(C(3)); + const std::map>> 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 #include @@ -23,7 +25,7 @@ int main() { { typedef test_compare > C; - std::multimap m(C(3)); + const std::multimap 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 > C; - std::multimap>> m(C(3)); + const std::multimap>> 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 #include @@ -21,8 +25,9 @@ int main() { typedef test_compare > C; - std::multiset m(C(3)); + const std::multiset 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 #include @@ -21,8 +25,9 @@ int main() { typedef test_compare > C; - std::set m(C(3)); + const std::set 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 non_const_compare +{ +// operator() deliberately not marked as 'const' + bool operator()(const C& x,const C&y) { return x < y; } +}; + + #endif // TEST_COMPARE_H -- cgit v1.2.3