fix for string to string conversion

This commit is contained in:
Erik Frojdh 2019-10-01 12:18:06 +02:00
parent 3c6d7ca4a5
commit ffa9bbe8d2
2 changed files with 18 additions and 1 deletions

View File

@ -170,4 +170,13 @@ ToString(const T &obj) {
return obj.str(); return obj.str();
} }
/**
* Call ToString with a string, causes copy but might be needed
* in generic code.
*/
template <>
inline std::string ToString<std::string>(const std::string& s){
return s;
}
} // namespace sls } // namespace sls

View File

@ -97,6 +97,11 @@ TEST_CASE("Convert types with str method"){
REQUIRE(ToString(sls::IpAddr{}) == "0.0.0.0"); REQUIRE(ToString(sls::IpAddr{}) == "0.0.0.0");
} }
TEST_CASE("String to string", "[support]"){
std::string s = "hej";
REQUIRE(ToString(s) == "hej");
}
TEST_CASE("vector of strings"){ TEST_CASE("vector of strings"){
std::vector<std::string> vec{"5", "s"}; std::vector<std::string> vec{"5", "s"};
REQUIRE(ToString(vec) == "[5, s]"); REQUIRE(ToString(vec) == "[5, s]");
@ -105,3 +110,6 @@ TEST_CASE("vector of strings"){
REQUIRE(ToString(vec2) == "[some, strange, words, 75]"); REQUIRE(ToString(vec2) == "[some, strange, words, 75]");
} }