Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abbaswasim/08045f18f628759691611930047588bc to your computer and use it in GitHub Desktop.
Save abbaswasim/08045f18f628759691611930047588bc 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