Template Metaprogramming with C++

person icon Packt Publishing

Template Metaprogramming with C++

Template Metaprogramming with C++

person icon Marius Bancila

ebook icon Packt Publishing

language icon Language - English

updated on icon Updated on Jan, 2023

architecture icon C++,Programming Languages,IT & Software


This eBook includes

Formats : PDF (Read Only)

Pages : 480

ISBN : 9781803230535

Language : English

About the Book

Book description

Understand how to use modern C++ templates for writing maintainable, robust, and fast software

Key Features

  • Grasp the fundamentals of and learn to write effective C++ templates
  • Get up to speed with the latest C++20 template features such as constraints and concepts
  • Explore different patterns and idioms to integrate templates in your program design

Book Description

Learn how the metaprogramming technique enables you to create data structures and functions that allow computation to happen at compile time. With this book, you'll realize how templates help you avoid writing duplicate code and are key to creating generic libraries, such as the standard library or Boost, that can be used in a multitude of programs.

The introductory chapters of this book will give you insights into the fundamentals of templates and metaprogramming. You'll then move on to practice writing complex templates and exploring advanced concepts such as template recursion, template argument deduction, forwarding references, type traits, and conditional compilation. Along the way, you'll learn how to write variadic templates and how to provide requirements to the template arguments with C++20 constraints and concepts. Finally, you'll apply your knowledge of C++ metaprogramming templates to implement various metaprogramming patterns and techniques.

By the end of this book, you'll have learned how to write effective templates and implement metaprogramming in your everyday programming journey.

What you will learn

  • Understand the syntax for all types of templates
  • Discover how specialization and instantiation works
  • Get to grips with template argument deduction and forwarding references
  • Write variadic templates with ease
  • Become familiar with type traits and conditional compilation
  • Restrict template arguments in C++20 with constraints and concepts
  • Implement patterns such as CRTP, mixins, and tag dispatching

Who this book is for

This book is for beginner-to-intermediate C++ developers who want to learn about template metaprogramming as well as advanced C++ developers looking to get up to speed with the new C++20 features related to templates and the the various idioms and patterns. Basic C++ coding experience is necessary to get started with this book.

Template Metaprogramming with C++

eBook Preview

Author Details

Packt Publishing

Packt Publishing

Founded in 2004 in Birmingham, UK, Packt's mission is to help the world put software to work in new ways, through the delivery of effective learning and information services to IT professionals.

Working towards that vision, we have published over 6,500 books and videos so far, providing IT professionals with the actionable knowledge they need to get the job done - whether that's specific learning on an emerging technology or optimizing key skills in more established tools.

As part of our mission, we have also awarded over $1,000,000 through our Open Source Project Royalty scheme, helping numerous projects become household names along the way.

Our students work
with the Best

Related eBooks

View More

Annual Membership

Become a valued member of Tutorials Point and enjoy unlimited access to our vast library of top-rated Video Courses

Subscribe now
People having fun around a laptop

Online Certifications

Master prominent technologies at full length and become a valued certified professional.

Explore Now
People having fun around a laptop

Talk to us