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
About the Author
About the Reviewers

Domain Specific Embedded Languages

In the last third of this chapter, we look at the applications of higher order and compile-time programming mainly in the area Domain Specific Embedded Languages.

Lazy evaluation

In C++, when we see the following code:

z = x + y();

We know that the value of z is immediately computed when the control reaches past the statement z = x + y(). In fact, the act of computing the sum involves evaluating the expressions x and y() themselves. Here, y is presumably a function or a functor instance, so the call to y() will in turn trigger more evaluations. Irrespective of whether z is ever used for anything later, its value would still be computed. This is the model of eager evaluation that a lot of programming languages follow. The actual story is slightly more complex because compilers can reorder and optimize away computations but there is little control the programmer has on the process.

What if we could defer the evaluation of such expressions and any of their sub...