Skip to content

Instantly share code, notes, and snippets.

@alepez
Created January 26, 2016 08:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alepez/de533a78acf5a1079a04 to your computer and use it in GitHub Desktop.
Save alepez/de533a78acf5a1079a04 to your computer and use it in GitHub Desktop.
C++ parameter pack of any type to vector of strings
template <typename... Args>
std::vector<std::string> toStringVector(Args... args) {
std::vector<std::string> result;
auto initList = {args...};
using T = typename decltype(initList)::value_type;
std::vector<T> expanded{initList};
result.resize(expanded.size());
std::transform(expanded.begin(), expanded.end(), result.begin(), [](T value) { return std::to_string(value); });
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment