memgraph/include/utils/string/intercalate.hpp
2016-08-10 09:39:02 +01:00

30 lines
503 B
C++

#pragma once
#include <sstream>
#include <string>
namespace utils
{
template <typename It>
std::string intercalate(It first, It last,
const std::string& separator)
{
if(first == last)
return "";
std::stringstream ss;
It second(first);
// append the first N-1 elements with a separator
for(second++; second != last; ++first, ++second)
ss << *first << separator;
// append the last element
ss << *first;
return ss.str();
}
}