我有一個std::array
和boost::fusion::vector<X, Y>
,我想傳遞給func1()
。此功能將爲每個std::array
元素添加一個boost::fusion::vector<X, Y>
實例。如何返回boost :: fusion :: vector <x,y,z>添加到std :: array的元素<boost :: fusion :: vector <x,y,z>>?
我必須使用fusion::fold()
,以便我可以將正確數量的元素添加到fusion::vector<X,Y>
,對吧?
所以我現在有這樣的事情:
void func1(){
boost::fusion::vector<X,Y> my_vec;
std::array<boost::fusion::vector<X,Y> > my_array[10];
func2(my_vec, my_array);
}
void func2(boost::fusion::vector<X,Y> my_vec, std::array<boost::fusion::vector<X,Y> > my_array){
//THIS IS THE PART I AM UNSURE ABOUT
for(int k=0; k<10; k++){
//The first two parameters aren't so important- just included to show the idea
my_array[k] = boost::fusion::fold(my_vec, 1, some_struct);
}
}
//This part is irrelevant
struct some_struct
{
typedef int result_type;
template<typename T>
int operator()(int x, T& t) const
{
t = something(x);
//Not sure if this part needs to return a boost::fusion::vector<X, Y>
return x;
}
};
我不確定的是如何使用的my_vec
簽名,以創建多個boost::fusion::vector<X,Y>
實例,並返回他們回來,這樣我可以添加的部分到func2()
中的數組。
請問有人請指教?
編輯 - 剛剛發現我得到的第一個參數爲fold()
錯誤,修正了我的問題。
我想創建衆多fusion :: vector s,並且這些實例中的每一個都應存儲在std :: array中。這有幫助嗎? –
user3125975
@ user3125975是和否。這基本上是你在這裏做的'std :: array> my_array [10];',所以我假設你想以特定的方式初始化它們。爲什麼不只是'my_array [k] = something()'其中'something'是返回一個'fusion :: vector'的函數,你在'somestruct'中調用? –
Johan
something()如何知道向量中放入了多少元素?它需要「看」my_vec的格式? – user3125975