1.1. Getting Started
One of the nice things about template metaprograms is a property they share with good old traditional systems: Once a metaprogram is written, it can be used without knowing what's under the hoodas long as it works, that is.
To build your confidence in that, let us begin by presenting a tiny C++ program that simply uses a facility implemented with template metaprogramming:
#include "libs/mpl/book/chapter1/binary.hpp"
#include <iostream>
int main()
{
std::cout << binary<101010>::value << std::endl;
return 0;
}
Even if you were always good at binary arithmetic and can tell what the output of the program will be without actually running it, we still suggest that you go to the trouble of trying to compile and run the example. Besides contributing to building your confidence, it's a good test of whether your compiler is able to handle the code we present in this book. The program should write the decimal value of the binary number 101010:
42
to the standard output.
 |