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