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

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

Paul's avatar
Paul committed
7
namespace migraphx {
Paul's avatar
Paul committed
8
inline namespace MIGRAPHX_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
}

Paul's avatar
Paul committed
36
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
37
} // namespace migraphx
Paul's avatar
Paul committed
38
39

#endif