// explicit map(const key_compare& comp);
+// key_compare key_comp() const;
+
#include <map>
#include <cassert>
{
{
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));
#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));
// explicit multimap(const key_compare& comp);
+// key_compare key_comp() const;
+
#include <map>
#include <cassert>
{
{
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));
#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));
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));
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));
// 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>
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));
}
// 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>
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));
}
{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