<p>Division is similar to multiplication, but instead of adding
exponents, we must subtract them. Rather than writing out a near
duplicate of <ttclass="literal"><spanclass="pre">plus_f</span></tt>, we can use the following trick to make
<ttclass="literal"><spanclass="pre">minus_f</span></tt> much simpler:</p>
<preclass="literal-block">
struct minus_f
{
template <class T1, class T2>
struct apply
: mpl::minus<T1,T2> {};
};
</pre>
<!-- @ # The following is OK because we showed how to get at mpl_plus
prefix.append('#include <boost/mpl/minus.hpp>')
compile(1) -->
<p>Here <ttclass="literal"><spanclass="pre">minus_f::apply</span></tt> uses inheritance to expose the nested
<ttclass="literal"><spanclass="pre">type</span></tt> of its base class, <ttclass="literal"><spanclass="pre">mpl::minus</span></tt>, so we don't have to
write:</p>
<preclass="literal-block">
typedef typename ...::type type
</pre>
<!-- @ignore() -->
<p>We don't have to write
<ttclass="literal"><spanclass="pre">typename</span></tt> here (in fact, it would be illegal), because the
compiler knows that dependent names in <ttclass="literal"><spanclass="pre">apply</span></tt>'s initializer
list must be base classes. <aclass="footnote-reference"href="#plus-too"id="id7"name="id7">[2]</a> This powerful
simplification is known as <strong>metafunction forwarding</strong>; we'll apply
it often as the book goes on. <aclass="footnote-reference"href="#edg"id="id8"name="id8">[3]</a></p>
<tr><tdclass="label"><aclass="fn-backref"href="#id8"name="edg">[3]</a></td><td>Users of EDG-based compilers should consult <aclass="reference"href="./resources.html">the book's</a> Appendix C
for a caveat about metafunction forwarding. You can tell whether
you have an EDG compiler by checking the preprocessor symbol
<ttclass="literal"><spanclass="pre">__EDG_VERSION__</span></tt>, which is defined by all EDG-based compilers.</td></tr>
</tbody>
</table>
<p>Syntactic tricks notwithstanding, writing trivial classes to wrap
existing metafunctions is going to get boring pretty quickly. Even
though the definition of <ttclass="literal"><spanclass="pre">minus_f</span></tt> was far less verbose than that
of <ttclass="literal"><spanclass="pre">plus_f</span></tt>, it's still an awful lot to type. Fortunately, MPL gives
us a <em>much</em> simpler way to pass metafunctions around. Instead of
building a whole metafunction class, we can invoke <ttclass="literal"><spanclass="pre">transform</span></tt>
# We explain placeholders below, so we can henceforth use them
# without qualification -->
<p>Those funny looking arguments (<ttclass="literal"><spanclass="pre">_1</span></tt> and <ttclass="literal"><spanclass="pre">_2</span></tt>) are known as
<strong>placeholders</strong>, and they signify that when the <ttclass="literal"><spanclass="pre">transform</span></tt>'s
<ttclass="literal"><spanclass="pre">BinaryOperation</span></tt> is invoked, its first and second arguments will
be passed on to <ttclass="literal"><spanclass="pre">minus</span></tt> in the positions indicated by <ttclass="literal"><spanclass="pre">_1</span></tt> and
<ttclass="literal"><spanclass="pre">_2</span></tt>, respectively. The whole type <ttclass="literal"><spanclass="pre">mpl::minus<_1,_2></span></tt> is
known as a <strong>placeholder expression</strong>.</p>
<divclass="note">
<pclass="admonition-title first">Note</p>
<p>MPL's placeholders are in the <ttclass="literal"><spanclass="pre">mpl::placeholders</span></tt>
namespace and defined in <ttclass="literal"><spanclass="pre">boost/mpl/placeholders.hpp</span></tt>. In
this book we will usually assume that you have written:</p>
<preclass="literal-block">
#include<boost/mpl/placeholders.hpp>
using namespace mpl::placeholders;
</pre>
<p>so that they can be accessed without qualification.</p>
</div>
<!-- @ prefix.append(str(example)) # move to common prefix
ignore() -->
<p>Here's our division operator written using placeholder
dimensional_analysis = stack[:-1] # save for later
run('all') -->
<p>If we got everything right, <ttclass="literal"><spanclass="pre">rounding_error</span></tt> should be very close
to zero. These are boring calculations, but they're just the sort
of thing that could ruin a whole program (or worse) if you got them
wrong. If we had written <ttclass="literal"><spanclass="pre">a/f</span></tt> instead of <ttclass="literal"><spanclass="pre">f/a</span></tt>, there would have
been a compilation error, preventing a mistake from propagating