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.