-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin.cpp
More file actions
93 lines (82 loc) · 3.05 KB
/
Copy pathjoin.cpp
File metadata and controls
93 lines (82 loc) · 3.05 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "join.h"
std::string pyfunc::join(std::string source, std::string join_by) {
std::string joined_str = "";
for (size_t index = 0; index < source.length() - 1; index++) {
joined_str += source[index];
joined_str += join_by;
}
joined_str += source[source.length() - 1];
return joined_str;
}
std::string pyfunc::join(std::string source, char join_by) {
std::string join_by_ = (std::string)"" + join_by;
return pyfunc::join(source, join_by_);
}
template<typename T>
std::string pyfunc::join(std::vector<T> source, std::string join_by) {
//bool string_convert = false;
std::string joined_str = "";
/*if (std::is_same<T,int>::value || std::is_same<T,long>::value || std::is_same<T,long long>::value ||
std::is_same<T,unsigned int>::value || std::is_same<T,unsigned long>::value ||std::is_same<T,unsigned long long>::value ||
std::is_same<T,float>::value|| std::is_same<T,double>::value || std::is_same<T,long double>::value ){
string_convert = true;
}*/
for (size_t index = 0; index < source.size() - 1; index++) {
//if (string_convert) joined_str += std::to_string(source[index]);
joined_str += source[index];
joined_str += join_by;
}
//if (string_convert) joined_str += std::to_string(source[source.size()-1]);
joined_str += source[source.size() - 1];
return joined_str;
}
template<typename T>
std::string pyfunc::join(std::vector<T> source, char join_by) {
std::string join_by_ = (std::string)"" + join_by;
return pyfunc::join(source, join_by_);
}
template<typename T, size_t size>
std::string pyfunc::join(std::array<T, size> source, std::string join_by) {
std::string joined_str = "";
for (size_t index = 0; index < size - 1; index++) {
joined_str += source[index];
joined_str += join_by;
}
joined_str += source[size - 1];
return joined_str;
}
template<typename T, size_t size>
std::string pyfunc::join(std::array<T, size> source, char join_by) {
std::string join_by_ = (std::string)"" + join_by;
return pyfunc::join(source, join_by_);
}
template<typename T>
std::string pyfunc::join(T* source, size_t size, std::string join_by) {
std::string joined_str = "";
for (int index = 0; index < size - 1; index++) {
joined_str += *source++;
joined_str += join_by;
}
joined_str += *source;
return joined_str;
}
template<typename T>
std::string pyfunc::join(T* source, size_t size, char join_by) {
std::string join_by_ = (std::string)"" + join_by;
return pyfunc::join(source, size, join_by_);
}
template<typename T>
std::string pyfunc::join(const T* source, size_t size, std::string join_by) {
std::string joined_str = "";
for (int index = 0; index < size - 1; index++) {
joined_str += *source++;
joined_str += join_by;
}
joined_str += *source;
return joined_str;
}
template<typename T>
std::string pyfunc::join(const T* source, size_t size, char join_by) {
std::string join_by_ = (std::string)"" + join_by;
return pyfunc::join(source, size, join_by_);
}