blob: 50e8b6079e96d4a3a1cb6abc630ac473554d2226 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;15.&#160;Boost.Proto</title>
<link rel="stylesheet" href="../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="libraries.html" title="Part&#160;I.&#160;The Boost C++ Libraries (BoostBook Subset)">
<link rel="prev" href="boost/property_tree/xml_parser/write_xml_id898989.html" title="Function template write_xml">
<link rel="next" href="proto/users_guide.html" title="Users' Guide">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td>
<td align="center"><a href="../../index.html">Home</a></td>
<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost/property_tree/xml_parser/write_xml_id898989.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="proto/users_guide.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div>
<div><h2 class="title">
<a name="proto"></a>Chapter&#160;15.&#160;Boost.Proto</h2></div>
<div><div class="author"><h3 class="author">
<span class="firstname">Eric</span> <span class="surname">Niebler</span>
</h3></div></div>
<div><p class="copyright">Copyright &#169; 2008 Eric Niebler</p></div>
<div><div class="legalnotice">
<a name="id2147997"></a><p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></div>
</div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="section"><a href="proto.html#boost_proto.preface">Preface</a></span></dt>
<dt><span class="section"><a href="proto/users_guide.html">Users' Guide</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.getting_started">Getting Started</a></span></dt>
<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.front_end">Fronts Ends: Defining
Terminals and Non-Terminals of Your DSEL</a></span></dt>
<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.intermediate_form">Intermediate
Form: Understanding and Introspecting Expressions</a></span></dt>
<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.back_end">Back Ends: Making Expression
Templates Do Useful Work</a></span></dt>
<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.examples">Examples</a></span></dt>
<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.resources">Background and Resources</a></span></dt>
<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.glossary">Glossary</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="proto/reference.html">Reference</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="proto/reference.html#proto.concepts">Concepts</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#proto.reference.classes">Classes</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#proto.reference.functions">Functions</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.args_hpp">Header &lt;boost/proto/args.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.core_hpp">Header &lt;boost/proto/core.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.debug_hpp">Header &lt;boost/proto/debug.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.deep_copy_hpp">Header &lt;boost/proto/deep_copy.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.domain_hpp">Header &lt;boost/proto/domain.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.eval_hpp">Header &lt;boost/proto/eval.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.expr_hpp">Header &lt;boost/proto/expr.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.extends_hpp">Header &lt;boost/proto/extends.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.fusion_hpp">Header &lt;boost/proto/fusion.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.generate_hpp">Header &lt;boost/proto/generate.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.literal_hpp">Header &lt;boost/proto/literal.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.make_expr_hpp">Header &lt;boost/proto/make_expr.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.matches_hpp">Header &lt;boost/proto/matches.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.operators_hpp">Header &lt;boost/proto/operators.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.proto_hpp">Header &lt;boost/proto/proto.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.proto_fwd_hpp">Header &lt;boost/proto/proto_fwd.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.proto_typeof_hpp">Header &lt;boost/proto/proto_typeof.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.repeat_hpp">Header &lt;boost/proto/repeat.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.tags_hpp">Header &lt;boost/proto/tags.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.traits_hpp">Header &lt;boost/proto/traits.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.arg_hpp">Header &lt;boost/proto/transform/arg.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.call_hpp">Header &lt;boost/proto/transform/call.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.default_hpp">Header &lt;boost/proto/transform/default.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.fold_hpp">Header &lt;boost/proto/transform/fold.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.fold_tree_hpp">Header &lt;boost/proto/transform/fold_tree.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.impl_hpp">Header &lt;boost/proto/transform/impl.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.lazy_hpp">Header &lt;boost/proto/transform/lazy.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.make_hpp">Header &lt;boost/proto/transform/make.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.pass_through_hpp">Header &lt;boost/proto/transform/pass_through.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.when_hpp">Header &lt;boost/proto/transform/when.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.context.callable_hpp">Header &lt;boost/proto/context/callable.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.context.default_hpp">Header &lt;boost/proto/context/default.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="proto/reference.html#header.boost.proto.context.null_hpp">Header &lt;boost/proto/context/null.hpp&gt;</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="proto/appendices.html">Appendices</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.release_notes">Appendix A: Release
Notes</a></span></dt>
<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.history">Appendix B: History</a></span></dt>
<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.rationale">Appendix C: Rationale</a></span></dt>
<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.implementation">Appendix D: Implementation
Notes</a></span></dt>
<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.acknowledgements">Appendix E:
Acknowledgements</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_proto.preface"></a><a class="link" href="proto.html#boost_proto.preface" title="Preface">Preface</a>
</h2></div></div></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="quote">&#8220;<span class="quote">There are more things in heaven and earth, Horatio, than are dreamt
of in your philosophy.</span>&#8221;</span>
</p></blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="bold"><strong><span class="emphasis"><em>-- William Shakespeare</em></span></strong></span>
</p></blockquote></div>
<a name="boost_proto.preface.description"></a><h4>
<a name="id2148063"></a>
<a class="link" href="proto.html#boost_proto.preface.description">Description</a>
</h4>
<p>
Proto is a framework for building Domain Specific Embedded Languages in C++.
It provides tools for constructing, type-checking, transforming and executing
<span class="emphasis"><em>expression templates</em></span><sup>[<a name="id2148083" href="#ftn.id2148083" class="footnote">2</a>]</sup>. More specifically, Proto provides:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
An expression tree data structure.
</li>
<li class="listitem">
A mechanism for giving expressions additional behaviors and members.
</li>
<li class="listitem">
Operator overloads for building the tree from an expression.
</li>
<li class="listitem">
Utilities for defining the grammar to which an expression must conform.
</li>
<li class="listitem">
An extensible mechanism for immediately executing an expression template.
</li>
<li class="listitem">
An extensible set of tree transformations to apply to expression trees.
</li>
</ul></div>
<a name="boost_proto.preface.motivation"></a><h4>
<a name="id2148156"></a>
<a class="link" href="proto.html#boost_proto.preface.motivation">Motivation</a>
</h4>
<p>
Expression Templates are an advanced technique that C++ library developers
use to define embedded mini-languages that target specific problem domains.
The technique has been used to create efficient and easy-to-use libraries for
linear algebra as well as to define C++ parser generators with a readable syntax.
But developing such a library involves writing an inordinate amount of unreadable
and unmaintainable template mumbo-jumbo. Boost.Proto eases the development
of <a class="link" href="proto/users_guide.html#boost_proto.users_guide.glossary.dsel">domain-specific embedded
languages (DSELs)</a>. Use Proto to define the primitives of your mini-language
and let Proto handle the operator overloading and the construction of the expression
parse tree. Immediately evaluate the expression tree by passing it a function
object. Or transform the expression tree by defining the grammar of your mini-language,
decorated with an assortment of tree transforms provided by Proto or defined
by you. Then use the grammar to give your users short and readable syntax errors
for invalid expressions! No more mumbo-jumbo -- an expression template library
developed with Proto is declarative and readable.
</p>
<p>
In short, Proto is a DSEL for defining DSELs.
</p>
<a name="boost_proto.preface.how_to_use_this_documentation"></a><h4>
<a name="id2148193"></a>
<a class="link" href="proto.html#boost_proto.preface.how_to_use_this_documentation">How to Use
This Documentation</a>
</h4>
<p>
This documentation makes use of the following naming and formatting conventions.
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
Code is in <code class="computeroutput"><span class="identifier">fixed</span> <span class="identifier">width</span>
<span class="identifier">font</span></code> and is syntax-highlighted.
</li>
<li class="listitem">
Replaceable text that you will need to supply is in <em class="replaceable"><code>italics</code></em>.
</li>
<li class="listitem">
If a name refers to a free function, it is specified like this: <code class="computeroutput"><span class="identifier">free_function</span><span class="special">()</span></code>;
that is, it is in code font and its name is followed by <code class="computeroutput"><span class="special">()</span></code>
to indicate that it is a free function.
</li>
<li class="listitem">
If a name refers to a class template, it is specified like this: <code class="computeroutput"><span class="identifier">class_template</span><span class="special">&lt;&gt;</span></code>;
that is, it is in code font and its name is followed by <code class="computeroutput"><span class="special">&lt;&gt;</span></code>
to indicate that it is a class template.
</li>
<li class="listitem">
If a name refers to a function-like macro, it is specified like this:
<code class="computeroutput"><span class="identifier">MACRO</span><span class="special">()</span></code>;
that is, it is uppercase in code font and its name is followed by <code class="computeroutput"><span class="special">()</span></code> to indicate that it is a function-like
macro. Object-like macros appear without the trailing <code class="computeroutput"><span class="special">()</span></code>.
</li>
<li class="listitem">
Names that refer to <span class="emphasis"><em>concepts</em></span> in the generic programming
sense are specified in CamelCase.
</li>
</ul></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
In addition, notes such as this one specify non-essential information that
provides additional background or rationale.
</p></td></tr>
</table></div>
<p>
Finally, you can mentally add the following to any code fragments in this document:
</p>
<pre class="programlisting"><span class="comment">// Include all of Proto
</span><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">proto</span><span class="special">/</span><span class="identifier">proto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="comment">// Create some namespace aliases
</span><span class="keyword">namespace</span> <span class="identifier">mpl</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">fusion</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">fusion</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">proto</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">proto</span><span class="special">;</span>
<span class="comment">// Allow unqualified use of Proto's wildcard pattern
</span><span class="keyword">using</span> <span class="identifier">proto</span><span class="special">::</span><span class="identifier">_</span><span class="special">;</span>
</pre>
</div>
<div class="footnotes">
<br><hr width="100" align="left">
<div class="footnote"><p><sup>[<a name="ftn.id2148083" href="#id2148083" class="para">2</a>] </sup>
See <a href="http://www.osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html" target="_top">Expression
Templates</a>
</p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: November 10, 2010 at 00:45:08 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost/property_tree/xml_parser/write_xml_id898989.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="proto/users_guide.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>