| 38 | // Joins a container of things into a single string, using the given separator. |
| 39 | template <typename ContainerT, typename SeparatorT> |
| 40 | std::string Join(const ContainerT& things, SeparatorT separator) { |
| 41 | if (things.empty()) { |
| 42 | return ""; |
| 43 | } |
| 44 | |
| 45 | std::ostringstream result; |
| 46 | result << *things.begin(); |
| 47 | for (auto it = std::next(things.begin()); it != things.end(); ++it) { |
| 48 | result << separator << *it; |
| 49 | } |
| 50 | return result.str(); |
| 51 | } |
| 52 | |
| 53 | // We instantiate the common cases in strings.cpp. |
| 54 | extern template std::string Join(const std::vector<std::string>&, char); |