Commit c71a2281 authored by Dominik Charousset's avatar Dominik Charousset

added algorithms to join strings

parent a1f03572
......@@ -34,6 +34,9 @@
#include <string>
#include <vector>
#include <algorithm>
#include <type_traits>
#include "cppa/util/type_traits.hpp"
namespace cppa { namespace util {
......@@ -42,14 +45,22 @@ std::vector<std::string> split(const std::string& str,
bool keep_empties = true);
template<typename Iterator>
std::string join(Iterator begin, Iterator end) {
typename std::enable_if<is_forward_iterator<Iterator>::value,std::string>::type
join(Iterator begin, Iterator end, const std::string& glue = "") {
std::string result;
std::for_each(begin, end, [&](const std::string& str) {
if (!result.empty()) result += glue;
result += str;
});
return result;
}
template<typename Container>
typename std::enable_if<is_iterable<Container>::value,std::string>::type
join(const Container& c, const std::string& glue = "") {
return join(c.begin(), c.end(), glue);
}
} } // namespace cppa::util
#endif // CPPA_UTIL_SPLIT_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment