mirror of
https://github.com/BlackMATov/flat.hpp.git
synced 2025-12-13 01:36:27 +07:00
add observers interface
This commit is contained in:
21
flat_map.hpp
21
flat_map.hpp
@@ -44,6 +44,19 @@ namespace flat_hpp
|
||||
using reverse_iterator = typename data_type::reverse_iterator;
|
||||
using const_reverse_iterator = typename data_type::const_reverse_iterator;
|
||||
|
||||
class value_compare final : public std::binary_function<value_type, value_type, bool> {
|
||||
public:
|
||||
bool operator()(const value_type& l, const value_type& r) const {
|
||||
return compare_(l.first, r.first);
|
||||
}
|
||||
private:
|
||||
friend class flat_map;
|
||||
explicit value_compare(const key_compare& compare)
|
||||
: compare_(compare) {}
|
||||
private:
|
||||
key_compare compare_;
|
||||
};
|
||||
|
||||
static_assert(
|
||||
std::is_same<typename allocator_type::value_type, value_type>::value,
|
||||
"Allocator::value_type must be same type as value_type");
|
||||
@@ -222,6 +235,14 @@ namespace flat_hpp
|
||||
//TODO(BlackMat): implme
|
||||
return end();
|
||||
}
|
||||
|
||||
key_compare key_comp() const {
|
||||
return compare_;
|
||||
}
|
||||
|
||||
value_compare value_comp() const {
|
||||
return value_compare(compare_);
|
||||
}
|
||||
private:
|
||||
data_type data_;
|
||||
key_compare compare_;
|
||||
|
||||
@@ -152,4 +152,10 @@ TEST_CASE("flat_map") {
|
||||
s0.upper_bound(30);
|
||||
my_as_const(s0).upper_bound(30);
|
||||
}
|
||||
SECTION("observers") {
|
||||
using map_t = flat_map<int, unsigned>;
|
||||
map_t s0;
|
||||
my_as_const(s0).key_comp();
|
||||
my_as_const(s0).value_comp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +221,14 @@ namespace flat_hpp
|
||||
//TODO(BlackMat): implme
|
||||
return end();
|
||||
}
|
||||
|
||||
key_compare key_comp() const {
|
||||
return compare_;
|
||||
}
|
||||
|
||||
value_compare value_comp() const {
|
||||
return value_compare(compare_);
|
||||
}
|
||||
private:
|
||||
data_type data_;
|
||||
key_compare compare_;
|
||||
|
||||
@@ -143,4 +143,10 @@ TEST_CASE("flat_set") {
|
||||
s0.upper_bound(30);
|
||||
my_as_const(s0).upper_bound(30);
|
||||
}
|
||||
SECTION("observers") {
|
||||
using set_t = flat_set<int>;
|
||||
set_t s0;
|
||||
my_as_const(s0).key_comp();
|
||||
my_as_const(s0).value_comp();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user