Contents
- 1. Item43. Prefer algorithm calls to hand-written loops.
- 2. Item44. Prefer member functions to algorithms with the same names.
- 3. Item45. Distinguish among count, find, binary_search, lower_bound, upper_bound, and equal_range.
- 4. Item46. Consider function objects instead of functions as algorithm parameters.
- 5. Item47. Avoid producing write-only code.
- 6. Item48. Always #include the proper headers.
- 7. Item49. Learn to decipher STL_related compiler diagnostics.
- 8. Item50. Familiarize yourself with STL-releated websites.
2.1. ์๋ก ¶
- ์ ๋ชฉ ๊ทธ๋๋ก.. ๊ฐ์ ์ด๋ฆ์ ์๊ณ ๋ฆฌ์ฆ์ ์ฐ๋ ๋์ ์, ๊ทธ ์ปจํ
์ด๋ ๊ฐ์ฒด์ ๊ฐ์ ์ด๋ฆ์ ๋ฉ์๋๋ฅผ ์ฐ๋๊ฒ ๋ซ๋ค.
- ์ด์ ๋, ๋ ํจ์จ์ ์ด๊ธฐ ๋๋ฌธ์.
- ๋ ๋ค๋ฅธ ์ด์ ๋, equivalnce์ equality์ ์ฐจ์ด์์ ์ค๋ ์ฑ๊ณต ์ฌ๋ถ๋๋๋ฐ.. ์ด ์ฑํฐ๋ ์์ง ์๋ดค๋ค.
2.2. ์์ ¶
- ์ ๊ฑธ ์ฆ์ ์งํฌ์ ์๊ฒ ํ๋ ์์ ๋ฅผ ๋ณด์ด๊ฒ ๋ค.
~cpp set<int> s; // s์๋ ์์๊ฐ ๋ฐฑ๋ง๊ฐ ๋ค์ด์๋ค. ์ด ์ค์์ 727์ด๋ผ๋ ์์๋ฅผ ์ฐพ๊ณ ์ถ๋ค. typedef set<int>::iterator SIIT; ... // ๋ฉ์๋ ํธ์ถ ๋ฒ์ ผ SIIT i = s.find(727); ... // ์๊ณ ๋ฆฌ์ฆ ํธ์ถ ๋ฒ์ ผ SIIT j = find(s.begin(), s.end(), 727)
2.3. ์ค๋ช ¶
- set์ find๋ฉ์๋๋ ๋ก๊ทธ์๊ฐ๋ด์ ์ํ๋๋ค. ํ์ง๋ง find ์๊ณ ๋ฆฌ์ฆ์ ์ ํ์๊ฐ๋ด์ ์ํ๋๋ค. ์ฆ
- find๋ฉ์๋์ average case๋ 20, worst case๋ 40.
- find์๊ณ ๋ฆฌ์ฆ์ average case๋ 5์ญ๋ง, worst case๋ ๋ฐฑ๋ง.
- ์ด ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด ๋น์ฐํ ์ ์์๊ฒ์ ์งํค๊ธฐ ๋ ๊ฒ์ด๋ค.
- find๋ฉ์๋์ average case๋ 20, worst case๋ 40.