• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4<!-- Copyright Aleksey Gurtovoy 2006. Distributed under the Boost -->
5<!-- Software License, Version 1.0. (See accompanying -->
6<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
7<head>
8<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
10<title>THE BOOST MPL LIBRARY: Partial Metafunction Application</title>
11<link rel="stylesheet" href="../style.css" type="text/css" />
12</head>
13<body class="docframe">
14<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Prev</a>&nbsp;<a href="./metafunction-composition.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group">Back&nbsp;<a href="./metafunction-composition.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Up</a>&nbsp;<a href="../index.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tutorial_toc.html" class="navigation-link">Full TOC</a></span></td>
15<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="./partial-metafunction.html" class="navigation-link">Partial Metafunction Application</a></td>
16</tr></table><div class="header-separator"></div>
17<div class="section" id="partial-metafunction">
18<h1><a class="toc-backref" href="./more-lambda-capabilities.html#id52" name="partial-metafunction">Partial Metafunction Application</a></h1>
19<p>Consider the lambda expression <tt class="literal"><span class="pre">mpl::plus&lt;_1,_1&gt;</span></tt>.  A single
20argument is directed to both of <tt class="literal"><span class="pre">plus</span></tt>'s parameters, thereby
21adding a number to itself.  Thus, a <em>binary</em> metafunction,
22<tt class="literal"><span class="pre">plus</span></tt>, is used to build a <em>unary</em> lambda expression.  In other
23words, we've created a whole new computation!  We're not done yet,
24though:  By supplying a non-placeholder as one of the arguments, we
25can build a unary lambda expression that adds a fixed value, say
2642, to its argument:</p>
27<pre class="literal-block">
28mpl::plus&lt;_1, mpl::int_&lt;42&gt; &gt;
29</pre>
30<!-- @ apply_test = 'enum { value = mpl::apply<', ''' >::type::value };
31              BOOST_STATIC_ASSERT(value == %d);'''
32
33example.wrap(apply_test[0],
34             ', mpl::int_<3>' + apply_test[1] % 45)
35compile() -->
36<p>The process of binding argument values to a subset of a function's
37parameters is known in the world of functional programming as
38<strong>partial function application</strong>.</p>
39</div>
40
41<div class="footer-separator"></div>
42<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Prev</a>&nbsp;<a href="./metafunction-composition.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group">Back&nbsp;<a href="./metafunction-composition.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Up</a>&nbsp;<a href="../index.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tutorial_toc.html" class="navigation-link">Full TOC</a></span></td>
43</tr></table></body>
44</html>
45