官术网_书友最值得收藏!

Understanding and Designing Templates

Templates are a unique feature of C++ by which functions and classes have the ability to support generic data types in other words, we can implement a function or class independent of a particular data type; for example, a client may request a max() function to handle different data types. Instead of implementing and maintaining many similar functions by using function overloading, we can just implement one max() and pass the data type as a parameter. Moreover, templates can work together with multiple inheritance and operator overloading to create powerful generic data structures and algorithms in C++ such as the Standard Template Library (STL). Additionally, templates can also be applied to compile-time computation, compile-time and runtime code optimization, and more.

In this chapter, we will learn about the syntax of function and class templates, their instantiations, and their specializations. Then, we will introduce variadic templates and their applications. Next, we will discuss template parameters and the corresponding arguments that are used for instantiating them. After that, we'll learn how to implement a type trait and how to use this type of information to optimize algorithms. Finally, we will present techniques that we can use to speed up programs when they're executed, which includes compile-time computation, compile-time code optimization, and static polymorphism.

This chapter will cover the following topics:

  • Exploring function and class templates
  • Understanding variadic templates
  • Understanding template parameters and arguments
  • What are traits?
  • Template meta-programming and its applications
主站蜘蛛池模板: 定西市| 京山县| 富蕴县| 偃师市| 松江区| 界首市| 安庆市| 旌德县| 沙洋县| 霍州市| 平安县| 汶川县| 兰西县| 宁都县| 康乐县| 确山县| 通州区| 崇左市| 吴旗县| 新邵县| 太仆寺旗| 六盘水市| 喀喇沁旗| 浏阳市| 定西市| 扎鲁特旗| 云梦县| 平果县| 合作市| 渭源县| 图木舒克市| 上林县| 资阳市| 上蔡县| 大渡口区| 枣强县| 贺兰县| 陆丰市| 巴中市| 永定县| 芮城县|