Last active
November 7, 2021 11:10
-
-
Save Gnomorian/c9f024aa3b5a42588a1a5a138b7c3b9e to your computer and use it in GitHub Desktop.
use function template params to concatenate parameters that can be inserted to streams sort of like a simple formatting function
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::string concat(Args...args) | |
{ | |
std::stringstream stream; | |
((stream << args), ...); | |
return std::move(stream.str()); | |
} | |
int main() | |
{ | |
constexpr auto something=10; | |
constexpr auto somethingelse=11; | |
auto msg{concat("something=", something, ", else=", else)}; | |
std::cout << msg << std::endl; // writes "something=10, else=11" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment