Skip to content

Instantly share code, notes, and snippets.

@Gnomorian
Last active November 7, 2021 11:10
Show Gist options
  • Save Gnomorian/c9f024aa3b5a42588a1a5a138b7c3b9e to your computer and use it in GitHub Desktop.
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
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