erase.hpp 940 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
namespace migraph { inline namespace MIGRAPH_INLINE_NS {
Paul's avatar
Paul committed
8

Paul's avatar
Paul committed
9
10
/**
 * @brief Erase all elements from a container
Paul's avatar
Paul committed
11
 *
Paul's avatar
Paul committed
12
13
14
15
 * @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
16
template <class R, class T>
Paul's avatar
Paul committed
17
18
auto erase(R&& r, const T& value)
{
Paul's avatar
Paul committed
19
    return r.erase(std::remove(r.begin(), r.end(), value), r.end());
Paul's avatar
Paul committed
20
21
}

Paul's avatar
Paul committed
22
23
/**
 * @brief Erase all elements from a container
Paul's avatar
Paul committed
24
 *
Paul's avatar
Paul committed
25
26
27
28
 * @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
29
template <class R, class P>
Paul's avatar
Paul committed
30
31
auto erase_if(R&& r, P&& pred)
{
Paul's avatar
Paul committed
32
    return r.erase(std::remove_if(r.begin(), r.end(), pred), r.end());
Paul's avatar
Paul committed
33
34
}

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

#endif