flat_map: add value_comp()

This commit is contained in:
Justin Viiret 2017-01-20 15:45:47 +11:00 committed by Matthew Barr
parent e37fdb240a
commit f520599ab7
2 changed files with 16 additions and 0 deletions

View File

@ -611,6 +611,21 @@ public:
return comp();
}
class value_compare {
friend class flat_map;
protected:
Compare c;
value_compare(Compare c_in) : c(c_in) {}
public:
bool operator()(const value_type &lhs, const value_type &rhs) {
return c(lhs.first, rhs.first);
}
};
value_compare value_comp() const {
return value_compare(comp());
}
// Operators.
bool operator==(const flat_map &a) const {

View File

@ -211,6 +211,7 @@ TEST(flat_map, custom_compare) {
ASSERT_EQ(10, f.rbegin()->second);
ASSERT_TRUE(flat_map_is_sorted(f));
ASSERT_TRUE(std::is_sorted(f.begin(), f.end(), f.value_comp()));
ASSERT_TRUE(flat_map_is_sorted_cmp(f, std::greater<u32>()));
}