#include <sstream>
using std::stringstream;
using std::string;
inline void __impl__inlineArgs(stringstream & ss, const string& str, int && from)
{
if(from != 0)
ss << str.substr(from);
else
ss << str;
}
template<typename T, typename... Args>
inline void __impl__inlineArgs(stringstream & ss, const string& str, const int && from, T t, Args... args)
{
const auto target = str.find_first_of('$', from);
if(target == string::npos)
{
ss << str.substr(from);
}
else
{
ss << str.substr(from, target - from) << t;
__impl__inlineArgs(ss, str, target + 1, args...);
}
}
template<typename... Args>
inline string inlineArgs(const string str, Args... args)
{
stringstream ss;
__impl__inlineArgs(ss, str, 0, args...);
return ss.str();
}
=================================================
사용방법
inlineArgs("value of userID($) userName($) is $", userId, userName, value[userId]);
=================================================
using std::stringstream;
using std::string;
inline void __impl__inlineArgs(stringstream & ss, const string& str, int && from)
{
if(from != 0)
ss << str.substr(from);
else
ss << str;
}
template<typename T, typename... Args>
inline void __impl__inlineArgs(stringstream & ss, const string& str, const int && from, T t, Args... args)
{
const auto target = str.find_first_of('$', from);
if(target == string::npos)
{
ss << str.substr(from);
}
else
{
ss << str.substr(from, target - from) << t;
__impl__inlineArgs(ss, str, target + 1, args...);
}
}
template<typename... Args>
inline string inlineArgs(const string str, Args... args)
{
stringstream ss;
__impl__inlineArgs(ss, str, 0, args...);
return ss.str();
}
=================================================
사용방법
inlineArgs("value of userID($) userName($) is $", userId, userName, value[userId]);
=================================================