Book Image

Learning Boost C++ Libraries

By : Arindam Mukherjee
Book Image

Learning Boost C++ Libraries

By: Arindam Mukherjee

Overview of this book

Table of Contents (19 chapters)
Learning Boost C++ Libraries
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Compile-time programming with Boost


Templates allow us to write C++ code that is independent of specific types of operands and can thus work unchanged with a large family of types. We can create both function templates and class templates (or struct templates), which take type parameters, nontype parameters (like constant integers), as well as template parameters. When a specialization of a class template is instantiated, member functions that are not directly or indirectly called are never instantiated.

The power of C++ templates goes beyond the ability to write generic code though. C++ templates are a powerful computation subsystem using which we can introspect C++ types, glean their properties, and write sophisticated recursive and branching logic that executes at compile time. Using these capabilities, it is possible to define generic interfaces to implementations that are highly optimized for each type they operate upon.

Basic compile-time control flow using templates

In this section...