mirror of
https://github.com/boostorg/contract.git
synced 2026-02-02 20:52:18 +00:00
101 lines
9.0 KiB
HTML
Executable File
101 lines
9.0 KiB
HTML
Executable File
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Macro CONTRACT_CONSTRUCTOR</title>
|
|
<link rel="stylesheet" href="doc/html/boostbook.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
|
<link rel="start" href="index.html" title="Contract++ 0.3.469">
|
|
<link rel="up" href="reference.html#header..home.lcaminiti.sandbox.dbcpp_sourceforge.boost-quickbook.doc.qbk.src.contract.macros_hpp" title="Header <contract/macros.hpp>">
|
|
<link rel="prev" href="CONTRACT_INVARIANT.html" title="Macro CONTRACT_INVARIANT">
|
|
<link rel="next" href="CONTRACT_DESTRUCTOR.html" title="Macro CONTRACT_DESTRUCTOR">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="CONTRACT_INVARIANT.html"><img src="./doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header..home.lcaminiti.sandbox.dbcpp_sourceforge.boost-quickbook.doc.qbk.src.contract.macros_hpp"><img src="./doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="./doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="CONTRACT_DESTRUCTOR.html"><img src="./doc/html/images/next.png" alt="Next"></a>
|
|
</div>
|
|
<hr>
|
|
<div class="refentry" lang="en">
|
|
<a name="CONTRACT_CONSTRUCTOR"></a><div class="titlepage"></div>
|
|
<div class="refnamediv">
|
|
<h2><span class="refentrytitle">Macro CONTRACT_CONSTRUCTOR</span></h2>
|
|
<p>CONTRACT_CONSTRUCTOR</p>
|
|
</div>
|
|
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
|
|
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="emphasis"><em>// In header: <<a class="link" href="reference.html#header..home.lcaminiti.sandbox.dbcpp_sourceforge.boost-quickbook.doc.qbk.src.contract.macros_hpp" title="Header <contract/macros.hpp>">contract/macros.hpp</a>>
|
|
|
|
</em></span>CONTRACT_CONSTRUCTOR(sequence)</pre></div>
|
|
<div class="refsect1" lang="en">
|
|
<a name="id2656408"></a><h2>Description</h2>
|
|
<p>Macro used to write contracts for constructors.</p>
|
|
<p>This macro must be used right after the constructor declaration -- and after the member initialization list if such a list is specified. There is no need for a trailing <code class="computeroutput">";"</code> after the macro closing parenthesis <code class="computeroutput">")"</code>.</p>
|
|
<p>For example (see the Tutorial section for more information): </p>
|
|
<pre class="programlisting"> template<typename T>
|
|
class myvector {
|
|
... // Invariants.
|
|
|
|
public:
|
|
explicit myvector(size_type count) // Constructor declaration.
|
|
: vector_(count) // Member initialization list.
|
|
CONTRACT_COSTRUCTOR( (class) (myvector)
|
|
(public) (myvector)( (size_type)(count) )
|
|
(precondition) ({
|
|
... // Assert constructor preconditions.
|
|
})
|
|
(postcondition) ({
|
|
... // Assert constructor postconditions.
|
|
})
|
|
(body) ({
|
|
... // Actual constructor implementation.
|
|
}) ) // No need for ";" after macro closing parenthesis ")".
|
|
|
|
... // Rest of the class.
|
|
};
|
|
</pre>
|
|
<p><span class="bold"><strong>Parameters:</strong></span> </p>
|
|
<div class="informaltable"><table class="table">
|
|
<colgroup>
|
|
<col>
|
|
<col>
|
|
</colgroup>
|
|
<tbody><tr>
|
|
<td><span class="bold"><strong><code class="computeroutput">sequence</code></strong></span></td>
|
|
<td>A Boost.Preprocessor sequence of tokens <code class="computeroutput">(1st-token)(2nd-token)...(last-token)</code> that repeats the constructor signature syntactic elements and specifies the contract.<div class="itemizedlist"><ul type="disc">
|
|
<li><p>The signature tokens are needed by the library to generate the contract code with the function name, the argument types and names, etc as discussed in the Without the Macros section (e.g., the argument names are needed to actually name the precondition and postcondition function arguments).</p></li>
|
|
<li><p>The extra parenthesis <code class="computeroutput">()</code> around the tokens are mandatory (they are the ones making the preprocessor sequence).</p></li>
|
|
<li><p>It is recommended to use <code class="computeroutput">CONTRACT_ASSERT()</code> to assert preconditions and postconditions within the relative code blocks.</p></li>
|
|
<li><p>Within the postcondition code block, <code class="computeroutput">CONTRACT_OLDOF(</code>argument-name<code class="computeroutput">)</code> is a constant reference to the related old argument value (as the value was before body execution) but only if the argument-type was tagged <code class="computeroutput">(copyable)</code> in <code class="computeroutput">sequence</code>.</p></li>
|
|
<li><p>For the body block, <code class="computeroutput">";"</code> can be used to separate the constructor definition from its declaration (see <code class="computeroutput">CONTRACT_CONSTRUCTOR_BODY()</code>).</p></li>
|
|
<li><p>As explained in the Tutorial section, the tokens in <code class="computeroutput">sequence</code> appear in the exact same order as they appear in the constructor declaration followed by the optional preconditions, optional postconditions, and mandatory body.</p></li>
|
|
<li><p>The constructor <code class="computeroutput">sequence</code> syntax is as follows ([] for optional tokens, {} tokens resulting from parenthesis contents evaluation, || one token or the other, + tokens repeated 1 or more times):</p></li>
|
|
</ul></div>
|
|
<code class="computeroutput"> [(class)] (class-type) {(public) || (protected) || (private)} [(template)( {(function-template-parameter-type)(function-template-parameter-name)}+ )] (class-name)( {(void) || {[(copyable)](argument-type)(argument-name)}+} ) [(precondition) ({ ... })] [(postcondition) ({ ... })] (body) ({ ... }) </code> </td>
|
|
</tr></tbody>
|
|
</table></div>
|
|
<p>
|
|
</p>
|
|
<p><span class="bold"><strong>Returns:</strong></span> See the Without the Macro section for examples of the code generated by this macro expansion. </p>
|
|
<div class="itemizedlist"><ul type="disc">
|
|
<li><p>If contract compilation is turned on, this macro expands to the constructor contract. </p></li>
|
|
<li><p>Otherwise, if contract compilation is turned off, this macro expands to just the constructor function body using the given body code block (and no contract overhead is added).</p></li>
|
|
</ul></div>
|
|
<p>
|
|
<span class="bold"><strong>Note:</strong></span> For functions with no argument <code class="computeroutput">(class-name)( (void) )</code>, and not just <code class="computeroutput">(class-name)( )</code>, must be used to specify the empty argument list within <code class="computeroutput">sequence</code>. This is because ISO standard C++ does not allow for empty macro parameters (this library also supports <code class="computeroutput">(class-name)( )</code> but this will only compile on C99 so its use is not recommended -- see the Tutorial section for more information).</p>
|
|
<p><span class="bold"><strong>Note:</strong></span> In comparing the <code class="computeroutput">sequence</code> syntax of constructors with the one of member functions from <code class="computeroutput">CONTRACT_FUNCTION()</code>, note the following differences (see also the Constructor Call Semantics in the Tutorial section): There is no <code class="computeroutput">(copyable)</code> before class-type because there is no object before construction body execution; There is no <code class="computeroutput">(inherit)</code> because constructors cannot directly subcontract; There is no <code class="computeroutput">(static)</code> or <code class="computeroutput">(virtual)</code> because constructors cannot be static or virtual; There is no <code class="computeroutput">(result-type)</code> because constructors have no return value; The function-name must be the class-name as always for constructors; There is no trailing <code class="computeroutput">(const)</code> because constructor cannot be constant members.</p>
|
|
<p><span class="bold"><strong>See:</strong></span> <code class="computeroutput">CONTRACT_ASSERT()</code>, <code class="computeroutput">CONTRACT_INVARIANT()</code>, <code class="computeroutput">CONTRACT_DESTRUCTOR()</code>, <code class="computeroutput">CONTRACT_FUNCTION()</code> </p>
|
|
</div>
|
|
</div>
|
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
|
<td align="left"></td>
|
|
<td align="right"><div class="copyright-footer">Copyright © 2009 -2010 Lorenzo Caminiti<p>
|
|
Distributed under the Contract++ Software License, Version 1.0 (see accompanying
|
|
file LICENSE_1_0.txt)
|
|
</p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="CONTRACT_INVARIANT.html"><img src="./doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header..home.lcaminiti.sandbox.dbcpp_sourceforge.boost-quickbook.doc.qbk.src.contract.macros_hpp"><img src="./doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="./doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="CONTRACT_DESTRUCTOR.html"><img src="./doc/html/images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|