Skip to content

Instantly share code, notes, and snippets.

@drewxa
Created September 1, 2017 13:05
Show Gist options
  • Save drewxa/78ce4baed653c00642169cfca2f3e751 to your computer and use it in GitHub Desktop.
Save drewxa/78ce4baed653c00642169cfca2f3e751 to your computer and use it in GitHub Desktop.
struct formater
{
formater(const char* str, size_t size)
: format(str, size)
{
}
template<class ...T>
std::string operator()(T&&... s) const
{
char str[10000] = {0};
sprintf (str, format.c_str(), std::forward<T>(s)...);
return std::string(str);
}
std::string format;
};
formater operator"" _format ( const char* str, size_t size )
{
return formater{str, size};
}
int main()
{
auto s = "Hello %s world%s"_format(",", "!");
std::cout << s ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment