0
我的目标是将数据发送到多个流。这可以通过使用boost :: tee来实现。但是我想用variadic模板编写一个封装器来使用多个流。如何在可变参数模板中声明“隐式转换”?
问题是我需要从后代结构到祖先结构的隐式转换。或类似的东西。
#include <boost/iostreams/tee.hpp>
#include <boost/iostreams/stream.hpp>
#include <fstream>
#include <iostream>
using namespace std;
namespace bio = boost::iostreams;
using bio::tee_device;
using bio::stream;
template<typename ... Ts>
struct pu;
template<typename T1,typename T2>
struct pu<T1,T2>:public stream<tee_device<T1,T2>>
{
typedef stream<tee_device<T1,T2>> base_type;
operator base_type() { return static_cast<base_type&>(*this); }
base_type& base = static_cast<base_type&>(*this);
pu(T1& t1, T2& t2): base_type(tee_device<T1,T2>(t1,t2)) {}
};
template<typename T1,typename T2,typename T3,typename ... Ts>
struct pu<T1,T2,T3,Ts...> : public stream<tee_device<T1,pu<T2, T3, Ts ...>>>
{
typedef stream<tee_device<T1,pu<T2, T3, Ts ...>>> base_type;
operator base_type() { return static_cast<base_type&>(*this); }
pu(T1& t1, T2& t2, T3& t3, Ts& ... ts) : base_type(t2,t3,ts...){}
};
int main()
{
pu<ostream,ostream> hT(cout,cout); hT<<"2";
pu<ostream,ostream,ostream> hR(cout,cout,cout); hR<<"3";
return 0;
}
该错误是
..\boost_1_56_0\boost\iostreams\detail\forward.hpp|73|error: no matching function for call to
'boost::iostreams::tee_device<std::basic_ostream<char>, pu<std::basic_ostream<char, std::char_traits<char> >, std::basic_ostream<char, std::char_traits<char> > > >::tee_device(std::basic_ostream<char>&, const std::basic_ostream<char>&)'|
预期的输出是 “22333”。 (我有“22”,但没有“333”。也就是说,它是无主的第二线运行良好)
换句话说,我需要从
template<typename T1,typename T2,typename T3,typename ... Ts>
转换
stream<tee_device<T1,pu<T2, T3, Ts ...>>>
模板内。
谢谢!
p.s. (这是我的第一篇文章)& &(我不是母语)
感谢名单,但我有绝对相同的问题吧。 ** \ boost \ iostreams \ detail \ forward.hpp | 73 |错误:没有匹配函数调用'boost :: iostreams :: tee_device,pu > std :: basic_ostream >>> :: tee_device(std :: basic_ostream &,const pu >,std :: basic_ostream >>&)'| ** –
ged
@GeorgeDunaev编辑。 – Oktalist