Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lefticus/2a4a317885dc2f9b2ff99f62d2bb6729 to your computer and use it in GitHub Desktop.
Save lefticus/2a4a317885dc2f9b2ff99f62d2bb6729 to your computer and use it in GitHub Desktop.
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
template<typename ... T>
std::vector<std::string> to_strings(const T& ... t)
{
std::stringstream ss;
return { (ss.str(""), ss << t, ss.str())... };
}
int main()
{
// convert an arbitrary list of things into a vector<string>
for ( const auto &s : to_strings(1, 2.4, 89.3f, "Hello World")) {
std::cout << s << '\n';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment