C STL與C LINQ中級聯處理的對比

2021-09-30 11:47:36 字數 788 閱讀 9254

在linq中,如下的級聯處理是常見的:

var result = src.select(x => f1(x))     // 用 y = f1(x), z = f2(y) 轉換 x序列

.where(y => c1(y))     // 篩選條件: c1(y) 與 c2(z)

.select(y => f2(y))

.where(z => c2(z));

在c++ stl中,沒有相同的級聯機制,但可以用函式巢狀(bind)的方法來實現相同操作:

// 將[p0, p1)中的資料轉換、篩選後放到[p,)中。

transform_if(p0, p1, p, f2·f1, c1·f1 && c2·f2·f1);

/* 說明:

1. stl中有remove_copy_if,但沒有transform_if,後者需要自己寫。

2. f2·f1代表函式巢狀,正確形式為bind(f2, bind(f1, _1))。

3. (c1·f1 && c2·f2·f1)(x) = (c1·f1)(x) && (c2·f2·f1)(x),代表兩個函式都估真值。

注意,boost lambda支援這種表示式,而c++11不支援。

4. 編譯器需要優化才能避免重複計算f1(x)等值。

*/

另一種標準處理方式則是使用transform_iterator與filter_iterator,它們分別對所指的值作轉換操作與過濾操作,這未被包含在標準c++ stl中。

Mysql中級聯刪除問題

1.對於兩張表 訂單表tb order orderid,訂單與菜表tb order dish orderid,dishid,2.選擇訂單表的orderid作為外來鍵,訂單與菜表的orderid做為子鍵 sql 語句應該為 drop table if exists tb order dish crea...

div css CSS標準中級聯的文件

http bbs.pku.edu.cn homepage看版 較驗div css格式,div css的margin縮寫方式 div css的padding縮寫方式 鏈結的 link,visited,hover,active四種狀態 div css使用backgroundrepeat樣式設定背景的顯示...

SQL 級聯刪除與級聯更新的方法

複製 如下 on delete cascade 當你更新或刪除主鍵表時,那麼外來鍵表也會跟隨一起更新或刪除,需要在建表時設定級聯屬性 create table countries countryid int primary key insert into countries countryid va...