@@ -30,20 +30,28 @@ NODISCARD inline std::string TrimString(const std::string& str, const std::strin
30
30
* @param separator The separator
31
31
* @param unary_op Apply this operator to each item in the list
32
32
*/
33
- template <typename T, typename UnaryOp>
34
- std::string Join (const std::vector<T>& list, const std::string& separator, UnaryOp unary_op)
33
+ template <typename T, typename BaseType, typename UnaryOp>
34
+ auto Join (const std::vector<T>& list, const BaseType& separator, UnaryOp unary_op)
35
+ -> decltype(unary_op(list.at(0 )))
35
36
{
36
- std::string ret;
37
+ decltype ( unary_op (list. at ( 0 ))) ret;
37
38
for (size_t i = 0 ; i < list.size (); ++i) {
38
39
if (i > 0 ) ret += separator;
39
40
ret += unary_op (list.at (i));
40
41
}
41
42
return ret;
42
43
}
43
44
45
+ template <typename T>
46
+ T Join (const std::vector<T>& list, const T& separator)
47
+ {
48
+ return Join (list, separator, [](const T& i) { return i; });
49
+ }
50
+
51
+ // Explicit overload needed for c_str arguments, which would otherwise cause a substitution failure in the template above.
44
52
inline std::string Join (const std::vector<std::string>& list, const std::string& separator)
45
53
{
46
- return Join (list, separator, []( const std::string& i) { return i; } );
54
+ return Join< std::string>(list, separator );
47
55
}
48
56
49
57
/* *
0 commit comments