Created
January 26, 2016 08:33
-
-
Save alepez/de533a78acf5a1079a04 to your computer and use it in GitHub Desktop.
C++ parameter pack of any type to vector of strings
This file contains hidden or 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