<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- Copyright Aleksey Gurtovoy 2006. Distributed under the Boost --> <!-- Software License, Version 1.0. (See accompanying --> <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" /> <title>THE BOOST MPL LIBRARY: Metafunction Composition</title> <link rel="stylesheet" href="../style.css" type="text/css" /> </head> <body class="docframe"> <table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./partial-metafunction.html" class="navigation-link">Prev</a> <a href="./lambda-details.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./partial-metafunction.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Up</a> <a href="../index.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./tutorial_toc.html" class="navigation-link">Full TOC</a></span></td> <td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./tutorial-metafunctions.html" class="navigation-link">Tutorial: Metafunctions and Higher-Order Metaprogramming</a> / <a href="./more-lambda-capabilities.html" class="navigation-link">More Lambda Capabilities</a> / <a href="./metafunction-composition.html" class="navigation-link">Metafunction Composition</a></td> </tr></table><div class="header-separator"></div> <div class="section" id="metafunction-composition"> <h1><a class="toc-backref" href="./more-lambda-capabilities.html#id53" name="metafunction-composition">Metafunction Composition</a></h1> <p>Lambda expressions can also be used to assemble more interesting computations from simple metafunctions. For example, the following expression, which multiplies the sum of two numbers by their difference, is a <strong>composition</strong> of the three metafunctions <tt class="literal"><span class="pre">multiplies</span></tt>, <tt class="literal"><span class="pre">plus</span></tt>, and <tt class="literal"><span class="pre">minus</span></tt>:</p> <pre class="literal-block"> mpl::multiplies<mpl::plus<_1,_2>, mpl::minus<_1,_2> > </pre> <!-- @ example.wrap(apply_test[0], ', mpl::int_<5>,mpl::int_<3>' + apply_test[1] % 16) # Can't exactly justify this yet, but there's no way to get # it into the text prefix += ['#include <boost/mpl/multiplies.hpp>'] compile() --> <p>When evaluating a lambda expression, MPL checks to see if any of its arguments are themselves lambda expressions, and evaluates each one that it finds. The results of these inner evaluations are substituted into the outer expression before it is evaluated.</p> </div> <div class="footer-separator"></div> <table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./partial-metafunction.html" class="navigation-link">Prev</a> <a href="./lambda-details.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./partial-metafunction.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Up</a> <a href="../index.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./tutorial_toc.html" class="navigation-link">Full TOC</a></span></td> </tr></table></body> </html>