17 #ifndef UTIL_ALGORITHM_H
18 #define UTIL_ALGORITHM_H
26 template <
typename InputIt,
typename OutputIt,
typename F>
27 auto extract_if(InputIt begin, InputIt end, OutputIt d_begin, F func)
29 begin = std::find_if(begin, end, func);
30 for (
auto i = begin; i != end; ++i) {
32 *d_begin++ = std::move(*i);
34 *begin++ = std::move(*i);
36 return std::pair{begin, d_begin};
39 template <
typename R,
typename Output,
typename F,
typename G>
40 long int transform_while_n(R& queue, Output out,
long int sz, F&& test_func, G&& transform_func)
42 auto [begin, end] =
champsim::get_span_p(std::begin(queue), std::end(queue), sz, std::forward<F>(test_func));
43 auto retval = std::distance(begin, end);
44 std::transform(begin, end, out, std::forward<G>(transform_func));
45 queue.erase(begin, end);
Definition: champsim.h:24
auto extract_if(InputIt begin, InputIt end, OutputIt d_begin, F func)
Definition: algorithm.h:27
std::pair< It, It > get_span_p(It begin, It end, typename std::iterator_traits< It >::difference_type sz, F &&func)
Definition: span.h:37
long int transform_while_n(R &queue, Output out, long int sz, F &&test_func, G &&transform_func)
Definition: algorithm.h:40