1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Chapter 32. Boost.Proto</title> 6<link rel="stylesheet" href="../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="libraries.html" title="Part I. The Boost C++ Libraries (BoostBook Subset)"> 10<link rel="prev" href="boost/property_tree/xml_parser/write_1_3_32_10_11_1_1_1_4.html" title="Function template write_xml"> 11<link rel="next" href="proto/users_guide.html" title="Users' Guide"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td> 16<td align="center"><a href="../../index.html">Home</a></td> 17<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="boost/property_tree/xml_parser/write_1_3_32_10_11_1_1_1_4.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> 25</div> 26<div class="chapter"> 27<div class="titlepage"><div> 28<div><h2 class="title"> 29<a name="proto"></a>Chapter 32. Boost.Proto</h2></div> 30<div><div class="author"><h3 class="author"> 31<span class="firstname">Eric</span> <span class="surname">Niebler</span> 32</h3></div></div> 33<div><p class="copyright">Copyright © 2008 Eric Niebler</p></div> 34<div><div class="legalnotice"> 35<a name="proto.legal"></a><p> 36 Distributed under the Boost Software License, Version 1.0. (See accompanying 37 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>) 38 </p> 39</div></div> 40</div></div> 41<div class="toc"> 42<p><b>Table of Contents</b></p> 43<dl class="toc"> 44<dt><span class="section"><a href="proto.html#boost_proto.preface">Preface</a></span></dt> 45<dt><span class="section"><a href="proto/users_guide.html">Users' Guide</a></span></dt> 46<dd><dl> 47<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.getting_started">Getting Started</a></span></dt> 48<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.front_end">Fronts Ends: Defining 49 Terminals and Non-Terminals of Your EDSL</a></span></dt> 50<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.intermediate_form">Intermediate 51 Form: Understanding and Introspecting Expressions</a></span></dt> 52<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.back_end">Back Ends: Making Expression 53 Templates Do Useful Work</a></span></dt> 54<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.examples">Examples</a></span></dt> 55<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.resources">Background and Resources</a></span></dt> 56<dt><span class="section"><a href="proto/users_guide.html#boost_proto.users_guide.glossary">Glossary</a></span></dt> 57</dl></dd> 58<dt><span class="section"><a href="proto/reference.html">Reference</a></span></dt> 59<dd><dl> 60<dt><span class="section"><a href="proto/reference.html#proto.concepts">Concepts</a></span></dt> 61<dt><span class="section"><a href="proto/reference.html#proto.reference.classes">Classes</a></span></dt> 62<dt><span class="section"><a href="proto/reference.html#proto.reference.functions">Functions</a></span></dt> 63<dt><span class="section"><a href="proto/reference.html#header.boost.proto.args_hpp">Header <boost/proto/args.hpp></a></span></dt> 64<dt><span class="section"><a href="proto/reference.html#header.boost.proto.core_hpp">Header <boost/proto/core.hpp></a></span></dt> 65<dt><span class="section"><a href="proto/reference.html#header.boost.proto.debug_hpp">Header <boost/proto/debug.hpp></a></span></dt> 66<dt><span class="section"><a href="proto/reference.html#header.boost.proto.deep_copy_hpp">Header <boost/proto/deep_copy.hpp></a></span></dt> 67<dt><span class="section"><a href="proto/reference.html#header.boost.proto.domain_hpp">Header <boost/proto/domain.hpp></a></span></dt> 68<dt><span class="section"><a href="proto/reference.html#header.boost.proto.eval_hpp">Header <boost/proto/eval.hpp></a></span></dt> 69<dt><span class="section"><a href="proto/reference.html#header.boost.proto.expr_hpp">Header <boost/proto/expr.hpp></a></span></dt> 70<dt><span class="section"><a href="proto/reference.html#header.boost.proto.extends_hpp">Header <boost/proto/extends.hpp></a></span></dt> 71<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional_hpp">Header <boost/proto/functional.hpp></a></span></dt> 72<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.fusion_hpp">Header <boost/proto/functional/fusion.hpp></a></span></dt> 73<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.fusion.at_hpp">Header <boost/proto/functional/fusion/at.hpp></a></span></dt> 74<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.fusion.pop_back_hpp">Header <boost/proto/functional/fusion/pop_back.hpp></a></span></dt> 75<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.fusion.pop_front_hpp">Header <boost/proto/functional/fusion/pop_front.hpp></a></span></dt> 76<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.fusion.push_back_hpp">Header <boost/proto/functional/fusion/push_back.hpp></a></span></dt> 77<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.fusion.push_front_hpp">Header <boost/proto/functional/fusion/push_front.hpp></a></span></dt> 78<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.fusion.reverse_hpp">Header <boost/proto/functional/fusion/reverse.hpp></a></span></dt> 79<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.range.begin_hpp">Header <boost/proto/functional/range/begin.hpp></a></span></dt> 80<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.range.empty_hpp">Header <boost/proto/functional/range/empty.hpp></a></span></dt> 81<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.range.end_hpp">Header <boost/proto/functional/range/end.hpp></a></span></dt> 82<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.range.rbegin_hpp">Header <boost/proto/functional/range/rbegin.hpp></a></span></dt> 83<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.range.rend_hpp">Header <boost/proto/functional/range/rend.hpp></a></span></dt> 84<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.range.size_hpp">Header <boost/proto/functional/range/size.hpp></a></span></dt> 85<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.std_hpp">Header <boost/proto/functional/std.hpp></a></span></dt> 86<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.std.iterator_hpp">Header <boost/proto/functional/std/iterator.hpp></a></span></dt> 87<dt><span class="section"><a href="proto/reference.html#header.boost.proto.functional.std.utility_hpp">Header <boost/proto/functional/std/utility.hpp></a></span></dt> 88<dt><span class="section"><a href="proto/reference.html#header.boost.proto.fusion_hpp">Header <boost/proto/fusion.hpp></a></span></dt> 89<dt><span class="section"><a href="proto/reference.html#header.boost.proto.generate_hpp">Header <boost/proto/generate.hpp></a></span></dt> 90<dt><span class="section"><a href="proto/reference.html#header.boost.proto.literal_hpp">Header <boost/proto/literal.hpp></a></span></dt> 91<dt><span class="section"><a href="proto/reference.html#header.boost.proto.make_expr_hpp">Header <boost/proto/make_expr.hpp></a></span></dt> 92<dt><span class="section"><a href="proto/reference.html#header.boost.proto.matches_hpp">Header <boost/proto/matches.hpp></a></span></dt> 93<dt><span class="section"><a href="proto/reference.html#header.boost.proto.operators_hpp">Header <boost/proto/operators.hpp></a></span></dt> 94<dt><span class="section"><a href="proto/reference.html#header.boost.proto.proto_hpp">Header <boost/proto/proto.hpp></a></span></dt> 95<dt><span class="section"><a href="proto/reference.html#header.boost.proto.proto_fwd_hpp">Header <boost/proto/proto_fwd.hpp></a></span></dt> 96<dt><span class="section"><a href="proto/reference.html#header.boost.proto.proto_typeof_hpp">Header <boost/proto/proto_typeof.hpp></a></span></dt> 97<dt><span class="section"><a href="proto/reference.html#header.boost.proto.repeat_hpp">Header <boost/proto/repeat.hpp></a></span></dt> 98<dt><span class="section"><a href="proto/reference.html#header.boost.proto.tags_hpp">Header <boost/proto/tags.hpp></a></span></dt> 99<dt><span class="section"><a href="proto/reference.html#header.boost.proto.traits_hpp">Header <boost/proto/traits.hpp></a></span></dt> 100<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform_hpp">Header <boost/proto/transform.hpp></a></span></dt> 101<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.arg_hpp">Header <boost/proto/transform/arg.hpp></a></span></dt> 102<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.call_hpp">Header <boost/proto/transform/call.hpp></a></span></dt> 103<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.default_hpp">Header <boost/proto/transform/default.hpp></a></span></dt> 104<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.env_hpp">Header <boost/proto/transform/env.hpp></a></span></dt> 105<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.fold_hpp">Header <boost/proto/transform/fold.hpp></a></span></dt> 106<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.fold_tree_hpp">Header <boost/proto/transform/fold_tree.hpp></a></span></dt> 107<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.impl_hpp">Header <boost/proto/transform/impl.hpp></a></span></dt> 108<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.integral_c_hpp">Header <boost/proto/transform/integral_c.hpp></a></span></dt> 109<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.lazy_hpp">Header <boost/proto/transform/lazy.hpp></a></span></dt> 110<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.make_hpp">Header <boost/proto/transform/make.hpp></a></span></dt> 111<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.pass_through_hpp">Header <boost/proto/transform/pass_through.hpp></a></span></dt> 112<dt><span class="section"><a href="proto/reference.html#header.boost.proto.transform.when_hpp">Header <boost/proto/transform/when.hpp></a></span></dt> 113<dt><span class="section"><a href="proto/reference.html#header.boost.proto.context_hpp">Header <boost/proto/context.hpp></a></span></dt> 114<dt><span class="section"><a href="proto/reference.html#header.boost.proto.context.callable_hpp">Header <boost/proto/context/callable.hpp></a></span></dt> 115<dt><span class="section"><a href="proto/reference.html#header.boost.proto.context.default_hpp">Header <boost/proto/context/default.hpp></a></span></dt> 116<dt><span class="section"><a href="proto/reference.html#header.boost.proto.context.null_hpp">Header <boost/proto/context/null.hpp></a></span></dt> 117</dl></dd> 118<dt><span class="section"><a href="proto/appendices.html">Appendices</a></span></dt> 119<dd><dl> 120<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.release_notes">Appendix A: Release 121 Notes</a></span></dt> 122<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.history">Appendix B: History</a></span></dt> 123<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.rationale">Appendix C: Rationale</a></span></dt> 124<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.implementation">Appendix D: Implementation 125 Notes</a></span></dt> 126<dt><span class="section"><a href="proto/appendices.html#boost_proto.appendices.acknowledgements">Appendix E: 127 Acknowledgements</a></span></dt> 128</dl></dd> 129</dl> 130</div> 131<div class="section"> 132<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 133<a name="boost_proto.preface"></a><a class="link" href="proto.html#boost_proto.preface" title="Preface">Preface</a> 134</h2></div></div></div> 135<div class="blockquote"><blockquote class="blockquote"><p> 136 <span class="quote">“<span class="quote">There are more things in heaven and earth, Horatio, than are dreamt 137 of in your philosophy.</span>”</span> 138 </p></blockquote></div> 139<div class="blockquote"><blockquote class="blockquote"><p> 140 <span class="bold"><strong><span class="emphasis"><em>-- William Shakespeare</em></span></strong></span> 141 </p></blockquote></div> 142<h4> 143<a name="boost_proto.preface.h0"></a> 144 <span class="phrase"><a name="boost_proto.preface.description"></a></span><a class="link" href="proto.html#boost_proto.preface.description">Description</a> 145 </h4> 146<p> 147 Proto is a framework for building Embedded Domain-Specific Languages in C++. 148 It provides tools for constructing, type-checking, transforming and executing 149 <span class="emphasis"><em>expression templates</em></span><a href="#ftn.boost_proto.preface.f0" class="footnote" name="boost_proto.preface.f0"><sup class="footnote">[33]</sup></a>. More specifically, Proto provides: 150 </p> 151<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 152<li class="listitem"> 153 An expression tree data structure. 154 </li> 155<li class="listitem"> 156 A mechanism for giving expressions additional behaviors and members. 157 </li> 158<li class="listitem"> 159 Operator overloads for building the tree from an expression. 160 </li> 161<li class="listitem"> 162 Utilities for defining the grammar to which an expression must conform. 163 </li> 164<li class="listitem"> 165 An extensible mechanism for immediately executing an expression template. 166 </li> 167<li class="listitem"> 168 An extensible set of tree transformations to apply to expression trees. 169 </li> 170</ul></div> 171<h4> 172<a name="boost_proto.preface.h1"></a> 173 <span class="phrase"><a name="boost_proto.preface.motivation"></a></span><a class="link" href="proto.html#boost_proto.preface.motivation">Motivation</a> 174 </h4> 175<p> 176 Expression Templates are an advanced technique that C++ library developers 177 use to define embedded mini-languages that target specific problem domains. 178 The technique has been used to create efficient and easy-to-use libraries for 179 linear algebra as well as to define C++ parser generators with a readable syntax. 180 But developing such a library involves writing an inordinate amount of unreadable 181 and unmaintainable template mumbo-jumbo. Boost.Proto eases the development 182 of <a class="link" href="proto/users_guide.html#boost_proto.users_guide.glossary.edsl">domain-specific embedded 183 languages (EDSLs)</a>. Use Proto to define the primitives of your mini-language 184 and let Proto handle the operator overloading and the construction of the expression 185 parse tree. Immediately evaluate the expression tree by passing it a function 186 object. Or transform the expression tree by defining the grammar of your mini-language, 187 decorated with an assortment of tree transforms provided by Proto or defined 188 by you. Then use the grammar to give your users short and readable syntax errors 189 for invalid expressions! No more mumbo-jumbo -- an expression template library 190 developed with Proto is declarative and readable. 191 </p> 192<p> 193 In short, Proto is an EDSL for defining EDSLs. 194 </p> 195<h4> 196<a name="boost_proto.preface.h2"></a> 197 <span class="phrase"><a name="boost_proto.preface.how_to_use_this_documentation"></a></span><a class="link" href="proto.html#boost_proto.preface.how_to_use_this_documentation">How 198 to Use This Documentation</a> 199 </h4> 200<p> 201 This documentation makes use of the following naming and formatting conventions. 202 </p> 203<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 204<li class="listitem"> 205 Code is in <code class="computeroutput"><span class="identifier">fixed</span> <span class="identifier">width</span> 206 <span class="identifier">font</span></code> and is syntax-highlighted. 207 </li> 208<li class="listitem"> 209 Replaceable text that you will need to supply is in <em class="replaceable"><code>italics</code></em>. 210 </li> 211<li class="listitem"> 212 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>; 213 that is, it is in code font and its name is followed by <code class="computeroutput"><span class="special">()</span></code> 214 to indicate that it is a free function. 215 </li> 216<li class="listitem"> 217 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"><></span></code>; 218 that is, it is in code font and its name is followed by <code class="computeroutput"><span class="special"><></span></code> 219 to indicate that it is a class template. 220 </li> 221<li class="listitem"> 222 If a name refers to a function-like macro, it is specified like this: 223 <code class="computeroutput"><span class="identifier">MACRO</span><span class="special">()</span></code>; 224 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 225 macro. Object-like macros appear without the trailing <code class="computeroutput"><span class="special">()</span></code>. 226 </li> 227<li class="listitem"> 228 Names that refer to <span class="emphasis"><em>concepts</em></span> in the generic programming 229 sense are specified in CamelCase. 230 </li> 231</ul></div> 232<div class="note"><table border="0" summary="Note"> 233<tr> 234<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../doc/src/images/note.png"></td> 235<th align="left">Note</th> 236</tr> 237<tr><td align="left" valign="top"><p> 238 In addition, notes such as this one specify non-essential information that 239 provides additional background or rationale. 240 </p></td></tr> 241</table></div> 242<p> 243 Finally, you can mentally add the following to any code fragments in this document: 244 </p> 245<pre class="programlisting"><span class="comment">// Include all of Proto</span> 246<span class="preprocessor">#include</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="identifier">proto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 247 248<span class="comment">// Create some namespace aliases</span> 249<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> 250<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> 251<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> 252 253<span class="comment">// Allow unqualified use of Proto's wildcard pattern</span> 254<span class="keyword">using</span> <span class="identifier">proto</span><span class="special">::</span><span class="identifier">_</span><span class="special">;</span> 255</pre> 256</div> 257<div class="footnotes"> 258<br><hr style="width:100; text-align:left;margin-left: 0"> 259<div id="ftn.boost_proto.preface.f0" class="footnote"><p><a href="#boost_proto.preface.f0" class="para"><sup class="para">[33] </sup></a> 260 See <a href="http://en.wikipedia.org/wiki/Expression_templates" target="_top">Expression 261 Templates</a> 262 </p></div> 263</div> 264</div> 265<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 266<td align="left"><p><small>Last revised: August 11, 2020 at 15:03:11 GMT</small></p></td> 267<td align="right"><div class="copyright-footer"></div></td> 268</tr></table> 269<hr> 270<div class="spirit-nav"> 271<a accesskey="p" href="boost/property_tree/xml_parser/write_1_3_32_10_11_1_1_1_4.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> 272</div> 273</body> 274</html> 275