Effective STL 讀書筆記 7

2021-04-03 03:03:55 字數 898 閱讀 2823

item 35:使用

mi**atch

或者 lexicographical_compare

實現簡單的忽略大小寫的字串比較函式。

int ci_compare (const string &s1, const string &s2)

int ci_compare_impl (const string &s1, const string &s2)

return ci_char_compare(*p.first, *p.second);}

bool ci_equal (const string &s1, const string &s2)

int ci_compare (const string &s1, const string &s2)

item 36:了解

copy_if

的適當實現。

template< typename inputiter,

typename outputiter,

typename predicate>

outputiter copy_if (inputiter begin,

inputiter end,

outputiter destbegin,

predicate p)

item 37:使用

accumulate

或者 for_each

計算總計。

double sum = accumulate(ld.begin(), ld.end(), 0.0); // must be 0.0

template< valuet, elementt >

class predicate : public binary_function, valuet

> ;

《Effective STL》讀書筆記

工作之後更多地接觸到stl,在專案中stl的使用更是屢見不鮮。最近在看此書,有必要小小地總結一下。1.用empty 而不用size 0去判斷容器是否為空 從功能上看,兩者是一樣的。但效能上可能會有所差別。對於vector而言,size 其實就是end begin 因為它是連續記憶體分布,所以這樣計算...

Effective STL 讀書筆記 1

讀技術書籍是一件開心的事情,但從來沒有哪本書像 effective 這樣讓我這麼開心。effective c 如是,more effective c 如是,effective stl 亦如是。沒有哪位作者比 scott meyers 更懂得輕鬆與嚴肅的學習了。以下只列舉被我 忽略 和 幾乎忽略 的東...

讀書筆記之 Effective STL

條款3 使容器裡物件的拷貝操作輕量而正確 stl中採用的都是拷貝物件的方式 如果所有這些使stl的拷貝機制聽起來很瘋狂,就請重新想想。是,stl進行了大量拷貝,但它通常設計為避免不必要的物件拷貝,實際上,它也被實現為避免不必要的物件拷貝。和c和c 內建容器的行為做個對比,下面的陣列 widget w...