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