-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.hpp
56 lines (43 loc) · 1.33 KB
/
common.hpp
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
55
56
#ifndef __COMMON_H__
#define __COMMON_H__
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
std::string readFile(const std::string &fileName);
void writeFile(const std::string &fileName, const std::string &s);
std::string replaceString(std::string subject, const std::string& search,
const std::string& replace);
template<typename T>
bool compareOperator(const T &a, const T &b)
{
return a == b;
}
template<typename T, typename Comparator>
bool isVectorsAreTheSame(const std::vector<T> &a, const std::vector<T> &b, Comparator compare)
{
if(a.size() != b.size())
return false;
for(int i = 0; i < a.size(); ++i)
if(!compare(a[i], b[i]))
return false;
return true;
}
template<typename T>
bool isVectorsAreTheSame(const std::vector<T> &a, const std::vector<T> &b)
{
return isVectorsAreTheSame(a, b, &compareOperator<T>);
}
template<typename T>
inline T last(const std::vector<T> &v)
{
return v[v.size() - 1];
}
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) ;
std::vector<std::string> split(const std::string &s, char delim);
std::string getExtensionOfFileByPath(std::string);
std::string pathToFile(const std::string &s);
#ifdef __GNUG__
#define TYPEOF(x) __typeof__((x))
#endif
#endif