2012-11-18 40 views
0

給定一個boost :: fusion :: vector類型,我想過濾掉所有非ref成員以獲得一個新類型。例如,這會將boost :: fusion :: vector轉換成 boost :: fusion :: vector。我猜測boost :: fusion :: filter_if元函數可能會這樣做, 但在文檔中沒有使用它的例子。任何建議,將不勝感激。需要示例使用boost :: fusion :: filter_if metafunction

+0

其實,這裏有個例子下**僅打印指針**:http://www.boost.org/doc/libs/1_61_0/libs/fusion/ DOC/HTML /融合/ quick_start.html –

回答

0

事情是這樣的:

#include <iostream> 
#include <boost/fusion/container/vector.hpp> 
#include <boost/fusion/algorithm/transformation/filter_if.hpp> 
#include <boost/fusion/include/at_c.hpp> 
#include <boost/fusion/include/equal_to.hpp> 
#include <boost/fusion/include/make_vector.hpp> 
#include <boost/mpl/assert.hpp> 

using namespace boost::fusion; 

int main(void) 
{ 
    int a = 10; 
    double b = 11.; 
    vector<int, int&, double, double&> vec(1, a, 13., b); 

    if(filter_if<boost::mpl::not_<boost::is_reference<boost::mpl::_>>>(vec) == make_vector(1, 13.)) 
     std::cout << "MATCH" << std::endl; 
}