考虑以下代码:
template<typename T0>
void send( const std::string& func, const T0& t0 )
{
std::ostringstream s;
s << func << ": " << t0;
sendMessage( s.str() );
}
template<typename T0, typename T1>
void send( const std::string& func, const T0& t0, const T1& t1 )
{
std::ostringstream s;
s << func << ": " << t0 << "," << t1;
sendMessage( s.str() );
}
template<typename T0, typename T1, typename T2>
void send( const std::string& func, const T0& t0, const T1& t1, const T2& t2 )
{
std::ostringstream s;
s << func << ": " << t0 << "," << t1 << "," << t2;
sendMessage( s.str() );
}
我需要将其扩展到15个参数左右。
我想知道是否可以使用Boost.Preprocessor来简化这种重复,并且该如何操作。我已经查看了文档,但是感觉比较混乱难懂。
char
和0
听起来很可能,因为流是字符。 - chrisstatic_assert(sizeof args... <= 15, "必须传递15个或更少的参数。");
- chris