diff --git a/src/tl/tl/tlString.cc b/src/tl/tl/tlString.cc index 01fdf3ec2..178020c61 100644 --- a/src/tl/tl/tlString.cc +++ b/src/tl/tl/tlString.cc @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -936,23 +935,6 @@ from_string (const std::string &s, bool &b) } } -std::string -join (const std::vector &vv, const std::string &s) -{ - std::ostringstream r; - - bool first = true; - for (std::vector ::const_iterator i = vv.begin (); i != vv.end (); ++i) { - if (!first) { - r << s; - } - first = false; - r << *i; - } - - return r.str (); -} - std::vector split (const std::string &t, const std::string &s) { diff --git a/src/tl/tl/tlString.h b/src/tl/tl/tlString.h index 1c8ea8fb7..dd7e7536a 100644 --- a/src/tl/tl/tlString.h +++ b/src/tl/tl/tlString.h @@ -27,6 +27,7 @@ #include "tlCommon.h" #include +#include #include #include #include @@ -930,7 +931,34 @@ inline std::string sprintf (const std::string &fmt, const tl::Variant &a1, const TL_PUBLIC std::string trim (const std::string &s); TL_PUBLIC std::vector split (const std::string &s, const std::string &sep); -TL_PUBLIC std::string join (const std::vector &strings, const std::string &sep); + +/** + * @brief Joins a generic iterated list into a single string using the given separator + */ +template +TL_PUBLIC_TEMPLATE std::string join (Iter from, Iter to, const std::string &sep) +{ + std::ostringstream r; + + bool first = true; + for (Iter i = from; i != to; ++i) { + if (!first) { + r << sep; + } + first = false; + r << tl::to_string (*i); + } + + return r.str (); +} + +/** + * @brief Joins a vector of strings into a single string using the given separator + */ +inline std::string join (const std::vector &strings, const std::string &sep) +{ + return join (strings.begin (), strings.end (), sep); +} /** * @brief Returns the lower-case character for a wchar_t