Giter Club home page Giter Club logo

template-metaprogramming-with-cpp's Introduction

Template Metaprogramming with C++

Template Metaprogramming with C++

This is the code repository for Template Metaprogramming with C++ , published by Packt.

Learn everything about C++ templates and unlock the power of template metaprogramming

What is this book about?

Templates are a key feature of the C++ language that enable us to reuse source code, write more efficient code, and create generic libraries that can be used in many applications. Yet, they are often complex and hard to understand. This book will help you in understanding and writing templates from their simplest forms to the latest C++20 features.

This book covers the following exciting features:

  • 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

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Errata

  • Page 258: The line of code return value--; must be read as return value-1; or return --value;

Instructions and Navigations

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

template <typename T>
struct parser : base_parser<T>
{
   void parse()
   {
   this->init(); // OK
   std::cout << "parse\n";
   }
};

Structure

The source code for the book is organized per chapters. Each chapter has its own subfolder in the src folder. These subfolders are called chapter_01, chapter_02, etc. For most chapters, the code is found in a single source file, main.cpp. This file is organized in multiple namespaces, such as n101, n102, n103 etc. for the first chapter, n201, n202, n203 etc. for the second chapter and so on.

Supported compilers

All the code provided in the book is cross-platform. You can use any of the major compilers, MSVC, Clang, or GCC to compile the sources.

You can also run snippets of code using compilers available online:

How to build

You must have CMake to build the code.

Example for creating a Visual Studio solution

Run the following commands to create a solution for Visual Studio 2019:

mkdir build
cd build
cmake -G "Visual Studio 16 2019" -A x64 ..

Run the following commands to create a solution for Visual Studio 2022:

mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A x64 ..

Following is what you need for this book: 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.

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. Click here to download it.

Related products

Get to Know the Author

Marius Bancila is a software engineer with two decades of experience in developing solutions for line of business applications and more. He is the author of Modern C++ Programming Cookbook and The Modern C++ Challenge. He works as a software architect and is focused on Microsoft technologies, mainly developing desktop applications with C++ and C#. He is passionate about sharing his technical expertise with others and, for that reason, he has been recognized as a Microsoft MVP for C++ and later developer technologies since 2006. Marius lives in Romania and is active in various online communities.

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781803243450

template-metaprogramming-with-cpp's People

Contributors

packt-itservice avatar mariusbancila avatar packt-pradeeps avatar tikshas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.