Skip to content

Instantly share code, notes, and snippets.

@SeijiEmery
Last active August 29, 2015 14:06
Show Gist options
  • Save SeijiEmery/fd7b90a475035ed75f56 to your computer and use it in GitHub Desktop.
Save SeijiEmery/fd7b90a475035ed75f56 to your computer and use it in GitHub Desktop.
C++11 Utility Functions
#include <sstream>
// Provides a generic python-inspired string join function that operates on iterators
// and containers.
template <typename Iterator>
string join (const std::string & delim, Iterator begin, Iterator end) {
std::ostringstream ss;
if (begin != end)
ss << *begin++;
for (; begin != end; ++begin)
ss << delim << *begin;
return ss.str();
}
template <typename Container>
std::string join (const std::string & delim, const Container & elems) {
return join(delim, std::begin(elems), std::end(elems));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment