Most important things about C++ templates… lesson learned

前端 未结 12 1452
暗喜
暗喜 2021-01-30 18:52

What are most important things you know about templates: hidden features, common mistakes, best and most useful practices, tips...common mistakes/oversight/assumptions

12条回答
  •  日久生厌
    2021-01-30 19:24

    I've used c++ and templates a lot, including more advanced template metaprogramming and my feeling is that their usefulness is overrated. They were originally added to the c++ language, well after the creation of c++, to tack on a generic programming capability. This simply allows one to focus on the logic of the code without regard for types, potentially making code clearer and reusable.

    My programming philosophy is to understand the original purpose and design of the language and it's features in order to really appreciate the language. I feel template metaprogramming is bastardization of templates and should be avoided. Templates are however useful for defining higher level generic types such as the case of Tuples.

提交回复
热议问题