mirror of
https://github.com/BlackMATov/flat.hpp.git
synced 2025-12-13 09:45:38 +07:00
add operators interface
This commit is contained in:
44
flat_map.hpp
44
flat_map.hpp
@@ -247,15 +247,43 @@ namespace flat_hpp
|
|||||||
data_type data_;
|
data_type data_;
|
||||||
key_compare compare_;
|
key_compare compare_;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
template < typename Key
|
namespace flat_hpp
|
||||||
, typename Value
|
{
|
||||||
, typename Compare
|
template < typename K, typename V, typename C, typename A >
|
||||||
, typename Allocator >
|
void swap(flat_map<K, V, C, A>& l, flat_map<K, V, C, A>& r) {
|
||||||
void swap(
|
|
||||||
flat_map<Key, Value, Compare, Allocator>& l,
|
|
||||||
flat_map<Key, Value, Compare, Allocator>& r)
|
|
||||||
{
|
|
||||||
l.swap(r);
|
l.swap(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename K, typename V, typename C, typename A >
|
||||||
|
bool operator==(const flat_map<K, V, C, A>& l, const flat_map<K, V, C, A>& r) {
|
||||||
|
return l.size() == r.size()
|
||||||
|
&& std::equal(l.begin(), l.end(), r.begin(), r.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename V, typename C, typename A >
|
||||||
|
bool operator!=(const flat_map<K, V, C, A>& l, const flat_map<K, V, C, A>& r) {
|
||||||
|
return !(l == r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename V, typename C, typename A >
|
||||||
|
bool operator<(const flat_map<K, V, C, A>& l, const flat_map<K, V, C, A>& r) {
|
||||||
|
return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename V, typename C, typename A >
|
||||||
|
bool operator>(const flat_map<K, V, C, A>& l, const flat_map<K, V, C, A>& r) {
|
||||||
|
return r < l;
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename V, typename C, typename A >
|
||||||
|
bool operator<=(const flat_map<K, V, C, A>& l, const flat_map<K, V, C, A>& r) {
|
||||||
|
return !(r < l);
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename V, typename C, typename A >
|
||||||
|
bool operator>=(const flat_map<K, V, C, A>& l, const flat_map<K, V, C, A>& r) {
|
||||||
|
return !(l < r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,4 +158,15 @@ TEST_CASE("flat_map") {
|
|||||||
my_as_const(s0).key_comp();
|
my_as_const(s0).key_comp();
|
||||||
my_as_const(s0).value_comp();
|
my_as_const(s0).value_comp();
|
||||||
}
|
}
|
||||||
|
SECTION("operators") {
|
||||||
|
using map_t = flat_map<int, unsigned>;
|
||||||
|
map_t s0;
|
||||||
|
map_t s1;
|
||||||
|
REQUIRE(s0 == s1);
|
||||||
|
REQUIRE_FALSE(s0 != s1);
|
||||||
|
REQUIRE_FALSE(s0 < s1);
|
||||||
|
REQUIRE_FALSE(s0 > s1);
|
||||||
|
REQUIRE(s0 <= s1);
|
||||||
|
REQUIRE(s0 >= s1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
43
flat_set.hpp
43
flat_set.hpp
@@ -233,14 +233,43 @@ namespace flat_hpp
|
|||||||
data_type data_;
|
data_type data_;
|
||||||
key_compare compare_;
|
key_compare compare_;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
template < typename Key
|
namespace flat_hpp
|
||||||
, typename Compare
|
{
|
||||||
, typename Allocator >
|
template < typename K, typename C, typename A >
|
||||||
void swap(
|
void swap(flat_set<K, C, A>& l, flat_set<K, C, A>& r) {
|
||||||
flat_set<Key, Compare, Allocator>& l,
|
|
||||||
flat_set<Key, Compare, Allocator>& r)
|
|
||||||
{
|
|
||||||
l.swap(r);
|
l.swap(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename K, typename C, typename A >
|
||||||
|
bool operator==(const flat_set<K, C, A>& l, const flat_set<K, C, A>& r) {
|
||||||
|
return l.size() == r.size()
|
||||||
|
&& std::equal(l.begin(), l.end(), r.begin(), r.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename C, typename A >
|
||||||
|
bool operator!=(const flat_set<K, C, A>& l, const flat_set<K, C, A>& r) {
|
||||||
|
return !(l == r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename C, typename A >
|
||||||
|
bool operator<(const flat_set<K, C, A>& l, const flat_set<K, C, A>& r) {
|
||||||
|
return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename C, typename A >
|
||||||
|
bool operator>(const flat_set<K, C, A>& l, const flat_set<K, C, A>& r) {
|
||||||
|
return r < l;
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename C, typename A >
|
||||||
|
bool operator<=(const flat_set<K, C, A>& l, const flat_set<K, C, A>& r) {
|
||||||
|
return !(r < l);
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename K, typename C, typename A >
|
||||||
|
bool operator>=(const flat_set<K, C, A>& l, const flat_set<K, C, A>& r) {
|
||||||
|
return !(l < r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,4 +149,15 @@ TEST_CASE("flat_set") {
|
|||||||
my_as_const(s0).key_comp();
|
my_as_const(s0).key_comp();
|
||||||
my_as_const(s0).value_comp();
|
my_as_const(s0).value_comp();
|
||||||
}
|
}
|
||||||
|
SECTION("operators") {
|
||||||
|
using set_t = flat_set<int>;
|
||||||
|
set_t s0;
|
||||||
|
set_t s1;
|
||||||
|
REQUIRE(s0 == s1);
|
||||||
|
REQUIRE_FALSE(s0 != s1);
|
||||||
|
REQUIRE_FALSE(s0 < s1);
|
||||||
|
REQUIRE_FALSE(s0 > s1);
|
||||||
|
REQUIRE(s0 <= s1);
|
||||||
|
REQUIRE(s0 >= s1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user