1#ifndef MSTL_CORE_ALGORITHM_REMOVE_HPP__
2#define MSTL_CORE_ALGORITHM_REMOVE_HPP__
38template <
typename Iterator1,
typename Iterator2,
typename T,
40constexpr Iterator2
remove_copy(Iterator1 first, Iterator1 last, Iterator2 result,
const T& value) {
41 for (; first != last; ++first) {
42 if (*first != value) {
64template <
typename Iterator1,
typename Iterator2,
typename Predicate,
66constexpr Iterator2
remove_copy_if(Iterator1 first, Iterator1 last, Iterator2 result, Predicate pred) {
67 for (; first != last; ++first) {
91template <
typename Iterator,
typename T, enable_if_t<is_ranges_fwd_iter_v<Iterator>,
int> = 0>
92constexpr Iterator
remove(Iterator first, Iterator last,
const T& value) {
94 Iterator
next = first;
113template <
typename Iterator,
typename Predicate, enable_if_t<is_ranges_fwd_iter_v<Iterator>,
int> = 0>
114constexpr Iterator
remove_if(Iterator first, Iterator last, Predicate pred) {
116 Iterator
next = first;
134template <
typename Container,
typename U>
135constexpr size_t erase(Container& cont,
const U& value) {
136 using T =
decltype(*cont.begin());
139 "U must be comparable to the value type of Container");
141 const auto old_size = cont.size();
142 const auto end = cont.end();
144 [&value](
const auto& iter) {
145 return *iter == value;
147 cont.erase(removed,
end);
148 return old_size - cont.size();
165template <
typename Container,
typename Predicate>
166constexpr size_t erase_if(Container& cont, Predicate pred) {
167 const size_t old_size = cont.size();
168 const auto end = cont.end();
170 [ref_pred =
_MSTL ref(pred)](
const auto& iter) {
171 return ref_pred(*iter);
173 cont.erase(removed,
end);
174 return old_size - cont.size();
MSTL_NODISCARD constexpr Iterator find(Iterator first, Iterator last, const T &value)
查找范围内第一个等于指定值的元素
constexpr Iterator find_if(Iterator first, Iterator last, Predicate pred)
查找范围内第一个满足谓词的元素
MSTL_INLINE17 constexpr bool is_ranges_fwd_iter_v
检查是否为范围前向迭代器
constexpr Iterator next(Iterator iter, iter_difference_t< Iterator > n=1)
获取迭代器的后一个位置
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD constexpr reference_wrapper< T > ref(T &val) noexcept
创建引用包装器
constexpr Iterator2 remove_copy(Iterator1 first, Iterator1 last, Iterator2 result, const T &value)
复制范围中不等于指定值的元素
constexpr Iterator remove_if(Iterator first, Iterator last, Predicate pred)
移除范围中满足谓词的元素
constexpr Iterator2 remove_copy_if(Iterator1 first, Iterator1 last, Iterator2 result, Predicate pred)
复制范围中不满足谓词的元素
constexpr size_t erase_if(Container &cont, Predicate pred)
从容器中删除所有满足谓词的元素
constexpr Iterator remove(Iterator first, Iterator last, const T &value)
移除范围中等于指定值的元素
constexpr size_t erase(Container &cont, const U &value)
从容器中删除所有等于指定值的元素
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) end(Container &cont) noexcept(noexcept(cont.end()))
获取容器的结束迭代器
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名