Skip to content
Free planNo credit card requiredStart writing

book chapter · Apress eBooks · 2023

Function Templates

Ivor Horton, Peter Van Weert

Cited by 0Abstract and details only

Abstract

You may have noticed that some of the overloaded functions in Ex8_15 consisted of exactly the same code. The only difference were the types that appear in the parameter list. It seems an unnecessary overhead to have to write the same code over and over, just because it has to work for different types. And indeed it is. In such situations you can write the code just once, as a function template. The Standard Library, for instance, makes heavy use of this feature to ensure that its functions work optimally with any type, including your own custom types, which of course the library cannot know about in advance. This chapter introduces the basics of defining your own function templates that work with any type you desire.

Cite this paper

APA 7

Horton, I., & Van Weert, P. (2023). Function Templates. Apress eBooks, 371–390. https://doi.org/10.1007/978-1-4842-9343-0_10

MLA 9

Horton, Ivor, and Peter Van Weert. “Function Templates.” Apress eBooks, 2023, pp. 371–90, https://doi.org/10.1007/978-1-4842-9343-0_10.

Chicago

Horton, Ivor, and Peter Van Weert. 2023. “Function Templates.” Apress eBooks: 371–90. https://doi.org/10.1007/978-1-4842-9343-0_10.

Harvard

Horton, I. and Van Weert, P. (2023) ‘Function Templates’, Apress eBooks, pp. 371–390. Available at: https://doi.org/10.1007/978-1-4842-9343-0_10.

BibTeX
@incollection{horton2023function,
  title = {{Function Templates}},
  author = {Horton, Ivor and Van Weert, Peter},
  booktitle = {Apress eBooks},
  pages = {371--390},
  year = {2023},
  doi = {10.1007/978-1-4842-9343-0_10}
}

Made from the index record. Check names, capitalisation and page numbers against the paper. Need another style? AI for Research has over 10,000.

Templates

Nancy Gill · Apress eBooks · 2003

Cited by 0