#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
template <typename T>
void print_impl(std::ostringstream& os, const char* format, T&& arg) {
while (*format) {
if (*format == '{' && *(format + 1) == '}') {
os << arg;
format += 2;
return;
}
os << *format++;
}
}
template <typename T, typename... Args>
void print_impl(std::ostringstream& os, const char* format, T&& arg, Args&&... args) {
while (*format) {
if (*format == '{' && *(format + 1) == '}') {
os << arg;
print_impl(os, format + 2, std::forward<Args>(args)...);
return;
}
os << *format++;
}
}
template <typename... Args>
void sys_transform(const char* format, Args&&... args) {
std::ostringstream os;
print_impl(os, format, std::forward<Args>(args)...);
std::cout<<os.str()<<std::endl;
}
//重载函数使得兼容无参数case
void sys_transform(const char* format) {
std::ostringstream os;
while (*format) {
if (*format == '{' && *(format + 1) == '}') {
os << "null";
format += 2;
continue;
}
os << *format++;
}
std::cout<<os.str()<<std::endl;
}
#define MYLOG(log_str, ...) sys_transform(log_str, ##__VA_ARGS__)
int main ()
{
int i = 1;
MYLOG("hello :{}", i);
MYLOG("hello :{}", "world");
MYLOG("hello :{}");
}