久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

boost 的 assign

 wlk8611 2012-07-26

 

一般只用包含  boost/assign.hpp 文件就可以了,,操作符包含在 namespace::assign。支持標(biāo)準(zhǔn)的 vector,,list,,queue,multimap,,map,,priority_queue,queue,,multiset,,set,stack,, boost::array,,boost::multi_index_container,Boost.Pointer Container
 
第一種方式通過重載 +=
vector<int> v;
v += 1,2,3,4,5,6,7,8,9;
 
第二種方式是重載(),,但是必須通過 insert,, push_front,push_back,,push 這幾個函數(shù)構(gòu)造一個 list_inserter 的對象,,如
typedef pair< string,string > str_pair;
deque<str_pair> deq;
push_front( deq )( "foo", "bar")( "boo", "far" );
 
第三種是利用 list_of() 或者是 list_of(const &T) 初始化 const 容器,如
如果是 stack,,queue,,prior_queue 這些 container adapter,,就使用 to_adapter()幫助編譯器識別,如:
而 map_list_of() 則是為了便于使用 map,,如:
map<int,int> next = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6);
next = list_of< pair<int,int> >(6,7)(7,8)(8,9); // 注意這時 next 只有 3 個元數(shù),。
tuple_list_of()則是為了便于使用 tuple,如:
typedef boost::tuple<int,std::string,int> tuple;
vector<tuple> v = tuple_list_of( 1, "foo", 2 )( 3, "bar", 4 );
 
如果有多個重復(fù)的元素,,則可以使用 repeat() 和 repeat_fun() 這兩個函數(shù),,如
而 repeat_fun() 則利用仿函數(shù)產(chǎn)生元素
template< class T >
struct next   
{
    T seed;
    next( T seed ) : seed(seed)
    { }
   
    T operator()()
    {
        return seed++;
    }
};
    
{
    vector<int> v;
    v += 1,2,repeat_fun(4,&rand),4;
    // v = [1,2,?,?,?,?,4]
    BOOST_ASSERT( v.size() == 7 );
   
    push_back( v ).repeat_fun(4,next<int>(0))(4).repeat_fun(4,next<int>(5));
    // v = old v + [0,1,2,3,4,5,6,7,8]
    BOOST_ASSERT( v.size() == 16 );
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn),。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多