Boost學習摘要 二繫結器

2021-08-28 15:35:02 字數 896 閱讀 9912

boost庫在工作(13)繫結器與函式物件之一

std::bind1st和std::bind2nd

boost庫在工作(14)繫結器與函式物件之二

std::for_each(vrect.begin(), vrect.end(),std::bind1st(std::mem_fun(&cobj::fun),this));

boost庫在工作(15)繫結器與函式物件之三

boost庫里的繫結器bind與stl裡定義的兩個相比,引數比較多,可以多達9個,也許你會問,如果多於9個怎麼樣辦呢?多於9個的情況是比較少的,就算有了,在這種情況之下,也需要定義乙個資料結構來儲存,傳遞乙個指標進來比較合算,因為這樣引數少,方便維護,同樣傳送的效率提高了。第二個優點是繫結成員函式簡單,不需要呼叫mem_fun函式,第三個優點是提供佔位符,可以隨便指定到那個引數傳入。9個引數的佔位符的名稱是_1,_2,_3,一直接到_9。

vrect.erase(std::remove_if(vrect.begin(), vrect.end(),boost::bind(&cobjbind::isless,this, _1)), vrect.end());

在這個例子裡,先呼叫演算法remove_if來刪除陣列中小於指定條件的元素,並返回無效元素的起始位置,然後呼叫vrect.erase刪除後面無效的元素,最終在陣列裡就剩下有效的元素了。

必須系統的好好學習stl了

boost::bind(std::logical_and(),

boost::bind(std::greater(),_1, 10),

boost::bind(std::less_equal(),_1, 20))(15);

std::remove_if

std::mem_fun

std::for_each

都沒用過。。。

Boost學習摘要 三線程

boost庫在工作 16 執行緒之一 boost thread boost bind run,1 boost庫在工作 17 執行緒之二 boost thread group 主要使用了boost庫里的執行緒池類thread group,它提供了多個執行緒建立 儲存 退出等管理。比如使用create ...

Boost學習摘要 四任務

boost庫在工作 21 任務之一 boost asio io service ioserice 定義乙個任務佇列。ioserice.post boost bind run,10 執行佇列裡的任務。ioserice.post boost bind run,2 ioserice.post boost ...

pandas學習摘要二

時間序列 按照列索引合併 in 16 df1 pd.dataframe np.ones 2,4 index a b columns list abcd in 17 df1 out 17 a b c d a 1.0 1.0 1.0 1.0 b 1.0 1.0 1.0 1.0 in 18 df2 pd....