January 2018
Intermediate to advanced
374 pages
9h 53m
English
If we were to create a function that makes a string out of any number of arguments without variadic template parameter packs, we would have to create a separate function for every number of arguments:
// Makes a string of by one argumenttemplate <typename T0>
auto make_string(const T0& v0) -> std::string {
auto sstr = std::ostringstream{};
sstr << v0;
return sstr.str();
}
// Makes a string of by two arguments
template <typename T0, typename T1>
auto make_string(const T0& v0, const T1& v1) -> std::string {
return make_string(v0) + " " + make_string(v1);
}
// Makes a string of by three arguments
template <typename T0, typename T1, typename T2> auto make_string(const T0& v0, const T1& ...