added string concat to ToString

This commit is contained in:
Erik Frojdh
2019-08-20 12:17:42 +02:00
parent 0c4ae89cd9
commit d1ea74120d
5 changed files with 49 additions and 31 deletions

View File

@ -19,8 +19,17 @@
namespace sls {
// std::string ToString(const std::vector<std::string> &vec,
// const char delimiter = ' ');
inline std::string ToString(const std::vector<std::string> &vec,
const char delimiter = ' ') {
std::ostringstream os;
if(!vec.empty()){
auto it = vec.begin();
os << *it++;
while(it != vec.end())
os << delimiter << *it++;
}
return os.str();
}
/** Convert std::chrono::duration with specified output unit */
template <typename T, typename Rep = double>

View File

@ -95,4 +95,13 @@ TEST_CASE("Convert types with str method"){
sls::IpAddr addr;
REQUIRE(ToString(addr) == "0.0.0.0");
REQUIRE(ToString(sls::IpAddr{}) == "0.0.0.0");
}
TEST_CASE("vector of strings"){
std::vector<std::string> vec{"5", "s"};
REQUIRE(ToString(vec) == "5 s");
std::vector<std::string> vec2{"some", "strange", "words", "75"};
REQUIRE(ToString(vec2) == "some strange words 75");
}