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