-
-
Save abbaswasim/08045f18f628759691611930047588bc to your computer and use it in GitHub Desktop.
C++ parameter pack of any type to vector of strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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