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>Concepts</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="../yap.html" title="Chapter 47. Boost.YAP"> 10<link rel="prev" href="manual.html" title="Manual"> 11<link rel="next" href="compiler_support.html" title="Compiler Support"> 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="manual.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../yap.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="compiler_support.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="boost_yap.concepts"></a><a class="link" href="concepts.html" title="Concepts">Concepts</a> 29</h2></div></div></div> 30<h4> 31<a name="boost_yap.concepts.h0"></a> 32 <span class="phrase"><a name="boost_yap.concepts.expression"></a></span><a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a> 33 </h4> 34<p> 35 <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a> is the central 36 concept in Boost.YAP. It must contain at least an <code class="computeroutput"><a class="link" href="../boost/yap/expr_kind.html" title="Type expr_kind">expr_kind</a></code> and a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">hana</span><span class="special">::</span><span class="identifier">tuple</span><span class="special"><></span></code> 37 of values. 38 </p> 39<p> 40 Here is a summary of the requirements on <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>. 41 In the tables below, <code class="computeroutput"><span class="identifier">E</span></code> is a 42 type that models <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>; 43 <code class="computeroutput"><span class="identifier">e</span></code> is an object of type <code class="computeroutput"><span class="identifier">E</span></code>; <code class="computeroutput"><span class="identifier">Tuple</span></code> 44 is an instantiation of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">hana</span><span class="special">::</span><span class="identifier">tuple</span><span class="special"><></span></code>; 45 and <code class="computeroutput"><span class="identifier">t</span></code> is an object of type 46 <code class="computeroutput"><span class="identifier">Tuple</span></code>. 47 </p> 48<div class="table"> 49<a name="boost_yap.concepts.expression_requirements"></a><p class="title"><b>Table 47.6. Expression Requirements</b></p> 50<div class="table-contents"><table class="table" summary="Expression Requirements"> 51<colgroup> 52<col> 53<col> 54<col> 55<col> 56</colgroup> 57<thead><tr> 58<th> 59 <p> 60 Expression 61 </p> 62 </th> 63<th> 64 <p> 65 Type 66 </p> 67 </th> 68<th> 69 <p> 70 Description 71 </p> 72 </th> 73<th> 74 <p> 75 Notes 76 </p> 77 </th> 78</tr></thead> 79<tbody> 80<tr> 81<td> 82 <p> 83 <code class="computeroutput"><span class="identifier">E</span><span class="special">::</span><span class="identifier">kind</span></code> 84 </p> 85 </td> 86<td> 87 <p> 88 <code class="computeroutput"><a class="link" href="../boost/yap/expr_kind.html" title="Type expr_kind">expr_kind</a></code> 89 </p> 90 </td> 91<td> 92 <p> 93 The kind of expression <code class="computeroutput"><span class="identifier">E</span></code> 94 is. 95 </p> 96 </td> 97<td> 98 <p> 99 Must be a compile-time constant. 100 </p> 101 </td> 102</tr> 103<tr> 104<td> 105 <p> 106 <code class="computeroutput"><span class="identifier">e</span><span class="special">.</span><span class="identifier">elements</span></code> 107 </p> 108 </td> 109<td> 110 <p> 111 <code class="computeroutput"><span class="identifier">Tuple</span></code> 112 </p> 113 </td> 114<td> 115 <p> 116 The child expressions of <code class="computeroutput"><span class="identifier">e</span></code>. 117 </p> 118 </td> 119<td> 120 <p> 121 The types of the elements must be appropriate to the kind of the 122 expression. 123 </p> 124 </td> 125</tr> 126<tr> 127<td> 128 <p> 129 <code class="computeroutput"><span class="identifier">E</span> <span class="identifier">e</span><span class="special">{</span><span class="identifier">t</span><span class="special">}</span></code> 130 </p> 131 </td> 132<td> 133 </td> 134<td> 135 <p> 136 Construction/initialization of <code class="computeroutput"><span class="identifier">e</span></code>. 137 </p> 138 </td> 139<td> 140 <p> 141 <code class="computeroutput"><span class="identifier">t</span></code> must be stored 142 in <code class="computeroutput"><span class="identifier">e</span><span class="special">.</span><span class="identifier">elements</span></code>. 143 </p> 144 </td> 145</tr> 146</tbody> 147</table></div> 148</div> 149<br class="table-break"><p> 150 As stated above, the <code class="computeroutput"><span class="identifier">elements</span></code> 151 data member must match the kind of the expression: 152 </p> 153<div class="table"> 154<a name="boost_yap.concepts.expression_requirements0"></a><p class="title"><b>Table 47.7. Expression Requirements</b></p> 155<div class="table-contents"><table class="table" summary="Expression Requirements"> 156<colgroup> 157<col> 158<col> 159<col> 160<col> 161</colgroup> 162<thead><tr> 163<th> 164 <p> 165 <code class="computeroutput"><span class="identifier">E</span><span class="special">::</span><span class="identifier">kind</span></code> 166 </p> 167 </th> 168<th> 169 <p> 170 <code class="computeroutput"><span class="identifier">hana</span><span class="special">::</span><span class="identifier">size</span><span class="special">(</span><span class="identifier">e</span><span class="special">.</span><span class="identifier">elements</span><span class="special">)</span></code> 171 </p> 172 </th> 173<th> 174 <p> 175 Possible Tuple Element Types 176 </p> 177 </th> 178<th> 179 <p> 180 Notes 181 </p> 182 </th> 183</tr></thead> 184<tbody> 185<tr> 186<td> 187 <p> 188 <code class="computeroutput"><span class="identifier">expr_kind</span><span class="special">::</span><span class="identifier">expr_ref</span></code> 189 </p> 190 </td> 191<td> 192 <p> 193 1 194 </p> 195 </td> 196<td> 197 <p> 198 Any non-<a class="link" href="../boost/yap/expr_kind.html#boost.yap.expr_kind.expr_ref"><code class="computeroutput"><span class="identifier">expr_kind</span><span class="special">::</span><span class="identifier">expr_ref</span></code></a> <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>. 199 </p> 200 </td> 201<td> 202 </td> 203</tr> 204<tr> 205<td> 206 <p> 207 <code class="computeroutput"><span class="identifier">expr_kind</span><span class="special">::</span><span class="identifier">terminal</span></code> 208 </p> 209 </td> 210<td> 211 <p> 212 1 213 </p> 214 </td> 215<td> 216 <p> 217 Any non-<a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>. 218 </p> 219 </td> 220<td> 221 <p> 222 A terminal with a <code class="computeroutput"><a class="link" href="../boost/yap/placeholder.html" title="Struct template placeholder">placeholder<></a></code> 223 value will be treated as a placeholder. 224 </p> 225 </td> 226</tr> 227<tr> 228<td> 229 <p> 230 Any unary operator 231 </p> 232 </td> 233<td> 234 <p> 235 1 236 </p> 237 </td> 238<td> 239 <p> 240 Any <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>. 241 </p> 242 </td> 243<td> 244 </td> 245</tr> 246<tr> 247<td> 248 <p> 249 Any binary operator 250 </p> 251 </td> 252<td> 253 <p> 254 2 255 </p> 256 </td> 257<td> 258 <p> 259 Any <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>. 260 </p> 261 </td> 262<td> 263 </td> 264</tr> 265<tr> 266<td> 267 <p> 268 <code class="computeroutput"><span class="identifier">expr_kind</span><span class="special">::</span><span class="identifier">if_else</span></code> 269 </p> 270 </td> 271<td> 272 <p> 273 3 274 </p> 275 </td> 276<td> 277 <p> 278 Any <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>. 279 </p> 280 </td> 281<td> 282 </td> 283</tr> 284<tr> 285<td> 286 <p> 287 <code class="computeroutput"><span class="identifier">expr_kind</span><span class="special">::</span><span class="identifier">call</span></code> 288 </p> 289 </td> 290<td> 291 <p> 292 Any number >= 1. 293 </p> 294 </td> 295<td> 296 <p> 297 Any <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>. 298 </p> 299 </td> 300<td> 301 </td> 302</tr> 303</tbody> 304</table></div> 305</div> 306<br class="table-break"><h4> 307<a name="boost_yap.concepts.h1"></a> 308 <span class="phrase"><a name="boost_yap.concepts.expressiontemplate"></a></span><a class="link" href="concepts.html#boost_yap.concepts.expressiontemplate">ExpressionTemplate</a> 309 </h4> 310<p> 311 <a class="link" href="concepts.html#boost_yap.concepts.expressiontemplate">ExpressionTemplate</a> 312 is any template with two parameters that, when instantiated with an <code class="computeroutput"><a class="link" href="../boost/yap/expr_kind.html" title="Type expr_kind">expr_kind</a></code> 313 and a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">hana</span><span class="special">::</span><span class="identifier">tuple</span><span class="special"><></span></code>, results in an <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>. 314 </p> 315<h4> 316<a name="boost_yap.concepts.h2"></a> 317 <span class="phrase"><a name="boost_yap.concepts.transform"></a></span><a class="link" href="concepts.html#boost_yap.concepts.transform">Transform</a> 318 </h4> 319<p> 320 <code class="computeroutput"><a class="link" href="../boost/yap/transform.html" title="Function template transform">transform()</a></code> takes a <a class="link" href="concepts.html#boost_yap.concepts.transform">Transform</a> 321 as its second parameter. A <a class="link" href="concepts.html#boost_yap.concepts.transform">Transform</a> 322 is a <a href="http://en.cppreference.com/w/cpp/concept/Callable" target="_top">Callable</a> 323 that takes expressions and returns values of unconstrained type. There are 324 two sorts of overloads <a class="link" href="concepts.html#boost_yap.concepts.transform">Transform</a> 325 may use: <a class="link" href="concepts.html#boost_yap.concepts.expressiontransform">ExpressionTransform</a> 326 and <a class="link" href="concepts.html#boost_yap.concepts.tagtransform">TagTransform</a>. 327 </p> 328<p> 329 A <a class="link" href="concepts.html#boost_yap.concepts.transform">Transform</a> may have any 330 number of overloads, including none. 331 </p> 332<h4> 333<a name="boost_yap.concepts.h3"></a> 334 <span class="phrase"><a name="boost_yap.concepts.expressiontransform"></a></span><a class="link" href="concepts.html#boost_yap.concepts.expressiontransform">ExpressionTransform</a> 335 </h4> 336<p> 337 <a class="link" href="concepts.html#boost_yap.concepts.expressiontransform">ExpressionTransform</a> 338 takes an <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a> as 339 its only parameter. Here are some examples. 340 </p> 341<p> 342 This one takes any <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a>: 343 </p> 344<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">xform</span> 345<span class="special">{</span> 346 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">></span> 347 <span class="keyword">auto</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span><span class="identifier">Expr</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">expr</span><span class="special">)</span> 348 <span class="special">{</span> 349 <span class="comment">// ...</span> 350 <span class="special">}</span> 351<span class="special">};</span> 352</pre> 353<p> 354 This one takes any type of <a class="link" href="concepts.html#boost_yap.concepts.expression">Expression</a> 355 that satisfies the constraints imposed by its template parameters: 356 </p> 357<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Expr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr2</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr3</span><span class="special">></span> 358<span class="keyword">decltype</span><span class="special">(</span><span class="keyword">auto</span><span class="special">)</span> <span class="identifier">xform</span> <span class="special">(</span> 359 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">yap</span><span class="special">::</span><span class="identifier">expression</span><span class="special"><</span> 360 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">yap</span><span class="special">::</span><span class="identifier">expr_kind</span><span class="special">::</span><span class="identifier">plus</span><span class="special">,</span> 361 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">hana</span><span class="special">::</span><span class="identifier">tuple</span><span class="special"><</span> 362 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">yap</span><span class="special">::</span><span class="identifier">expression</span><span class="special"><</span> 363 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">yap</span><span class="special">::</span><span class="identifier">expr_kind</span><span class="special">::</span><span class="identifier">multiplies</span><span class="special">,</span> 364 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">hana</span><span class="special">::</span><span class="identifier">tuple</span><span class="special"><</span> 365 <span class="identifier">Expr1</span><span class="special">,</span> 366 <span class="identifier">Expr2</span> 367 <span class="special">></span> 368 <span class="special">>,</span> 369 <span class="identifier">Expr3</span> 370 <span class="special">></span> 371 <span class="special">></span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">expr</span> 372<span class="special">)</span> <span class="special">{</span> 373 <span class="comment">// ...</span> 374<span class="special">}</span> 375</pre> 376<p> 377 This one takes only a specific type: 378 </p> 379<pre class="programlisting"><span class="keyword">decltype</span><span class="special">(</span><span class="keyword">auto</span><span class="special">)</span> <span class="identifier">xform</span> <span class="special">(</span> 380 <span class="keyword">decltype</span><span class="special">(</span><span class="identifier">term</span><span class="special"><</span><span class="identifier">number</span><span class="special">>{{</span><span class="number">0.0</span><span class="special">}}</span> <span class="special">*</span> <span class="identifier">number</span><span class="special">{}</span> <span class="special">+</span> <span class="identifier">number</span><span class="special">{})</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">expr</span> 381<span class="special">)</span> <span class="special">{</span> 382 <span class="comment">// ...</span> 383<span class="special">}</span> 384</pre> 385<h4> 386<a name="boost_yap.concepts.h4"></a> 387 <span class="phrase"><a name="boost_yap.concepts.tagtransform"></a></span><a class="link" href="concepts.html#boost_yap.concepts.tagtransform">TagTransform</a> 388 </h4> 389<p> 390 <a class="link" href="concepts.html#boost_yap.concepts.tagtransform">TagTransform</a> takes a 391 tag-type as its first parameter, and the individual elements of an expression 392 as the remaining parameters. 393 </p> 394<p> 395 Tags are named such that the tag for an expression with <code class="computeroutput"><a class="link" href="../boost/yap/expr_kind.html" title="Type expr_kind">expr_kind</a></code> <code class="computeroutput"><span class="identifier">expr_kind</span><span class="special">::</span><span class="identifier">foo</span></code> is 396 named <code class="computeroutput"><span class="identifier">foo_tag</span></code>. Here are some 397 examples. 398 </p> 399<p> 400 This one takes any terminal that contains a <code class="computeroutput"><span class="identifier">user</span><span class="special">::</span><span class="identifier">number</span></code> 401 (or reference to such a terminal): 402 </p> 403<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">xform</span> 404<span class="special">{</span> 405 <span class="keyword">decltype</span><span class="special">(</span><span class="keyword">auto</span><span class="special">)</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">yap</span><span class="special">::</span><span class="identifier">terminal_tag</span><span class="special">,</span> <span class="identifier">user</span><span class="special">::</span><span class="identifier">number</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">n</span><span class="special">)</span> 406 <span class="special">{</span> 407 <span class="comment">// ...</span> 408 <span class="special">}</span> 409<span class="special">};</span> 410</pre> 411<p> 412 This one takes any plus expression that contains a pair of <code class="computeroutput"><span class="identifier">user</span><span class="special">::</span><span class="identifier">number</span></code> 413 terminals (or references to terminals): 414 </p> 415<pre class="programlisting"><span class="keyword">decltype</span><span class="special">(</span><span class="keyword">auto</span><span class="special">)</span> <span class="identifier">xform</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">yap</span><span class="special">::</span><span class="identifier">plus_tag</span><span class="special">,</span> <span class="identifier">user</span><span class="special">::</span><span class="identifier">number</span> <span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">user</span><span class="special">::</span><span class="identifier">number</span> <span class="identifier">rhs</span><span class="special">)</span> 416<span class="special">{</span> 417 <span class="comment">// ...</span> 418<span class="special">}</span> 419</pre> 420<p> 421 This one takes any negation expression: 422 </p> 423<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">xform</span> 424<span class="special">{</span> 425 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">></span> 426 <span class="keyword">decltype</span><span class="special">(</span><span class="keyword">auto</span><span class="special">)</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">yap</span><span class="special">::</span><span class="identifier">negate_tag</span><span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">expr</span><span class="special">)</span> 427 <span class="special">{</span> 428 <span class="comment">// ...</span> 429 <span class="special">}</span> 430<span class="special">};</span> 431</pre> 432<p> 433 This one takes any call expression with two terminals (or references to terminals) 434 containing values convertible to <code class="computeroutput"><span class="keyword">double</span></code>: 435 </p> 436<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">xform</span> 437<span class="special">{</span> 438 <span class="keyword">decltype</span><span class="special">(</span><span class="keyword">auto</span><span class="special">)</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">yap</span><span class="special">::</span><span class="identifier">call_tag</span><span class="special">,</span> <span class="identifier">tag_type</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">b</span><span class="special">)</span> 439 <span class="special">{</span> 440 <span class="comment">// ...</span> 441 <span class="special">}</span> 442<span class="special">}</span> 443</pre> 444</div> 445<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 446<td align="left"></td> 447<td align="right"><div class="copyright-footer">Copyright © 2018 T. Zachary Laine<p> 448 Distributed under the Boost Software License, Version 1.0. (See accompanying 449 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>) 450 </p> 451</div></td> 452</tr></table> 453<hr> 454<div class="spirit-nav"> 455<a accesskey="p" href="manual.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../yap.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="compiler_support.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 456</div> 457</body> 458</html> 459