-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathalgorithm.hpp
More file actions
54 lines (40 loc) · 1.36 KB
/
algorithm.hpp
File metadata and controls
54 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#ifndef __CPPM_UTIL_ALGORITHM_HPP__
#define __CPPM_UTIL_ALGORITHM_HPP__
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <range/v3/all.hpp>
using namespace ranges;
namespace cppm::util
{
template<typename Collection>
void insert(Collection& src, Collection& des) {
src.insert(src.end(), des.begin(), des.end());
}
template<typename Collection, typename Func>
void for_each(Collection& col, Func func) {
std::for_each(col.begin(), col.end(), func);
}
template<typename Collection>
std::string accumulate(Collection stl, std::string token="") {
return ranges::accumulate(stl, std::string{},
[&token](auto& str, const auto& piece) { return str += (token + piece);});
}
namespace str
{
std::string erase(const std::string& target_str, const std::string& erase_str);
}
// -------------------------------------------------------------------
// --- Reversed iterable
template <typename T>
struct reversion_wrapper { T& iterable; };
template <typename T>
auto begin (reversion_wrapper<T> w) { return rbegin(w.iterable); }
template <typename T>
auto end (reversion_wrapper<T> w) { return rend(w.iterable); }
template <typename T>
reversion_wrapper<T> reverse (T&& iterable) { return { iterable }; }
}
#endif