Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / contract / doc / html / boost / contract / call_if.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Function template call_if</title>
5 <link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Chapter&#160;1.&#160;Boost.Contract 1.0.0">
8 <link rel="up" href="../../reference.html#header.boost.contract.call_if_hpp" title="Header &lt;boost/contract/call_if.hpp&gt;">
9 <link rel="prev" href="call_if_c.html" title="Function template call_if_c">
10 <link rel="next" href="condition_if_c.html" title="Function template condition_if_c">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="call_if_c.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.call_if_hpp"><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="condition_if_c.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="refentry">
26 <a name="boost.contract.call_if"></a><div class="titlepage"></div>
27 <div class="refnamediv">
28 <h2><span class="refentrytitle">Function template call_if</span></h2>
29 <p>boost::contract::call_if &#8212; Select compilation and execution of functor template calls using a nullary boolean meta-function (not needed on C++17 compilers, use <code class="computeroutput">if constexpr</code> instead). </p>
30 </div>
31 <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
32 <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../reference.html#header.boost.contract.call_if_hpp" title="Header &lt;boost/contract/call_if.hpp&gt;">boost/contract/call_if.hpp</a>&gt;
33
34 </span>
35 <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Pred<span class="special">,</span> <span class="keyword">typename</span> Then<span class="special">&gt;</span> 
36   <a class="link" href="call_if_statement.html" title="Struct template call_if_statement">call_if_statement</a><span class="special">&lt;</span> <span class="identifier">Pred</span><span class="special">::</span><span class="identifier">value</span><span class="special">,</span> <span class="identifier">Then</span> <span class="special">&gt;</span> <span class="identifier">call_if</span><span class="special">(</span><span class="identifier">Then</span> f<span class="special">)</span><span class="special">;</span></pre></div>
37 <div class="refsect1">
38 <a name="idm45707997647376"></a><h2>Description</h2>
39 <p>This is equivalent to <code class="computeroutput">boost::contract::call_if_c&lt;Pred::value&gt;(f)</code>. Create a call-if object with the specified then-branch functor template:</p>
40 <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">call_if</span><span class="special">&lt;</span><span class="identifier">Pred1</span><span class="special">&gt;</span><span class="special">(</span>
41     <span class="identifier">then_functor_template1</span>
42 <span class="special">)</span><span class="special">.</span><span class="keyword">template</span> <span class="identifier">else_if</span><span class="special">&lt;</span><span class="identifier">Pred2</span><span class="special">&gt;</span><span class="special">(</span>              <span class="comment">// Optional.</span>
43     <span class="identifier">then_functor_template2</span>
44 <span class="special">)</span>                                       <span class="comment">// Optionally, other `else_if` or</span>
45 <span class="special">...</span>                                     <span class="comment">// `else_if_c`.</span>
46 <span class="special">.</span><span class="identifier">else_</span><span class="special">(</span>                                 <span class="comment">// Optional for `void` functors,</span>
47     <span class="identifier">else_functor_template</span>               <span class="comment">// but required for non `void`.</span>
48 <span class="special">)</span>
49 </pre>
50 <p>Optional functor templates for else-if-branches and the else-branch can be specified as needed (the else-branch functor template is required if <code class="computeroutput">f</code> returns non-void).</p>
51 <p><span class="bold"><strong>See Also:</strong></span></p>
52 <p> <a class="link" href="../../boost_contract/extras.html#boost_contract.extras.assertion_requirements__templates_" title="Assertion Requirements (Templates)">
53         Assertion Requirements</a></p>
54 <p>
55 </p>
56 <p>
57
58
59
60 </p>
61 <div class="variablelist"><table border="0" class="variablelist compact">
62 <colgroup>
63 <col align="left" valign="top">
64 <col>
65 </colgroup>
66 <tbody>
67 <tr>
68 <td><p><span class="term">Parameters:</span></p></td>
69 <td><div class="variablelist"><table border="0" class="variablelist compact">
70 <colgroup>
71 <col align="left" valign="top">
72 <col>
73 </colgroup>
74 <tbody><tr>
75 <td><p><span class="term"><code class="computeroutput">f</code></span></p></td>
76 <td><p>Then-branch nullary functor template. The functor template call <code class="computeroutput">f()</code> is compiled and executed if and only if <code class="computeroutput">Pred::value</code> is <code class="computeroutput">true</code>. The return type of other functor template calls specified for this call-if statement (else-branch, else-if-branches, etc.) must be the same as (or implicitly convertible to) the return type of then-branch functor template call <code class="computeroutput">f()</code>.</p></td>
77 </tr></tbody>
78 </table></div></td>
79 </tr>
80 <tr>
81 <td><p><span class="term">Template Parameters:</span></p></td>
82 <td><div class="variablelist"><table border="0" class="variablelist compact">
83 <colgroup>
84 <col align="left" valign="top">
85 <col>
86 </colgroup>
87 <tbody><tr>
88 <td><p><span class="term"><code class="computeroutput">Pred</code></span></p></td>
89 <td><p>Nullary boolean meta-function selecting which functor template call to compile and execute.</p></td>
90 </tr></tbody>
91 </table></div></td>
92 </tr>
93 <tr>
94 <td><p><span class="term">Returns:</span></p></td>
95 <td><p>A call-if statement so else and else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed (which could also be <code class="computeroutput">void</code>). </p></td>
96 </tr>
97 </tbody>
98 </table></div>
99 </div>
100 </div>
101 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
102 <td align="left"></td>
103 <td align="right"><div class="copyright-footer">Copyright &#169; 2008-2019 Lorenzo Caminiti<p>
104         Distributed under the Boost Software License, Version 1.0 (see accompanying
105         file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
106       </p>
107 </div></td>
108 </tr></table>
109 <hr>
110 <div class="spirit-nav">
111 <a accesskey="p" href="call_if_c.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.call_if_hpp"><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="condition_if_c.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
112 </div>
113 </body>
114 </html>