diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index b2f63138e..f5784f3d2 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -170,4 +170,13 @@ ToString(const T &obj) { return obj.str(); } +/** + * Call ToString with a string, causes copy but might be needed + * in generic code. + */ +template <> +inline std::string ToString(const std::string& s){ + return s; +} + } // namespace sls diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index 42f60309b..0c295ce09 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -97,6 +97,11 @@ TEST_CASE("Convert types with str method"){ 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"){ std::vector vec{"5", "s"}; REQUIRE(ToString(vec) == "[5, s]"); @@ -104,4 +109,7 @@ TEST_CASE("vector of strings"){ std::vector vec2{"some", "strange", "words", "75"}; REQUIRE(ToString(vec2) == "[some, strange, words, 75]"); -} \ No newline at end of file +} + + +