Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/beman/inplace_vector/inplace_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,22 @@ struct inplace_vector : private __iv_detail::__storage::_t<__T, __N> {
}
};

template <typename T, std::size_t N, typename U = T>
constexpr std::size_t erase(inplace_vector<T, N> &c, const U &value) {
auto it = std::remove(c.begin(), c.end(), value);
auto r = std::distance(it, c.end());
c.erase(it, c.end());
return r;
}

template <typename T, std::size_t N, typename Predicate>
constexpr std::size_t erase_if(inplace_vector<T, N> &c, Predicate pred) {
auto it = std::remove_if(c.begin(), c.end(), pred);
auto r = std::distance(it, c.end());
c.erase(it, c.end());
return r;
}

} // namespace beman

// undefine all the internal macros
Expand Down
19 changes: 8 additions & 11 deletions tests/beman/inplace_vector/erasure.test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <gtest/gtest.h>

#include "gtest_setup.hpp"
Expand Down Expand Up @@ -34,11 +35,8 @@ TYPED_TEST(Erasure, ByValue) {
device.push_back(duplicates);
}

// TODO: uncomment this after erase is implemented
// beman::erase(device, duplicates);
// EXPECT_EQ(uniques, device);

GTEST_SKIP() << "Not implemented";
beman::erase(device, duplicates);
EXPECT_EQ(uniques, device);
}

TYPED_TEST(Erasure, ByPred) {
Expand All @@ -61,11 +59,10 @@ TYPED_TEST(Erasure, ByPred) {
for (auto i = 0; i < static_cast<int>(device.capacity()); ++i)
device.push_back(T{i});

// TODO: complete this when its implemented
// beman::erase_if(device,
// [&](auto &v) { return v.value > (device.capacity() / 2);
// });

GTEST_SKIP() << "Not implemented";
beman::erase_if(device,
[&](auto &v) { return v.value > (device.capacity() / 2); });
EXPECT_TRUE(std::all_of(device.begin(), device.end(), [&](auto val) {
return val.value <= (device.capacity() / 2);
}));
}
}; // namespace