-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringutils.h
More file actions
38 lines (34 loc) · 822 Bytes
/
stringutils.h
File metadata and controls
38 lines (34 loc) · 822 Bytes
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
#include <iostream>
#include <string>
// TODO: Try this with std::string and see if it fails - use traits for type checking
template<typename T>
std::string VectorToString(const std::vector<T>& vec)
{
std::string ret = "[";
int count = vec.size();
int last = count - 1;
for(int i = 0 ; i < count ; ++i)
{
ret.append(std::to_string(vec[i]));
if(i != last)
{
ret.append(", ");
}
}
ret.append("]");
return ret;
}
std::string MapToString(const std::map<int, int>& input)
{
std::string ret = "[";
for(auto e : input)
{
ret.append("[");
ret.append(std::to_string(e.first));
ret.append(", ");
ret.append(std::to_string(e.second));
ret.append("]");
}
ret.append("]");
return ret;
}