Skip to content

Instantly share code, notes, and snippets.

@JakubGrobelny
Last active January 15, 2019 00:44
Show Gist options
  • Save JakubGrobelny/91823c517112c39b86d72760e1c0d846 to your computer and use it in GitHub Desktop.
Save JakubGrobelny/91823c517112c39b86d72760e1c0d846 to your computer and use it in GitHub Desktop.
Simple C++ string formatiing
#include <string>
namespace implementation
{
template <typename T>
inline auto stringify(const T& t) -> std::string
{
return std::to_string(t);
}
inline auto stringify(const char* str) -> std::string
{
return str;
}
inline auto stringify(const std::string& str) -> std::string
{
return str;
}
}
template <typename ... T>
auto format(T ... args) -> std::string
{
return (... + implementation::stringify(args));
}
@JakubGrobelny
Copy link
Author

JakubGrobelny commented Aug 15, 2018

usage:

std::string str = format("This ", "string", " should end with ", 42, '.');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment