erase.hpp 933 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPH_GUARD_ERASE_HPP
#define MIGRAPH_GUARD_ERASE_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
#include <algorithm>
5
#include <migraph/config.hpp>
Paul's avatar
Paul committed
6

7
8
namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
Paul's avatar
Paul committed
9

Paul's avatar
Paul committed
10
11
/**
 * @brief Erase all elements from a container
Paul's avatar
Paul committed
12
 *
Paul's avatar
Paul committed
13
14
15
16
 * @param r The container to erase elements from
 * @param value The value to be erased
 * @return Returns iterator to erased element
 */
Paul's avatar
Paul committed
17
template <class R, class T>
Paul's avatar
Paul committed
18
19
auto erase(R&& r, const T& value)
{
Paul's avatar
Paul committed
20
    return r.erase(std::remove(r.begin(), r.end(), value), r.end());
Paul's avatar
Paul committed
21
22
}

Paul's avatar
Paul committed
23
24
/**
 * @brief Erase all elements from a container
Paul's avatar
Paul committed
25
 *
Paul's avatar
Paul committed
26
27
28
29
 * @param r The container to erase elements from
 * @param pred Predicate function that selects which elements should be erased.
 * @return Returns iterator to erased element
 */
Paul's avatar
Paul committed
30
template <class R, class P>
Paul's avatar
Paul committed
31
32
auto erase_if(R&& r, P&& pred)
{
Paul's avatar
Paul committed
33
    return r.erase(std::remove_if(r.begin(), r.end(), pred), r.end());
Paul's avatar
Paul committed
34
35
}

36
} // namespace MIGRAPH_INLINE_NS
Paul's avatar
Paul committed
37
} // namespace migraph
Paul's avatar
Paul committed
38
39

#endif