U E D R , A S I H C RSS

EffectiveSTL/Programming WithSTL


1. Item43. Prefer algorithm calls to hand-written loops.


2. Item44. Prefer member functions to algorithms with the same names.

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๋Š” ๋ฐฑ๋งŒ.
    • ์ด ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด ๋‹น์—ฐํžˆ ์ € ์œ„์˜๊ฒƒ์„ ์ง€ํ‚ค๊ธฐ ๋  ๊ฒƒ์ด๋‹ค.



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.

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:10
Processing time 0.0049 sec