Skip to main content

Templates

  • Chapter
  • First Online:
Guide to Scientific Computing in C++

Part of the book series: Undergraduate Topics in Computer Science ((UTICS))

  • 215k Accesses

Abstract

If we want to write a function that returns the larger of two numbers, and we want this function to be used for both integer variables and double precision floating point variables, then we could write two functions: one for integer variables and the other for double precision floating point variables. Both of these functions would require only a few lines of code, and it would not be difficult to maintain both functions. For larger functions maintaining more than one function to do the same operations may be problematic. This may be avoided by the use of templates, a feature of the C++ language that allows very general code to be written. We begin this chapter by discussing templates and the flexibility that they permit. One library associated with C++ is the Standard Template Library (STL): we conclude this chapter by giving a brief survey of this library, and other functionality that has been introduced in recent C++ standards.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    The STL set is implemented as a tree structure known as a red-black search tree.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Joe Pitt-Francis .

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing AG, part of Springer Nature

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Pitt-Francis, J., Whiteley, J. (2017). Templates. In: Guide to Scientific Computing in C++. Undergraduate Topics in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-319-73132-2_8

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-73132-2_8

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-73131-5

  • Online ISBN: 978-3-319-73132-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics