我想构建类似的东西,
template<class Ostream, int N>
class StreamPrinter{
public:
StreamPrinter(Ostream& out, std::string tail = "\n", std::string head = "", std::string middle = "\t")
: out(out)
, tail(tail)
, head(head) {}
template<class... Data>
void operator()(const Data&... dat){
//if N = 3,
//out << head << dat1 << middle << dat2 << middle << dat3 << tail;
//where dat# means the #'s argument of dat...
}
private:
Ostream& out;
std::string tail;
std::string head;
std::string middle;
};
我想operator()
根据模板参数构造不同的行为N
。的行为N=3
在上面的代码中进行了描述。假设sizeof...(dat) >= N
.
我尝试了一段时间。但我没能做到。请给我一些建议。:)