add erasers interface

This commit is contained in:
2019-05-04 11:19:10 +07:00
parent cd3e02093f
commit beb5d0a2c8
4 changed files with 101 additions and 8 deletions

View File

@@ -20,9 +20,9 @@ namespace flat_hpp
template < typename Key
, typename Value
, typename Compare = std::less<Key>
, typename Allocator = std::allocator<std::pair<const Key, Value>> >
, typename Allocator = std::allocator<std::pair<Key, Value>> >
class flat_map final {
using data_type = std::vector<std::pair<const Key, Value>, Allocator>;
using data_type = std::vector<std::pair<Key, Value>, Allocator>;
public:
using key_type = Key;
using mapped_type = Value;
@@ -154,8 +154,42 @@ namespace flat_hpp
//TODO(BlackMat): implme
return insert(value_type(std::forward<Args>(args)...));
}
void clear() noexcept {
data_.clear();
}
iterator erase(const_iterator iter) {
//TODO(BlackMat): implme
return end();
}
iterator erase(const_iterator first, const_iterator last) {
//TODO(BlackMat): implme
return end();
}
iterator erase(const key_type& key) {
//TODO(BlackMat): implme
return end();
}
void swap(flat_map& other) {
//TODO(BlackMat): implme
}
private:
data_type data_;
key_compare compare_;
};
template < typename Key
, typename Value
, typename Compare
, typename Allocator >
void swap(
flat_map<Key, Value, Compare, Allocator>& l,
flat_map<Key, Value, Compare, Allocator>& r)
{
l.swap(r);
}
}

View File

@@ -40,7 +40,7 @@ TEST_CASE("flat_map") {
std::is_same<map_t::mapped_type, unsigned>::value,
"unit test static error");
static_assert(
std::is_same<map_t::value_type, std::pair<const int, unsigned>>::value,
std::is_same<map_t::value_type, std::pair<int, unsigned>>::value,
"unit test static error");
static_assert(
@@ -51,22 +51,22 @@ TEST_CASE("flat_map") {
"unit test static error");
static_assert(
std::is_same<map_t::reference, std::pair<const int, unsigned>&>::value,
std::is_same<map_t::reference, std::pair<int, unsigned>&>::value,
"unit test static error");
static_assert(
std::is_same<map_t::const_reference, const std::pair<const int, unsigned>&>::value,
std::is_same<map_t::const_reference, const std::pair<int, unsigned>&>::value,
"unit test static error");
static_assert(
std::is_same<map_t::pointer, std::pair<const int, unsigned>*>::value,
std::is_same<map_t::pointer, std::pair<int, unsigned>*>::value,
"unit test static error");
static_assert(
std::is_same<map_t::const_pointer, const std::pair<const int, unsigned>*>::value,
std::is_same<map_t::const_pointer, const std::pair<int, unsigned>*>::value,
"unit test static error");
}
SECTION("ctors") {
using alloc_t = dummy_allocator<
std::pair<const int,unsigned>>;
std::pair<int,unsigned>>;
using map_t = flat_map<
int,
@@ -121,4 +121,17 @@ TEST_CASE("flat_map") {
s0.emplace_hint(s0.cend(), 6, 100500);
}
}
SECTION("erasers") {
using map_t = flat_map<int, unsigned>;
map_t s0;
s0.clear();
s0.erase(s0.begin());
s0.erase(s0.cbegin());
s0.erase(s0.begin(), s0.end());
s0.erase(s0.cbegin(), s0.cend());
s0.erase(42);
map_t s1;
s0.swap(s1);
swap(s0, s1);
}
}

View File

@@ -153,8 +153,41 @@ namespace flat_hpp
//TODO(BlackMat): implme
return insert(hint, value_type(std::forward<Args>(args)...));
}
void clear() noexcept {
data_.clear();
}
iterator erase(const_iterator iter) {
//TODO(BlackMat): implme
return end();
}
iterator erase(const_iterator first, const_iterator last) {
//TODO(BlackMat): implme
return end();
}
iterator erase(const key_type& key) {
//TODO(BlackMat): implme
return end();
}
void swap(flat_set& other) {
//TODO(BlackMat): implme
}
private:
data_type data_;
key_compare compare_;
};
template < typename Key
, typename Compare
, typename Allocator >
void swap(
flat_set<Key, Compare, Allocator>& l,
flat_set<Key, Compare, Allocator>& r)
{
l.swap(r);
}
}

View File

@@ -112,4 +112,17 @@ TEST_CASE("flat_set") {
s0.emplace_hint(s0.cend(), 100500);
}
}
SECTION("erasers") {
using set_t = flat_set<int>;
set_t s0;
s0.clear();
s0.erase(s0.begin());
s0.erase(s0.cbegin());
s0.erase(s0.begin(), s0.end());
s0.erase(s0.cbegin(), s0.cend());
s0.erase(42);
set_t s1;
s0.swap(s1);
swap(s0, s1);
}
}