- Expert C++
- Vardan Grigoryan Shunguang Wu
- 247字
- 2021-06-24 16:34:05
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
- CockroachDB權(quán)威指南
- Python Game Programming By Example
- 機(jī)械工程師Python編程:入門、實(shí)戰(zhàn)與進(jìn)階
- Python程序設(shè)計(jì)案例教程
- SQL Server 2016數(shù)據(jù)庫應(yīng)用與開發(fā)習(xí)題解答與上機(jī)指導(dǎo)
- 硅谷Python工程師面試指南:數(shù)據(jù)結(jié)構(gòu)、算法與系統(tǒng)設(shè)計(jì)
- Go語言精進(jìn)之路:從新手到高手的編程思想、方法和技巧(2)
- Solr Cookbook(Third Edition)
- 軟件供應(yīng)鏈安全:源代碼缺陷實(shí)例剖析
- Android群英傳
- Learning AWS
- Kubernetes進(jìn)階實(shí)戰(zhàn)
- Python開發(fā)基礎(chǔ)
- 軟件工程與UML案例解析(第三版)
- Practical Predictive Analytics