cargo: join elements from std::set 58/61658/1 tizen
authorKrzysztof Dynowski <k.dynowski@samsung.com>
Wed, 9 Mar 2016 10:39:48 +0000 (11:39 +0100)
committerKrzysztof Dynowski <k.dynowski@samsung.com>
Wed, 9 Mar 2016 10:39:48 +0000 (11:39 +0100)
[Feature]       Joins set elements to string
[Cause]         N/A
[Solution]      Similar to join of vector
[Verification]  Build, install, run tests.

Change-Id: I7ed488bde84ba6705351ffe26d03c82812fb0eaa

common/utils/text.hpp

index a6219d45d8734ce8a5740503b4a3b9a11d89619f..0587a53335ebd60ca7e566c157630d9227b23695 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <string>
 #include <vector>
+#include <set>
 #include <sstream>
 
 namespace utils {
@@ -65,6 +66,19 @@ std::string join(const std::vector<T>& vec, const char *delim)
     return res.str();
 }
 
+template<typename T>
+std::string join(const std::set<T>& vec, const char *delim)
+{
+    std::stringstream res;
+    for (const auto& s : vec) {
+        if (res.tellp()>0) {
+            res << delim;
+        }
+        res << s;
+    }
+    return res.str();
+}
+
 std::vector<std::string> split(const std::string& str, const std::string& delim);
 
 } // namespace utils