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.0114 sec