Refactoring with C++ 11

前端 未结 11 2375
夕颜
夕颜 2020-11-28 18:17

Given the new toolset provided by c++ lots of programmers, aiming at code simplification, expressiveness, efficiency, skim through their old code and make tweaks (some point

11条回答
  •  清酒与你
    2020-11-28 18:51

    1. Changing std::map to std::unordered_map and std::set to std::unordered_set where ever order of container's elements is irrelevant, enhances significantly the performance.
    2. Using std::map::at instead of using square bracket syntax insertion, when you want to avoid involuntary insertions.
    3. Use alias templates when you want to typedef templates.
    4. Use of initialization lists instead of for loops to initialize STL containers.
    5. Replace fixed size C arrays with std::array.

提交回复
热议问题