Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74227 - in sandbox/contract/libs/contract/doc/html2: . contract__
From: lorcaminiti_at_[hidden]
Date: 2011-09-04 13:37:17


Author: lcaminiti
Date: 2011-09-04 13:37:15 EDT (Sun, 04 Sep 2011)
New Revision: 74227
URL: http://svn.boost.org/trac/boost/changeset/74227

Log:
Upd docs.
Added:
   sandbox/contract/libs/contract/doc/html2/
   sandbox/contract/libs/contract/doc/html2/contract__/
   sandbox/contract/libs/contract/doc/html2/contract__/Examples.html (contents, props changed)
   sandbox/contract/libs/contract/doc/html2/contract__/bibliography.html (contents, props changed)
   sandbox/contract/libs/contract/doc/html2/contract__/grammar.html (contents, props changed)
   sandbox/contract/libs/contract/doc/html2/contract__/release_notes.html (contents, props changed)
   sandbox/contract/libs/contract/doc/html2/index.html (contents, props changed)

Added: sandbox/contract/libs/contract/doc/html2/contract__/Examples.html
==============================================================================
--- (empty file)
+++ sandbox/contract/libs/contract/doc/html2/contract__/Examples.html 2011-09-04 13:37:15 EDT (Sun, 04 Sep 2011)
@@ -0,0 +1,4470 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Appendix: Examples</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Contract++ 0.4.x">
+<link rel="up" href="../index.html" title="Contract++ 0.4.x">
+<link rel="prev" href="../index.html" title="Contract++ 0.4.x">
+<link rel="next" href="grammar.html" title="Appendix: Grammar">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="grammar.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="contract__.examples"></a><a class="link" href="examples.html" title="Appendix: Examples">Appendix: Examples</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="examples.html#contract__.examples.n1962_vector">[N1962] Vector: Comparison
+ with C++ proposal syntax</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n1962___circle__subcontracting">[N1962]
+ Circle: Subcontracting</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n1962___factorial__recursion_and_importance_ordering">[N1962]
+ Factorial: Recursion and importance ordering</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n1962___equal__operators">[N1962]
+ Equal: Operators</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n1962___sum__separated_body_definition">[N1962]
+ Sum: Separated body definition</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n1962___square_root__default_parameters">[N1962]
+ Square Root: Default parameters</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n1962___block__block_invariants">[N1962]
+ Block: Block invariants</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.n2081_add">[N2081] Add: Generic addition
+ algorithm</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___advance__concept_based_iterator_overloading__emulated_using_tags_">[N2081]
+ Advance: Concept-based iterator overloading (emulated using tags)</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___find__generic_find_algorithm">[N2081]
+ Find: Generic find algorithm</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___apply__overloaded_invocation_of_functors">[N2081]
+ Apply: Overloaded invocation of functors</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___for_each__generic_for_each_algorithm">[N2081]
+ For Each: Generic for-each algorithm</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___transform__generic_binary_transformation_algorithm">[N2081]
+ Transform: Generic binary transformation algorithm</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___count__generic_count_algorithm">[N2081]
+ Count: Generic count algorithm</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___convert__conversion_between_two_types">[N2081]
+ Convert: Conversion between two types</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___equal__generic_equality_comparison">[N2081]
+ Equal: Generic equality comparison</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___less_equal__generic_less_than_or_equal_to_comparison">[N2081]
+ Less Equal: Generic less-than or equal-to comparison</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___de_ref__generic_iterator_dereferencing">[N2081]
+ De-Ref: Generic iterator dereferencing</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__n2081___min__generic_minimum_algorithm">[N2081]
+ Min: Generic minimum algorithm</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.meyer97_stack4">[Meyer97] Stack4:
+ Comparison with Eiffel syntax</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__meyer97___stack3__error_codes_instead_of_preconditions">[Meyer97]
+ Stack3: Error codes instead of preconditions</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.meyer97_gcd">[Meyer97] GCD: Loop
+ variant and comparison with Eiffel syntax</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__meyer97___max_array__nested_loop_variants">[Meyer97]
+ Max Array: Nested loop variants</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__mitchell02___name_list__relaxing_subcontracts">[Mitchell02]
+ Name List: Relaxing subcontracts</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__mitchell02___dictionary__simple_key_value_map">[Mitchell02]
+ Dictionary: Simple key-value map</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__mitchell02___courier__subcontracting_and_static_class_invariants">[Mitchell02]
+ Courier: Subcontracting and static class invariants</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__mitchell02___stack__simple_stack_dispenser">[Mitchell02]
+ Stack: Simple stack dispenser</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__mitchell02___simple_queue__simple_queue_dispenser">[Mitchell02]
+ Simple Queue: Simple queue dispenser</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__mitchell02___customer_manager__contracts_instead_of_defensive_programming">[Mitchell02]
+ Customer Manager: Contracts instead of Defensive Programming</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__mitchell02___observer__contracts_for_pure_virtual_functions">[Mitchell02]
+ Observer: Contracts for pure virtual functions</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.mitchell02_counter">[Mitchell02]
+ Counter: Subcontracting and virtual specifiers (final, override, new, and pure)</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__stroustrup97___string__throw_when_contract_is_broken">[Stroustrup97]
+ String: Throw when contract is broken</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.cline90_vector">[Cline90] Vector:
+ Comparison with A++ proposal syntax</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__cline90___vector_stack__subcontracting_from_abstract_data_type">[Cline90]
+ Vector-Stack: Subcontracting from Abstract Data Type</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__cline90___stack__a_very_simple_stack">[Cline90]
+ Stack: A very simple stack</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__cline90___calendar__a_very_simple_calendar">[Cline90]
+ Calendar: A very simple calendar</a></span></dt>
+</dl></div>
+<p>
+ This section lists quite a few examples programmed using this library and taken
+ from a number of different sources (which are referenced in the example title):
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ <a class="link" href="bibliography.html" title="Bibliography">[N1962]</a> contains examples
+ from the proposal to add Contract Programming submitted to the C++ standard
+ committee (not accepted into the standard).
+ </li>
+<li class="listitem">
+ <a class="link" href="bibliography.html" title="Bibliography">[N2081]</a> contains examples
+ from the proposal to add Concept Programming submitted to the C++ standard
+ committee (not accepted into the standard). These examples have been extended
+ here to specify both compile-time and run-time interface requirements using
+ concepts and contracts respectively.
+ </li>
+<li class="listitem">
+ <a class="link" href="bibliography.html" title="Bibliography">[Meyer97]</a> and <a class="link" href="bibliography.html" title="Bibliography">[Mitchell02]</a>
+ contain examples using the Eiffel programming language.
+ </li>
+<li class="listitem">
+ <a class="link" href="bibliography.html" title="Bibliography">[Cline90]</a> contains examples
+ from a very early proposal called Annotated C++ (A++) to extend C++ with
+ Contract Programming (A++ was never actually implemented).
+ </li>
+<li class="listitem">
+ <a class="link" href="bibliography.html" title="Bibliography">[Stroustrup97]</a> contains
+ one example that shows the importance of class invariants and how to configure
+ this library to throw exceptions instead of terminating the program when
+ a contract is broken.
+ </li>
+</ul></div>
+<p>
+ The followings are among the most interesting examples:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ Comparison with syntax from C++ Contract and Concept Programming proposals
+ (see <a class="link" href="examples.html#contract__.examples.n1962_vector" title="[N1962] Vector: Comparison with C++ proposal syntax">here</a>) and
+ with a user-defined concept (see <a class="link" href="examples.html#contract__.examples.n2081_add" title="[N2081] Add: Generic addition algorithm">here</a>).
+ </li>
+<li class="listitem">
+ Subcontracting and C++0x-like virtual specifiers <code class="computeroutput"><span class="identifier">final</span></code>,
+ <code class="computeroutput"><span class="identifier">override</span></code>, and <code class="computeroutput"><span class="keyword">new</span></code> (see <a class="link" href="examples.html#contract__.examples.mitchell02_counter" title="[Mitchell02] Counter: Subcontracting and virtual specifiers (final, override, new, and pure)">here</a>).
+ </li>
+<li class="listitem">
+ Comparison with Eiffel syntax (see <a class="link" href="examples.html#contract__.examples.meyer97_stack4" title="[Meyer97] Stack4: Comparison with Eiffel syntax">here</a>)
+ and for loop variants (see <a class="link" href="examples.html#contract__.examples.meyer97_gcd" title="[Meyer97] GCD: Loop variant and comparison with Eiffel syntax">here</a>).
+ </li>
+<li class="listitem">
+ Comparison with A++ syntax (see <a class="link" href="examples.html#contract__.examples.cline90_vector" title="[Cline90] Vector: Comparison with A++ proposal syntax">here</a>).
+ </li>
+</ul></div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.n1962_vector"></a><a class="link" href="examples.html#contract__.examples.n1962_vector" title="[N1962] Vector: Comparison with C++ proposal syntax">[N1962] Vector: Comparison
+ with C++ proposal syntax</a>
+</h3></div></div></div>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ ISO C++ (this library)
+ </p>
+ </th>
+<th>
+ <p>
+ C++ Proposals (<a class="link" href="bibliography.html" title="Bibliography">[N1962]</a>,
+ <a class="link" href="bibliography.html" title="Bibliography">[N2081]</a>, etc)
+ </p>
+ </th>
+</tr></thead>
+<tbody><tr>
+<td>
+ <p>
+
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// For boost::prior().</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iterator</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
+
+<span class="comment">// Tools (forward declared, see actual declarations at the bottom).</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">bool</span> <span class="identifier">all_equals</span> <span class="special">(</span> <span class="identifier">Iter</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">last</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span> <span class="special">)</span> <span class="special">;</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Size</span> <span class="special">&gt;</span>
+<span class="keyword">bool</span> <span class="identifier">equal_distance</span> <span class="special">(</span> <span class="identifier">Iter</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">Size</span> <span class="identifier">size</span> <span class="special">)</span> <span class="special">;</span>
+
+<span class="comment">// New vector interface (with contracts).</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Alloc</span><span class="special">,</span> <span class="keyword">default</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="comment">// No base classes so no subcontracting for this example.</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span> <span class="comment">// At very beginning of the class declaration.</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">),</span>
+ <span class="keyword">int</span><span class="special">(</span><span class="identifier">size</span><span class="special">())</span> <span class="special">==</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">()),</span>
+ <span class="keyword">int</span><span class="special">(</span><span class="identifier">size</span><span class="special">())</span> <span class="special">==</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rbegin</span><span class="special">(),</span> <span class="identifier">rend</span><span class="special">()),</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;=</span> <span class="identifier">capacity</span><span class="special">(),</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&lt;=</span> <span class="identifier">max_size</span><span class="special">()</span>
+ <span class="special">)</span> <span class="comment">// No static or volatile class invariants for this example.</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">allocator_type</span> <span class="identifier">allocator_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">pointer</span> <span class="identifier">pointer</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">const_pointer</span> <span class="identifier">const_pointer</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">reference</span> <span class="identifier">reference</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">const_reference</span> <span class="identifier">const_reference</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="identifier">value_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">iterator</span> <span class="identifier">iterator</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">const_iterator</span> <span class="identifier">const_iterator</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">reverse_iterator</span> <span class="identifier">reverse_iterator</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">const_reverse_iterator</span>
+ <span class="identifier">const_reverse_iterator</span><span class="special">;</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// Must always specify the access level (public).</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">vect_</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// Member initializers.</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">Alloc</span><span class="special">&amp;)</span> <span class="identifier">al</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">al</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">(),</span> <span class="identifier">al</span> <span class="special">==</span> <span class="identifier">get_allocator</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span><span class="special">,</span> <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">T</span><span class="special">())</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">count</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span><span class="special">,</span> <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">val</span><span class="special">)</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">count</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">val</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">Alloc</span><span class="special">&amp;)</span> <span class="identifier">al</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">,</span> <span class="identifier">al</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span><span class="special">,</span>
+ <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">val</span><span class="special">),</span>
+ <span class="identifier">al</span> <span class="special">==</span> <span class="identifier">get_allocator</span><span class="special">()</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">template</span><span class="special">(</span> <span class="keyword">class</span> <span class="identifier">InIt</span> <span class="special">)</span> <span class="identifier">requires</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIt</span><span class="special">&gt;</span> <span class="special">)</span> <span class="comment">// Concept.</span>
+ <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">InIt</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">InIt</span><span class="special">)</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">equal_distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">size</span><span class="special">())</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">template</span><span class="special">(</span> <span class="keyword">class</span> <span class="identifier">InIt</span> <span class="special">)</span> <span class="identifier">requires</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIt</span><span class="special">&gt;</span> <span class="special">)</span>
+ <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">InIt</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">InIt</span><span class="special">)</span> <span class="identifier">last</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">Alloc</span><span class="special">&amp;)</span> <span class="identifier">al</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">al</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">equal_distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">size</span><span class="special">()),</span>
+ <span class="identifier">al</span> <span class="special">==</span> <span class="identifier">get_allocator</span><span class="special">()</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">vector</span><span class="special">&amp;)</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">right</span><span class="special">.</span><span class="identifier">vect_</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">right</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Operator symbol followed by (arbitrary) name `copy`.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">&amp;)</span> <span class="keyword">operator</span><span class="special">(=)(</span><span class="identifier">copy</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">vector</span><span class="special">&amp;)</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">right</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">vect_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Contract destructor so to check class</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// invariants when object is destroyed.</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="comment">// No required wrapping parenthesis for keyword types like `void`, `bool`, etc.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">reserve</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span><span class="identifier">count</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="special">(</span><span class="identifier">capacity</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="comment">// Constant member.</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">&gt;=</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// With result.</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">capacity</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">begin</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">(</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">end</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// If-guarded assertion.</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">const_iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">begin</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="comment">// Overload above member.</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">(</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">end</span><span class="special">()</span> <span class="special">)</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Contract members even if no pre/post</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">end</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// conditions so to check class invariants.</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">const_iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">end</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">reverse_iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">rbegin</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">(</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">rend</span><span class="special">()</span> <span class="special">)</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">rbegin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">const_reverse_iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">rbegin</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">(</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">rend</span><span class="special">()</span> <span class="special">)</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">rbegin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">reverse_iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">rend</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">rend</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">const_reverse_iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">rend</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">rend</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">resize</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">newsize</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span> <span class="comment">// Old value (as before body).</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">newsize</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">newsize</span> <span class="special">&gt;</span> <span class="identifier">old_size</span><span class="special">)</span> <span class="special">(</span> <span class="comment">// Version 1: Within an `if`.</span>
+ <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">old_size</span><span class="special">,</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">T</span><span class="special">())</span>
+ <span class="special">)</span> <span class="comment">// Omitted optional `else( ... )`.</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">resize</span><span class="special">(</span><span class="identifier">newsize</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">resize</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">newsize</span><span class="special">,</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span> <span class="comment">// Specify old type.</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">newsize</span><span class="special">,</span>
+ <span class="identifier">newsize</span> <span class="special">&gt;</span> <span class="identifier">old_size</span> <span class="special">?</span> <span class="comment">// Version 2: With ternary operator.</span>
+ <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">old_size</span><span class="special">,</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">val</span><span class="special">)</span> <span class="special">:</span> <span class="keyword">true</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">resize</span><span class="special">(</span><span class="identifier">newsize</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="special">(</span><span class="identifier">size</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">&lt;=</span> <span class="identifier">capacity</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="special">(</span><span class="identifier">max_size</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">&gt;=</span> <span class="identifier">capacity</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">max_size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">empty</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">empty</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">Alloc</span><span class="special">)</span> <span class="special">(</span><span class="identifier">get_allocator</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">get_allocator</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">reference</span><span class="special">)</span> <span class="special">(</span><span class="identifier">at</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">off</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">off</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">off</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">const_reference</span><span class="special">)</span> <span class="special">(</span><span class="identifier">at</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">off</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">off</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">off</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">reference</span><span class="special">)</span> <span class="keyword">operator</span><span class="special">([])(</span><span class="identifier">at</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">off</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">off</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">[</span><span class="identifier">off</span><span class="special">];</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">const_reference</span><span class="special">)</span> <span class="keyword">operator</span><span class="special">([])(</span><span class="identifier">at</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">off</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">off</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">[</span><span class="identifier">off</span><span class="special">];</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">reference</span><span class="special">)</span> <span class="special">(</span><span class="identifier">front</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="keyword">bool</span><span class="special">(!</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">)</span> <span class="comment">// bool for leading non alphanumeric `!`.</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">front</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">const_reference</span><span class="special">)</span> <span class="special">(</span><span class="identifier">front</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span> <span class="comment">// Or, `== false` instead of `!`.</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">front</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">reference</span><span class="special">)</span> <span class="special">(</span><span class="identifier">back</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">back</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">const_reference</span><span class="special">)</span> <span class="special">(</span><span class="identifier">back</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">back</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">push_back</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_capacity</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">capacity</span><span class="special">(),</span>
+ <span class="identifier">back</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">val</span><span class="special">,</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_size</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">old_capacity</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">pop_back</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_size</span> <span class="special">-</span> <span class="number">1</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">pop_back</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">template</span><span class="special">(</span> <span class="keyword">class</span> <span class="identifier">InIt</span> <span class="special">)</span> <span class="identifier">requires</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIt</span><span class="special">&gt;</span> <span class="special">)</span>
+ <span class="keyword">void</span> <span class="special">(</span><span class="identifier">assign</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">InIt</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">InIt</span><span class="special">)</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="comment">// Precondition: [first, last) is not a sub-range of [begin(), end()).</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">equal_distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">size</span><span class="special">())</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">assign</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">count</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span> <span class="special">&lt;=</span> <span class="identifier">max_size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">val</span><span class="special">)</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span><span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">insert</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="identifier">pos</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span>
+ <span class="identifier">val</span> <span class="special">==</span> <span class="special">*</span><span class="identifier">result</span><span class="special">,</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_size</span> <span class="special">+</span> <span class="number">1</span>
+ <span class="comment">// if(capacity() &gt; oldof capacity()): [begin(), end()] invalid</span>
+ <span class="comment">// else: [pos, end()) invalid</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">pos</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">insert</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="identifier">pos</span><span class="special">,</span> <span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">count</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">count</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_capacity</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">capacity</span><span class="special">(),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_pos</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">pos</span><span class="special">,</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_size</span> <span class="special">+</span> <span class="identifier">count</span><span class="special">,</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">old_capacity</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_capacity</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">prior</span><span class="special">(</span><span class="identifier">old_pos</span><span class="special">),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">prior</span><span class="special">(</span><span class="identifier">old_pos</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">)</span>
+ <span class="comment">// [pos, end()) invalid</span>
+ <span class="special">)</span> <span class="comment">// else: [begin(), end()) invalid</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">pos</span><span class="special">,</span> <span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">template</span><span class="special">(</span> <span class="keyword">class</span> <span class="identifier">InIt</span> <span class="special">)</span>
+ <span class="keyword">void</span> <span class="special">(</span><span class="identifier">insert</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="identifier">pos</span><span class="special">,</span> <span class="special">(</span><span class="identifier">InIt</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">InIt</span><span class="special">)</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="comment">// [first, last) not a sub-range of [begin(), end())</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">()</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_capacity</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">capacity</span><span class="special">(),</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_size</span> <span class="special">+</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">),</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">old_capacity</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">pos</span><span class="special">,</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">erase</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="identifier">pos</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">,</span>
+ <span class="identifier">pos</span> <span class="special">!=</span> <span class="identifier">end</span><span class="special">()</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">(</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">end</span><span class="special">()</span> <span class="special">)</span>
+ <span class="comment">// [pos, end()) invalid</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">erase</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="special">(</span><span class="identifier">erase</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">iterator</span><span class="special">)</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">(),</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_size</span> <span class="special">-</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">),</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">(</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">end</span><span class="special">()</span> <span class="special">)</span>
+ <span class="comment">// [first, last) invalid</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">erase</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">clear</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">clear</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">swap</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">&amp;)</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_self</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="special">*</span><span class="keyword">this</span><span class="special">,</span>
+ <span class="keyword">auto</span> <span class="identifier">old_right</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">right</span><span class="special">,</span>
+ <span class="identifier">old_self</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">,</span>
+ <span class="identifier">old_right</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">right</span><span class="special">);</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;</span> <span class="identifier">vect_</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ForwardIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="comment">// For simplicity, assume T comparable.</span>
+ <span class="special">)</span>
+<span class="keyword">bool</span> <span class="special">(</span><span class="identifier">all_equals</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">last</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">val</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="identifier">Iter</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">first</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">last</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="keyword">if</span><span class="special">(*</span><span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">val</span><span class="special">)</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Size</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="comment">// Could use internal tagging mechanism to pass even input iterators.</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ForwardIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;,</span>
+ <span class="comment">// IDENTITY_TYPE to handle unwrapped commas within macro parameters.</span>
+ <span class="keyword">typename</span> <span class="identifier">CONTRACT_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">Convertible</span><span class="special">&lt;</span><span class="identifier">Size</span><span class="special">,</span> <span class="keyword">int</span><span class="special">&gt;))</span>
+ <span class="special">)</span>
+<span class="keyword">bool</span> <span class="special">(</span><span class="identifier">equal_distance</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">last</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Size</span><span class="special">)</span> <span class="identifier">size</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="keyword">int</span><span class="special">(</span><span class="identifier">size</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+<span class="special">}</span>
+
+<span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">)</span> <span class="identifier">requires</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">)</span>
+<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">(==)(</span><span class="identifier">equal</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;)</span> <span class="identifier">left</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;)</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">left</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span>
+ <span class="comment">// left and right values are all equal to each other.</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">!=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">size</span><span class="special">())</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">const_iterator</span>
+ <span class="identifier">l</span> <span class="special">=</span> <span class="identifier">left</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span> <span class="identifier">l</span> <span class="special">!=</span> <span class="identifier">left</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span> <span class="special">++</span><span class="identifier">l</span><span class="special">,</span> <span class="special">++</span><span class="identifier">r</span><span class="special">)</span>
+ <span class="keyword">if</span><span class="special">(*</span><span class="identifier">l</span> <span class="special">!=</span> <span class="special">*</span><span class="identifier">r</span><span class="special">)</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+ </td>
+<td>
+ <p>
+
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// Extra spacing and newlines used to visually align with this library code.</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">concepts</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iterator</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
+
+
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">bool</span> <span class="identifier">all_equals</span> <span class="special">(</span> <span class="identifier">Iter</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">last</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span> <span class="special">)</span> <span class="special">;</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Size</span> <span class="special">&gt;</span>
+<span class="keyword">bool</span> <span class="identifier">equal_distance</span> <span class="special">(</span> <span class="identifier">Iter</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">Size</span> <span class="identifier">size</span> <span class="special">)</span> <span class="special">;</span>
+
+
+
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Alloc</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&gt;</span>
+<span class="keyword">class</span> <span class="identifier">vector</span>
+<span class="special">{</span>
+ <span class="identifier">invariant</span> <span class="special">{</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">int</span><span class="special">(</span><span class="identifier">size</span><span class="special">())</span> <span class="special">==</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">());</span>
+ <span class="keyword">int</span><span class="special">(</span><span class="identifier">size</span><span class="special">())</span> <span class="special">==</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rbegin</span><span class="special">(),</span> <span class="identifier">rend</span><span class="special">());</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;=</span> <span class="identifier">capacity</span><span class="special">();</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&lt;=</span> <span class="identifier">max_size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">allocator_type</span> <span class="identifier">allocator_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">pointer</span> <span class="identifier">pointer</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">const_pointer</span> <span class="identifier">const_pointer</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">reference</span> <span class="identifier">reference</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">const_reference</span> <span class="identifier">const_reference</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="identifier">value_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">iterator</span> <span class="identifier">iterator</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">const_iterator</span> <span class="identifier">const_iterator</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">difference_type</span> <span class="identifier">difference_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">reverse_iterator</span> <span class="identifier">reverse_iterator</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;::</span><span class="identifier">const_reverse_iterator</span>
+ <span class="identifier">const_reverse_iterator</span><span class="special">;</span>
+
+ <span class="comment">// `public:` and `void` used to visually align with this library code.</span>
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">vector</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">vect_</span><span class="special">()</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">;</span> <span class="special">}</span>
+ <span class="special">{}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">explicit</span> <span class="identifier">vector</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">Alloc</span><span class="special">&amp;</span> <span class="identifier">al</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">al</span><span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">empty</span><span class="special">();</span> <span class="identifier">al</span> <span class="special">==</span> <span class="identifier">get_allocator</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">explicit</span> <span class="identifier">vector</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">count</span><span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span><span class="special">;</span> <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">T</span><span class="special">());</span> <span class="special">}</span>
+ <span class="special">{}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">vector</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">count</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span><span class="special">;</span> <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">val</span><span class="special">);</span> <span class="special">}</span>
+ <span class="special">{}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">vector</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">count</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Alloc</span><span class="special">&amp;</span> <span class="identifier">al</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">,</span> <span class="identifier">al</span><span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span><span class="special">;</span>
+ <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="identifier">al</span> <span class="special">==</span> <span class="identifier">get_allocator</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">{}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">InIt</span> <span class="special">&gt;</span> <span class="identifier">requires</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIt</span><span class="special">&gt;</span>
+ <span class="identifier">vector</span> <span class="special">(</span> <span class="identifier">InIt</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">InIt</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">equal_distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">size</span><span class="special">());</span> <span class="special">}</span>
+ <span class="special">{}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">InIt</span> <span class="special">&gt;</span> <span class="identifier">requires</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIt</span><span class="special">&gt;</span>
+ <span class="identifier">vector</span> <span class="special">(</span> <span class="identifier">InIt</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">InIt</span> <span class="identifier">last</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Alloc</span><span class="special">&amp;</span> <span class="identifier">al</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">al</span><span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+ <span class="identifier">equal_distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">size</span><span class="special">());</span>
+ <span class="identifier">al</span> <span class="special">==</span> <span class="identifier">get_allocator</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">{}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">vector</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">vector</span><span class="special">&amp;</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">right</span><span class="special">.</span><span class="identifier">vect_</span><span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">right</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span> <span class="special">}</span>
+ <span class="special">{}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">vector</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">vector</span><span class="special">&amp;</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span>
+
+ <span class="identifier">right</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">vect_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">vector</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">{}</span>
+
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">void</span> <span class="identifier">reserve</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">count</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">count</span><span class="special">;</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span><span class="identifier">count</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">size_type</span> <span class="identifier">capacity</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">result</span> <span class="special">&gt;=</span> <span class="identifier">size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">capacity</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">iterator</span> <span class="identifier">begin</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">const_iterator</span> <span class="identifier">begin</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">end</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">iterator</span> <span class="identifier">end</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">const_iterator</span> <span class="identifier">end</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">reverse_iterator</span> <span class="identifier">rbegin</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">rend</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">rbegin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">const_reverse_iterator</span> <span class="identifier">rbegin</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">rend</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">rbegin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">reverse_iterator</span> <span class="identifier">rend</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">rend</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">const_reverse_iterator</span> <span class="identifier">rend</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">rend</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">void</span> <span class="identifier">resize</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">newsize</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">newsize</span><span class="special">;</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">newsize</span> <span class="special">&gt;</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">())</span> <span class="special">{</span>
+ <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">T</span><span class="special">());</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">resize</span><span class="special">(</span><span class="identifier">newsize</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">void</span> <span class="identifier">resize</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">newsize</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">newsize</span><span class="special">;</span>
+ <span class="identifier">newsize</span> <span class="special">&gt;</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">?</span>
+ <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">val</span><span class="special">)</span> <span class="special">:</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">resize</span><span class="special">(</span><span class="identifier">newsize</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">size_type</span> <span class="identifier">size</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">result</span> <span class="special">&lt;=</span> <span class="identifier">capacity</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">size_type</span> <span class="identifier">max_size</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">result</span> <span class="special">&gt;=</span> <span class="identifier">capacity</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">max_size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">bool</span> <span class="identifier">empty</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">);</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">empty</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">Alloc</span> <span class="identifier">get_allocator</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">get_allocator</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">reference</span> <span class="identifier">at</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">off</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">off</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">off</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">const_reference</span> <span class="identifier">at</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">off</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">off</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">off</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">reference</span> <span class="keyword">operator</span><span class="special">[]</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">off</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">off</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">[</span><span class="identifier">off</span><span class="special">];</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">const_reference</span> <span class="keyword">operator</span><span class="special">[]</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">off</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">off</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">[</span><span class="identifier">off</span><span class="special">];</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">reference</span> <span class="identifier">front</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="special">!</span><span class="identifier">empty</span><span class="special">();</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">front</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">const_reference</span> <span class="identifier">front</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">;</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">front</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">reference</span> <span class="identifier">back</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">;</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">back</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">const_reference</span> <span class="identifier">back</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">;</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">back</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="identifier">push_back</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">()</span> <span class="special">}</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+
+
+ <span class="identifier">back</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">val</span><span class="special">;</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="number">1</span><span class="special">;</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">oldof</span> <span class="identifier">capacity</span><span class="special">()</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">void</span> <span class="identifier">pop_back</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">;</span> <span class="special">}</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">-</span> <span class="number">1</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">pop_back</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">InIt</span> <span class="special">&gt;</span> <span class="identifier">requires</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIt</span><span class="special">&gt;</span>
+ <span class="keyword">void</span> <span class="identifier">assign</span> <span class="special">(</span> <span class="identifier">InIt</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">InIt</span> <span class="identifier">last</span> <span class="special">)</span>
+
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">equal_distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">size</span><span class="special">());</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">void</span> <span class="identifier">assign</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">count</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">count</span> <span class="special">&lt;=</span> <span class="identifier">max_size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span> <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">end</span><span class="special">(),</span> <span class="identifier">val</span><span class="special">);</span> <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span><span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">iterator</span> <span class="identifier">insert</span> <span class="special">(</span> <span class="identifier">iterator</span> <span class="identifier">pos</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span>
+
+
+ <span class="identifier">val</span> <span class="special">==</span> <span class="special">*</span><span class="identifier">result</span><span class="special">;</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="number">1</span><span class="special">;</span>
+
+
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">pos</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">void</span> <span class="identifier">insert</span> <span class="special">(</span> <span class="identifier">iterator</span> <span class="identifier">pos</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="identifier">count</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">count</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">();</span> <span class="special">}</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+
+
+
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">count</span><span class="special">;</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">oldof</span> <span class="identifier">capacity</span><span class="special">();</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">oldof</span> <span class="identifier">capacity</span><span class="special">())</span> <span class="special">{</span>
+ <span class="identifier">all_equals</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">prior</span><span class="special">(</span><span class="identifier">oldof</span> <span class="identifier">pos</span><span class="special">),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">prior</span><span class="special">(</span><span class="identifier">oldof</span> <span class="identifier">pos</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+
+ <span class="special">}</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">pos</span><span class="special">,</span> <span class="identifier">count</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">InIt</span> <span class="special">&gt;</span>
+ <span class="keyword">void</span> <span class="identifier">insert</span> <span class="special">(</span> <span class="identifier">iterator</span> <span class="identifier">pos</span><span class="special">,</span> <span class="identifier">InIt</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">InIt</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span>
+
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">&lt;</span> <span class="identifier">max_size</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+
+
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">oldof</span> <span class="identifier">capacity</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">pos</span><span class="special">,</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">iterator</span> <span class="identifier">erase</span> <span class="special">(</span> <span class="identifier">iterator</span> <span class="identifier">pos</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="identifier">pos</span> <span class="special">!=</span> <span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span>
+
+
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">oldod</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">end</span><span class="special">();</span>
+
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">erase</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="identifier">iterator</span> <span class="identifier">erase</span> <span class="special">(</span> <span class="identifier">iterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">iterator</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="identifier">precondition</span> <span class="special">{</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">lasst</span><span class="special">);</span> <span class="special">}</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span>
+
+
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">oldof</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">-</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">end</span><span class="special">();</span>
+
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">erase</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">clear</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">clear</span><span class="special">();</span>
+ <span class="special">}</span>
+
+
+ <span class="keyword">public</span><span class="special">:</span> <span class="keyword">void</span> <span class="identifier">swap</span> <span class="special">(</span> <span class="identifier">vector</span><span class="special">&amp;</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span> <span class="special">{</span>
+
+
+ <span class="identifier">oldof</span> <span class="special">*</span><span class="keyword">this</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">;</span>
+ <span class="identifier">oldof</span> <span class="identifier">right</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">right</span><span class="special">);</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;</span> <span class="identifier">vect_</span><span class="special">;</span>
+<span class="special">};</span>
+
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+ <span class="identifier">requires</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ForwardIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span>
+
+<span class="keyword">bool</span> <span class="identifier">all_equals</span> <span class="special">(</span> <span class="identifier">Iter</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">last</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="identifier">Iter</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">first</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">last</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="keyword">if</span><span class="special">(*</span><span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">val</span><span class="special">)</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+<span class="special">}</span>
+
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Size</span> <span class="special">&gt;</span>
+ <span class="identifier">requires</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ForwardIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;,</span>
+
+ <span class="keyword">typename</span> <span class="identifier">CONTRACT_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">Convertible</span><span class="special">&lt;</span><span class="identifier">Size</span><span class="special">,</span> <span class="keyword">int</span><span class="special">&gt;))</span>
+
+<span class="keyword">bool</span> <span class="identifier">equal_distance</span> <span class="special">(</span> <span class="identifier">Iter</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iter</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">Size</span> <span class="identifier">size</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">return</span> <span class="keyword">int</span><span class="special">(</span><span class="identifier">size</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">);</span>
+<span class="special">}</span>
+
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">T</span> <span class="special">&gt;</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span>
+<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">left</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span>
+
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">left</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span>
+
+ <span class="special">}</span>
+ <span class="special">}</span>
+<span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">!=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">size</span><span class="special">())</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">const_iterator</span>
+ <span class="identifier">l</span> <span class="special">=</span> <span class="identifier">left</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span> <span class="identifier">l</span> <span class="special">!=</span> <span class="identifier">left</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span> <span class="special">++</span><span class="identifier">l</span><span class="special">,</span> <span class="special">++</span><span class="identifier">r</span><span class="special">)</span>
+ <span class="keyword">if</span><span class="special">(*</span><span class="identifier">l</span> <span class="special">!=</span> <span class="special">*</span><span class="identifier">r</span><span class="special">)</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+ </td>
+</tr></tbody>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n1962___circle__subcontracting"></a><a class="link" href="examples.html#contract__.examples.__n1962___circle__subcontracting" title="[N1962] Circle: Subcontracting">[N1962]
+ Circle: Subcontracting</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">shape</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// Must always specify class invariants.</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">shape</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">compute_area</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">&gt;</span> <span class="number">0</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="comment">// Contracts also for pure virtual functions.</span>
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">circle</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="keyword">public</span> <span class="identifier">shape</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// In AND with base class invariants.</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">radius</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="number">2</span><span class="special">;</span> <span class="special">}</span> <span class="comment">// For simplicity, hard-code radius.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Also optional override specifier.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">compute_area</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="identifier">override</span>
+ <span class="comment">// Eventual preconditions in OR with base function preconditions.</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="comment">// In AND with base function postconditions.</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">PI</span> <span class="special">*</span> <span class="identifier">radius</span><span class="special">()</span> <span class="special">*</span> <span class="identifier">radius</span><span class="special">()</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">PI</span> <span class="special">*</span> <span class="identifier">radius</span><span class="special">()</span> <span class="special">*</span> <span class="identifier">radius</span><span class="special">();</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">PI</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span> <span class="comment">// Truncated from 3.14...</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n1962___factorial__recursion_and_importance_ordering"></a><a class="link" href="examples.html#contract__.examples.__n1962___factorial__recursion_and_importance_ordering" title="[N1962] Factorial: Recursion and importance ordering">[N1962]
+ Factorial: Recursion and importance ordering</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="comment">// Assertion importance used to model computational complexity.</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_1</span> <span class="number">0</span> <span class="comment">// O(1) constant (default).</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_N</span> <span class="number">1</span> <span class="comment">// O(n) linear.</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_NN</span> <span class="number">2</span> <span class="comment">// O(n * n) quadratic.</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_NX</span> <span class="number">3</span> <span class="comment">// O(n^x) polynomial.</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_FACTN</span> <span class="number">4</span> <span class="comment">// O(n!) factorial.</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_EXPN</span> <span class="number">5</span> <span class="comment">// O(e^n) exponential.</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">int</span> <span class="special">(</span><span class="identifier">factorial</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">n</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">,</span>
+ <span class="identifier">n</span> <span class="special">&lt;=</span> <span class="number">12</span> <span class="comment">// Max function input.</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">&gt;=</span> <span class="number">1</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">n</span> <span class="special">&lt;</span> <span class="number">2</span><span class="special">)</span> <span class="special">(</span> <span class="comment">// Select assertion.</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="number">1</span>
+ <span class="special">)</span> <span class="keyword">else</span> <span class="special">(</span>
+ <span class="comment">// Contracts disable assertions within assertion checking so</span>
+ <span class="comment">// this postcondition can recursively call the function without</span>
+ <span class="comment">// causing infinite recursion. Moreover, this check adds</span>
+ <span class="comment">// significant run-time overhead so assertion importance is used to</span>
+ <span class="comment">// allow to selectively disable it.</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">n</span> <span class="special">*</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">importance</span> <span class="identifier">O_FACTN</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">n</span> <span class="special">&lt;</span> <span class="number">2</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="keyword">return</span> <span class="identifier">n</span> <span class="special">*</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n1962___equal__operators"></a><a class="link" href="examples.html#contract__.examples.__n1962___equal__operators" title="[N1962] Equal: Operators">[N1962]
+ Equal: Operators</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: equal.hpp</span>
+<span class="preprocessor">#include</span> <span class="string">"equal_not.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">(==)(</span><span class="identifier">equal</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">l</span><span class="special">,</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">r</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">!(</span><span class="identifier">l</span> <span class="special">!=</span> <span class="identifier">r</span><span class="special">)</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">l</span><span class="special">.</span><span class="identifier">value</span> <span class="special">==</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">value</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: equal_not.hpp</span>
+<span class="preprocessor">#include</span> <span class="string">"equal.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">(!=)(</span><span class="identifier">not_equal</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">l</span><span class="special">,</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">r</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">!(</span><span class="identifier">l</span> <span class="special">==</span> <span class="identifier">r</span><span class="special">)</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">l</span><span class="special">.</span><span class="identifier">value</span> <span class="special">!=</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">value</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n1962___sum__separated_body_definition"></a><a class="link" href="examples.html#contract__.examples.__n1962___sum__separated_body_definition" title="[N1962] Sum: Separated body definition">[N1962]
+ Sum: Separated body definition</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: sum.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">double</span> <span class="special">(</span><span class="identifier">sum</span><span class="special">)(</span> <span class="keyword">int</span> <span class="identifier">count</span><span class="special">,</span> <span class="special">(</span><span class="keyword">double</span><span class="special">*)</span> <span class="identifier">array</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span> <span class="special">%</span> <span class="number">4</span> <span class="special">==</span> <span class="number">0</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">;</span> <span class="comment">// Separate body definition from function declaration (see .cpp file).</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"sum.hpp"</span>
+
+<span class="keyword">double</span> <span class="identifier">CONTRACT_FREE_BODY</span><span class="special">(</span><span class="identifier">sum</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">count</span><span class="special">,</span> <span class="keyword">double</span><span class="special">*</span> <span class="identifier">array</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">double</span> <span class="identifier">accum</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">;</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">count</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="identifier">accum</span> <span class="special">+=</span> <span class="identifier">array</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span>
+ <span class="keyword">return</span> <span class="identifier">accum</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n1962___square_root__default_parameters"></a><a class="link" href="examples.html#contract__.examples.__n1962___square_root__default_parameters" title="[N1962] Square Root: Default parameters">[N1962]
+ Square Root: Default parameters</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cmath</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Default value for `precision` parameter.</span>
+<span class="keyword">double</span> <span class="special">(</span><span class="identifier">mysqrt</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">double</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">precision</span><span class="special">,</span> <span class="keyword">default</span> <span class="keyword">double</span><span class="special">(</span><span class="number">1e-6</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">x</span> <span class="special">&gt;=</span> <span class="number">0.0</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">root</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="comment">// Result value named `root`.</span>
+ <span class="identifier">fabs</span><span class="special">(</span><span class="identifier">root</span> <span class="special">*</span> <span class="identifier">root</span> <span class="special">-</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">&lt;=</span> <span class="identifier">precision</span> <span class="comment">// Equal within precision.</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n1962___block__block_invariants"></a><a class="link" href="examples.html#contract__.examples.__n1962___block__block_invariants" title="[N1962] Block: Block invariants">[N1962]
+ Block: Block invariants</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="number">100</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_BLOCK_INVARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">i</span> <span class="special">)</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="number">10</span> <span class="special">)</span> <span class="comment">// Intentionally fails.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">i</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.n2081_add"></a><a class="link" href="examples.html#contract__.examples.n2081_add" title="[N2081] Add: Generic addition algorithm">[N2081] Add: Generic addition
+ algorithm</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">class</span> <span class="identifier">Addable</span> <span class="special">{</span> <span class="comment">// User-defined concept.</span>
+ <span class="identifier">T</span> <span class="identifier">x</span><span class="special">;</span>
+ <span class="identifier">T</span> <span class="identifier">y</span><span class="special">;</span>
+ <span class="keyword">void</span> <span class="identifier">return_type</span> <span class="special">(</span> <span class="identifier">T</span> <span class="special">);</span> <span class="comment">// Used to check addition returns type `T`.</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">BOOST_CONCEPT_USAGE</span><span class="special">(</span><span class="identifier">Addable</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">return_type</span><span class="special">(</span><span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// Check addition `T operator+(T x, T y)`.</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="identifier">Addable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span>
+<span class="preprocessor">#ifndef</span> <span class="identifier">CONTRACT_CONFIG_NO_POSTCONDITIONS</span> <span class="comment">// Equality only for postconditions.</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span>
+<span class="preprocessor">#endif</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">(</span><span class="identifier">add</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">x</span><span class="special">,</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">y</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___advance__concept_based_iterator_overloading__emulated_using_tags_"></a><a class="link" href="examples.html#contract__.examples.__n2081___advance__concept_based_iterator_overloading__emulated_using_tags_" title="[N2081] Advance: Concept-based iterator overloading (emulated using tags)">[N2081]
+ Advance: Concept-based iterator overloading (emulated using tags)</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mpl</span><span class="special">/</span><span class="keyword">bool</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">list</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iterator</span><span class="special">&gt;</span>
+
+<span class="keyword">namespace</span> <span class="identifier">aux</span> <span class="special">{</span> <span class="comment">// Tag dispatch helpers (in a private namespace).</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">InputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Distance</span> <span class="special">&gt;</span>
+<span class="keyword">void</span> <span class="identifier">myadvance_dispatch</span> <span class="special">(</span> <span class="identifier">InputIterator</span><span class="special">&amp;</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">Distance</span> <span class="identifier">n</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">input_iterator_tag</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">while</span><span class="special">(</span><span class="identifier">n</span><span class="special">--)</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">)</span> <span class="identifier">n</span> <span class="special">)</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">BidirectionalIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Distance</span> <span class="special">&gt;</span>
+<span class="keyword">void</span> <span class="identifier">myadvance_dispatch</span> <span class="special">(</span> <span class="identifier">BidirectionalIterator</span><span class="special">&amp;</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">Distance</span> <span class="identifier">n</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">bidirectional_iterator_tag</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">n</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">while</span><span class="special">(</span><span class="identifier">n</span><span class="special">--)</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">)</span> <span class="identifier">n</span> <span class="special">)</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+<span class="preprocessor">#ifndef</span> <span class="identifier">CONTRACT_CONFIG_NO_LOOP_VARIANTS</span>
+ <span class="identifier">Distance</span> <span class="identifier">n_max</span> <span class="special">=</span> <span class="identifier">n</span><span class="special">;</span>
+<span class="preprocessor">#endif</span>
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">while</span><span class="special">(</span><span class="identifier">n</span><span class="special">++)</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">n_max</span><span class="special">,</span> <span class="identifier">n</span> <span class="special">)</span> <span class="identifier">n_max</span> <span class="special">-</span> <span class="identifier">n</span> <span class="special">)</span>
+ <span class="special">--</span><span class="identifier">i</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">RandomAccessIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Distance</span> <span class="special">&gt;</span>
+<span class="keyword">void</span> <span class="identifier">myadvance_dispatch</span> <span class="special">(</span> <span class="identifier">RandomAccessIterator</span><span class="special">&amp;</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">Distance</span> <span class="identifier">n</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">random_access_iterator_tag</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">i</span> <span class="special">+=</span> <span class="identifier">n</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="special">}</span> <span class="comment">// namespace aux</span>
+
+<span class="comment">// Contract helper meta-function.</span>
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">is_input_iterator</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="identifier">false_</span> <span class="special">{};</span>
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">is_input_iterator</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">input_iterator_tag</span><span class="special">&gt;</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="identifier">true_</span> <span class="special">{};</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">InputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Distance</span> <span class="special">)</span>
+<span class="keyword">void</span> <span class="special">(</span><span class="identifier">myadvance</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">InputIterator</span><span class="special">&amp;)</span> <span class="identifier">i</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Distance</span><span class="special">)</span> <span class="identifier">n</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="comment">// Precondition: All iterators in [i, i + n] non-singular.</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">is_input_iterator</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special">&lt;</span><span class="identifier">InputIterator</span><span class="special">&gt;::</span>
+ <span class="identifier">iterator_category</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">n</span> <span class="special">&gt;</span> <span class="number">0</span> <span class="comment">// if input iterator, n positive</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_i</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">i</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">old_i</span><span class="special">,</span> <span class="identifier">i</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">n</span> <span class="comment">// iterator advanced of n</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">aux</span><span class="special">::</span><span class="identifier">myadvance_dispatch</span><span class="special">(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special">&lt;</span><span class="identifier">InputIterator</span><span class="special">&gt;::</span>
+ <span class="identifier">iterator_category</span><span class="special">());</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___find__generic_find_algorithm"></a><a class="link" href="examples.html#contract__.examples.__n2081___find__generic_find_algorithm" title="[N2081] Find: Generic find algorithm">[N2081]
+ Find: Generic find algorithm</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">Iter</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="keyword">typename</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="special">(</span><span class="identifier">myfind</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">last</span><span class="special">,</span>
+ <span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">value</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">first</span> <span class="special">&lt;=</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">result</span> <span class="special">!=</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">value</span> <span class="special">==</span> <span class="special">*</span><span class="identifier">result</span> <span class="comment">// if result not last, value found</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">while</span><span class="special">(</span><span class="identifier">first</span> <span class="special">!=</span> <span class="identifier">last</span> <span class="special">&amp;&amp;</span> <span class="special">*</span><span class="identifier">first</span> <span class="special">!=</span> <span class="identifier">value</span><span class="special">)</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span> <span class="special">)</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">)</span>
+ <span class="special">++</span><span class="identifier">first</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">first</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___apply__overloaded_invocation_of_functors"></a><a class="link" href="examples.html#contract__.examples.__n2081___apply__overloaded_invocation_of_functors" title="[N2081] Apply: Overloaded invocation of functors">[N2081]
+ Apply: Overloaded invocation of functors</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="comment">// Use importance ordering to specify assertion computational complexity.</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_1</span> <span class="number">0</span> <span class="comment">// O(1) constant (default)</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_BODY</span> <span class="number">1</span> <span class="comment">// same computation complexity of the body</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Invoke unary functors.</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">Result</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Arg0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">UnaryOp</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="keyword">typename</span> <span class="identifier">CONTRACT_IDENTITY_TYPE</span><span class="special">((</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">UnaryFunction</span><span class="special">&lt;</span><span class="identifier">UnaryOp</span><span class="special">,</span> <span class="identifier">Result</span><span class="special">,</span> <span class="identifier">Arg0</span><span class="special">&gt;</span> <span class="special">))</span>
+<span class="preprocessor">#ifndef</span> <span class="identifier">CONTRACT_CONFIG_NO_POSTCONDITIONS</span> <span class="comment">// Equality only for postconditions.</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;</span>
+<span class="preprocessor">#endif</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="identifier">Result</span><span class="special">)</span> <span class="special">(</span><span class="identifier">apply</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">UnaryOp</span><span class="special">)</span> <span class="identifier">op</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Arg0</span><span class="special">)</span> <span class="identifier">arg0</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Result</span><span class="special">&amp;)</span> <span class="identifier">result</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">return_value</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">op</span><span class="special">(</span><span class="identifier">arg0</span><span class="special">),</span> <span class="identifier">importance</span> <span class="identifier">O_BODY</span><span class="special">,</span>
+ <span class="identifier">return_value</span> <span class="special">==</span> <span class="identifier">result</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">op</span><span class="special">(</span><span class="identifier">arg0</span><span class="special">);</span>
+<span class="special">}</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Overload to invoke binary functors.</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">Result</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Arg0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Arg1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">BinaryOp</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="keyword">typename</span> <span class="identifier">CONTRACT_INDETITY_TYPE</span><span class="special">((</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">BinaryFunction</span><span class="special">&lt;</span><span class="identifier">BinaryOp</span><span class="special">,</span> <span class="identifier">Result</span><span class="special">,</span> <span class="identifier">Arg0</span><span class="special">,</span> <span class="identifier">Arg1</span><span class="special">&gt;</span> <span class="special">))</span>
+<span class="preprocessor">#ifndef</span> <span class="identifier">CONTRACT_CONFIG_NO_POSTCONDITIONS</span> <span class="comment">// Equality only for postconditions.</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;</span>
+<span class="preprocessor">#endif</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="identifier">Result</span><span class="special">)</span> <span class="special">(</span><span class="identifier">apply</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">BinaryOp</span><span class="special">)</span> <span class="identifier">op</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Arg0</span><span class="special">)</span> <span class="identifier">arg0</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Arg1</span><span class="special">)</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Result</span><span class="special">&amp;)</span> <span class="identifier">result</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">return_value</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">op</span><span class="special">(</span><span class="identifier">arg0</span><span class="special">,</span> <span class="identifier">arg1</span><span class="special">),</span> <span class="identifier">importance</span> <span class="identifier">O_BODY</span><span class="special">,</span>
+ <span class="identifier">return_value</span> <span class="special">==</span> <span class="identifier">result</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">op</span><span class="special">(</span><span class="identifier">arg0</span><span class="special">,</span> <span class="identifier">arg1</span><span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___for_each__generic_for_each_algorithm"></a><a class="link" href="examples.html#contract__.examples.__n2081___for_each__generic_for_each_algorithm" title="[N2081] For Each: Generic for-each algorithm">[N2081]
+ For Each: Generic for-each algorithm</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">Iter</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Func</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;</span>
+ <span class="keyword">typename</span> <span class="identifier">CONTRACT_INDENTITY_TYPE</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">UnaryFunction</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">,</span> <span class="keyword">void</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span> <span class="special">))</span>
+<span class="preprocessor">#ifndef</span> <span class="identifier">CONTRACT_CONFIG_NO_POSTCONDITIONS</span> <span class="comment">// Equality only for postconditions.</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">&gt;</span>
+<span class="preprocessor">#endif</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="identifier">Func</span><span class="special">)</span> <span class="special">(</span><span class="identifier">my_for_each</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">last</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Func</span><span class="special">)</span> <span class="identifier">func</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">first</span> <span class="special">&lt;=</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">func</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">while</span><span class="special">(</span><span class="identifier">first</span> <span class="special">&lt;</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">)</span> <span class="special">{</span> <span class="comment">// OK: Iter is InputIterator.</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span> <span class="special">)</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">func</span><span class="special">(*</span><span class="identifier">first</span><span class="special">);</span> <span class="comment">// OK: func is UnaryFunction.</span>
+ <span class="special">++</span><span class="identifier">first</span><span class="special">;</span> <span class="comment">// OK: Iter is InputIterator.</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">func</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___transform__generic_binary_transformation_algorithm"></a><a class="link" href="examples.html#contract__.examples.__n2081___transform__generic_binary_transformation_algorithm" title="[N2081] Transform: Generic binary transformation algorithm">[N2081]
+ Transform: Generic binary transformation algorithm</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">CONTRACT_CONFIG_FUNCTION_ARITY_MAX</span> <span class="number">6</span> <span class="comment">// Support 5 function parameters.</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">algorithm</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">InIter1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">InIter2</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">OutIter</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">BinOp</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIter1</span><span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIter2</span><span class="special">&gt;,</span>
+ <span class="keyword">typename</span> <span class="identifier">CONTRACT_IDENTITY_TYPE</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">OutputIterator</span><span class="special">&lt;</span><span class="identifier">OutIter</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIter1</span><span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="special">&gt;</span> <span class="special">)),</span>
+ <span class="keyword">typename</span> <span class="identifier">CONTRACT_IDENTITY_TYPE</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">BinaryFunction</span><span class="special">&lt;</span><span class="identifier">BinOp</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIter1</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIter1</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIter2</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span> <span class="special">))</span>
+<span class="preprocessor">#ifndef</span> <span class="identifier">CONTRACT_CONFIG_NO_POSTCONDITIONS</span> <span class="comment">// Equality only for postcondition</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="keyword">typename</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">InIter1</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span>
+<span class="preprocessor">#endif</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="identifier">OutIter</span><span class="special">)</span> <span class="special">(</span><span class="identifier">mytransform</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">InIter1</span><span class="special">)</span> <span class="identifier">first1</span><span class="special">,</span> <span class="special">(</span><span class="identifier">InIter1</span><span class="special">)</span> <span class="identifier">last1</span><span class="special">,</span> <span class="special">(</span><span class="identifier">InIter2</span><span class="special">)</span> <span class="identifier">first2</span><span class="special">,</span>
+ <span class="special">(</span><span class="identifier">OutIter</span><span class="special">)</span> <span class="identifier">result</span><span class="special">,</span> <span class="special">(</span><span class="identifier">BinOp</span><span class="special">)</span> <span class="identifier">op</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">first1</span> <span class="special">&lt;=</span> <span class="identifier">last1</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">return_value</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">return_value</span> <span class="special">==</span> <span class="identifier">result</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">transform</span><span class="special">(</span><span class="identifier">first1</span><span class="special">,</span> <span class="identifier">last1</span><span class="special">,</span> <span class="identifier">first2</span><span class="special">,</span> <span class="identifier">result</span><span class="special">,</span> <span class="identifier">op</span><span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___count__generic_count_algorithm"></a><a class="link" href="examples.html#contract__.examples.__n2081___count__generic_count_algorithm" title="[N2081] Count: Generic count algorithm">[N2081]
+ Count: Generic count algorithm</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">Iter</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="keyword">typename</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">difference_type</span><span class="special">)</span> <span class="special">(</span><span class="identifier">mycount</span><span class="special">)</span> <span class="special">(</span>
+ <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">last</span><span class="special">,</span>
+ <span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">value</span> <span class="special">)</span>
+ <span class="comment">// Precondition: [first, last) is valid range.</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">first</span> <span class="special">&lt;=</span> <span class="identifier">last</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">difference_type</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">while</span><span class="special">(</span><span class="identifier">first</span> <span class="special">!=</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">)</span> <span class="special">{</span> <span class="comment">// OK: Iter is equality comparable.</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span> <span class="special">)</span>
+ <span class="keyword">if</span><span class="special">(*</span><span class="identifier">first</span> <span class="special">==</span> <span class="identifier">value</span><span class="special">)</span> <span class="comment">// OK: Value is equality comparable.</span>
+ <span class="special">++</span><span class="identifier">result</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">first</span><span class="special">;</span> <span class="comment">// OK: Iterator is input iterator.</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span> <span class="comment">// OK: Input iterator difference is copy constructible.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___convert__conversion_between_two_types"></a><a class="link" href="examples.html#contract__.examples.__n2081___convert__conversion_between_two_types" title="[N2081] Convert: Conversion between two types">[N2081]
+ Convert: Conversion between two types</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">To</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">From</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="keyword">typename</span> <span class="identifier">CONTRACT_IDENTITY_TYPE</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">Convertible</span><span class="special">&lt;</span><span class="identifier">From</span><span class="special">,</span> <span class="identifier">To</span><span class="special">&gt;</span> <span class="special">))</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="identifier">To</span><span class="special">)</span> <span class="special">(</span><span class="identifier">convert</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">From</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">from</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">from</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___equal__generic_equality_comparison"></a><a class="link" href="examples.html#contract__.examples.__n2081___equal__generic_equality_comparison" title="[N2081] Equal: Generic equality comparison">[N2081]
+ Equal: Generic equality comparison</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">)</span>
+<span class="keyword">bool</span> <span class="special">(</span><span class="identifier">equal</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">left</span><span class="special">,</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">left</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">)</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">left</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___less_equal__generic_less_than_or_equal_to_comparison"></a><a class="link" href="examples.html#contract__.examples.__n2081___less_equal__generic_less_than_or_equal_to_comparison" title="[N2081] Less Equal: Generic less-than or equal-to comparison">[N2081]
+ Less Equal: Generic less-than or equal-to comparison</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">LessThanComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">)</span>
+<span class="keyword">bool</span> <span class="special">(</span><span class="identifier">leq</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">left</span><span class="special">,</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">left</span> <span class="special">&lt;</span> <span class="identifier">right</span> <span class="special">||</span> <span class="identifier">left</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">)</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">left</span> <span class="special">&lt;</span> <span class="identifier">right</span> <span class="special">||</span> <span class="identifier">left</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___de_ref__generic_iterator_dereferencing"></a><a class="link" href="examples.html#contract__.examples.__n2081___de_ref__generic_iterator_dereferencing" title="[N2081] De-Ref: Generic iterator dereferencing">[N2081]
+ De-Ref: Generic iterator dereferencing</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">Iter</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">CopyConstructible</span><span class="special">&lt;</span><span class="keyword">typename</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;,</span>
+<span class="preprocessor">#ifndef</span> <span class="identifier">CONTRACT_CONFIG_NO_POSTCONDITIONS</span> <span class="comment">// Equality only for postconditions.</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="keyword">typename</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span>
+<span class="preprocessor">#endif</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span><span class="special">&lt;</span><span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">)</span> <span class="special">(</span><span class="identifier">deref</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Iter</span><span class="special">)</span> <span class="identifier">i</span> <span class="special">)</span>
+ <span class="comment">// Precondition: i is non-singular.</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">==</span> <span class="special">*</span><span class="identifier">i</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="special">*</span><span class="identifier">i</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__n2081___min__generic_minimum_algorithm"></a><a class="link" href="examples.html#contract__.examples.__n2081___min__generic_minimum_algorithm" title="[N2081] Min: Generic minimum algorithm">[N2081]
+ Min: Generic minimum algorithm</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">concept_check</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+ <span class="identifier">requires</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">LessThanComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span>
+<span class="preprocessor">#ifndef</span> <span class="identifier">CONTRACT_CONFIG_NO_POSTCONDITIONS</span> <span class="comment">// Equality only for postconditions.</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">EqualityComparable</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span>
+<span class="preprocessor">#endif</span>
+ <span class="special">)</span>
+<span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">min</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">x</span><span class="special">,</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">y</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">x</span> <span class="special">&lt;</span> <span class="identifier">y</span> <span class="special">?</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">x</span> <span class="special">:</span> <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">y</span> <span class="comment">// Need both `&lt;` and `==`.</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">&lt;</span> <span class="identifier">y</span> <span class="special">?</span> <span class="identifier">x</span> <span class="special">:</span> <span class="identifier">y</span><span class="special">;</span> <span class="comment">// OK: T is less than comparable `&lt;`.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.meyer97_stack4"></a><a class="link" href="examples.html#contract__.examples.meyer97_stack4" title="[Meyer97] Stack4: Comparison with Eiffel syntax">[Meyer97] Stack4:
+ Comparison with Eiffel syntax</a>
+</h3></div></div></div>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ ISO C++ (this library)
+ </p>
+ </th>
+<th>
+ <p>
+ Eiffel (<a class="link" href="bibliography.html" title="Bibliography">[Meyer97]</a>)
+ </p>
+ </th>
+</tr></thead>
+<tbody><tr>
+<td>
+ <p>
+
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// In header: stack4.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="comment">// Specification.</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Dispenser with LIFO access policy and a fixed max capacity.</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">stack4</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">,</span> <span class="comment">// count non negative</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">&lt;=</span> <span class="identifier">capacity</span><span class="special">(),</span> <span class="comment">// count bounded</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="comment">// empty if no elements</span>
+ <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Initialization.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Allocate stack for a maximum of n elements.</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">stack4</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;)</span> <span class="identifier">n</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">n</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="comment">// non negative capacity</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">n</span> <span class="comment">// capacity set</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span> <span class="comment">// Deferred body definition (see bottom).</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Deep copy.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">stack4</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">stack4</span><span class="special">&amp;)</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">capacity</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span>
+ <span class="comment">// all items equal right's items one by one</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Deep assignment.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">stack4</span><span class="special">&amp;)</span> <span class="keyword">operator</span><span class="special">(=)(</span><span class="identifier">assign</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">stack4</span><span class="special">&amp;)</span> <span class="identifier">right</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">capacity</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span>
+ <span class="comment">// all items equal right's items one by one</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Destroy this stack.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">stack4</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Access.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Max number of stack elements.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">capacity</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Number of stack elements.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Top element.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">item</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="comment">// not empty (i.e., count &gt; 0)</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Status report.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Is stack empty?</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">empty</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="comment">// empty definition</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Is stack full?</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">full</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">capacity</span><span class="special">())</span> <span class="comment">// full definition</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Element change.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Add x on top.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">x</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">full</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="comment">// not full</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">,</span> <span class="comment">// not empty</span>
+ <span class="identifier">item</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">x</span><span class="special">,</span> <span class="comment">// added to top</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">+</span> <span class="number">1</span> <span class="comment">// one more item</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Remove top item.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">remove</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="comment">// not empty (i.e., count &gt; 0)</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">full</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">,</span> <span class="comment">// not full</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">-</span> <span class="number">1</span> <span class="comment">// one fewer item</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">capacity_</span><span class="special">;</span>
+ <span class="keyword">int</span> <span class="identifier">count_</span><span class="special">;</span>
+ <span class="identifier">T</span><span class="special">*</span> <span class="identifier">representation_</span><span class="special">;</span> <span class="comment">// Using C-style array.</span>
+<span class="special">};</span>
+
+<span class="comment">// Implementation.</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;,</span> <span class="identifier">stack4</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">n</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">capacity_</span> <span class="special">=</span> <span class="identifier">n</span><span class="special">;</span>
+ <span class="identifier">count_</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">representation_</span> <span class="special">=</span> <span class="keyword">new</span> <span class="identifier">T</span><span class="special">[</span><span class="identifier">n</span><span class="special">];</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;,</span> <span class="identifier">stack4</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">stack4</span><span class="special">&amp;</span> <span class="identifier">right</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">capacity_</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">capacity_</span><span class="special">;</span>
+ <span class="identifier">count_</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">count_</span><span class="special">;</span>
+ <span class="identifier">representation_</span> <span class="special">=</span> <span class="keyword">new</span> <span class="identifier">T</span><span class="special">[</span><span class="identifier">right</span><span class="special">.</span><span class="identifier">capacity_</span><span class="special">];</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">count_</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">representation_</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">representation_</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="keyword">operator</span><span class="special">(=)(</span><span class="identifier">assign</span><span class="special">))</span> <span class="special">(</span>
+ <span class="keyword">const</span> <span class="identifier">stack4</span><span class="special">&amp;</span> <span class="identifier">right</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">delete</span><span class="special">[]</span> <span class="identifier">representation_</span><span class="special">;</span>
+ <span class="identifier">capacity_</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">capacity_</span><span class="special">;</span>
+ <span class="identifier">count_</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">count_</span><span class="special">;</span>
+ <span class="identifier">representation_</span> <span class="special">=</span> <span class="keyword">new</span> <span class="identifier">T</span><span class="special">[</span><span class="identifier">right</span><span class="special">.</span><span class="identifier">capacity_</span><span class="special">];</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">count_</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">representation_</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">representation_</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span>
+ <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="identifier">CONTRACT_DESTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;,</span> <span class="special">~</span><span class="identifier">stack4</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">delete</span><span class="special">[]</span> <span class="identifier">representation_</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">int</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">capacity</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">capacity_</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">int</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">count_</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">item</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">representation_</span><span class="special">[</span><span class="identifier">count</span><span class="special">()</span> <span class="special">-</span> <span class="number">1</span><span class="special">];</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">bool</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">empty</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">bool</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">full</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">capacity</span><span class="special">();</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">void</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">x</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">representation_</span><span class="special">[</span><span class="identifier">count_</span><span class="special">++]</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
+<span class="keyword">void</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">remove</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="special">--</span><span class="identifier">count_</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+ </td>
+<td>
+ <p>
+
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">--</span> <span class="identifier">Extra</span> <span class="identifier">spacing</span> <span class="keyword">and</span> <span class="identifier">newlines</span> <span class="identifier">used</span> <span class="identifier">to</span> <span class="identifier">visually</span> <span class="identifier">align</span> <span class="identifier">with</span> <span class="keyword">this</span> <span class="identifier">library</span> <span class="identifier">code</span><span class="special">.</span>
+
+
+
+
+<span class="identifier">indexing</span>
+ <span class="identifier">destription</span><span class="special">:</span> <span class="string">"Dispenser with LIFO access policy and a fixed max capacity."</span>
+<span class="keyword">class</span> <span class="identifier">interface</span> <span class="identifier">STACK4</span><span class="special">[</span><span class="identifier">G</span><span class="special">]</span> <span class="identifier">creation</span> <span class="identifier">make</span>
+
+<span class="identifier">invariant</span>
+ <span class="identifier">count_non_negative</span><span class="special">:</span> <span class="identifier">count</span> <span class="special">&gt;=</span> <span class="number">0</span>
+ <span class="identifier">count_bounded</span><span class="special">:</span> <span class="identifier">count</span> <span class="special">&lt;=</span> <span class="identifier">capacity</span>
+ <span class="identifier">empty_if_no_elements</span><span class="special">:</span> <span class="identifier">empty</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">count</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span>
+
+
+
+<span class="identifier">feature</span> <span class="special">--</span> <span class="identifier">Initialization</span><span class="special">.</span>
+
+ <span class="special">--</span> <span class="identifier">Allocate</span> <span class="identifier">stack</span> <span class="keyword">for</span> <span class="identifier">a</span> <span class="identifier">maximum</span> <span class="identifier">of</span> <span class="identifier">n</span> <span class="identifier">elements</span><span class="special">.</span>
+ <span class="identifier">make</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">:</span> <span class="identifier">INTEGER</span> <span class="special">)</span> <span class="identifier">is</span>
+ <span class="identifier">require</span>
+ <span class="identifier">non_negative_capacity</span><span class="special">:</span> <span class="identifier">n</span> <span class="special">&gt;=</span> <span class="number">0</span>
+
+ <span class="identifier">ensure</span>
+ <span class="identifier">capacity_set</span><span class="special">:</span> <span class="identifier">capacity</span> <span class="special">=</span> <span class="identifier">n</span>
+
+ <span class="identifier">end</span>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<span class="identifier">feature</span> <span class="special">--</span> <span class="identifier">Access</span><span class="special">.</span>
+
+ <span class="special">--</span> <span class="identifier">Max</span> <span class="identifier">number</span> <span class="identifier">of</span> <span class="identifier">stack</span> <span class="identifier">elements</span><span class="special">.</span>
+ <span class="identifier">capacity</span> <span class="special">:</span> <span class="identifier">INTEGER</span>
+
+
+ <span class="special">--</span> <span class="identifier">Number</span> <span class="identifier">of</span> <span class="identifier">stack</span> <span class="identifier">elements</span><span class="special">.</span>
+ <span class="identifier">count</span> <span class="special">:</span> <span class="identifier">INTEGER</span>
+
+
+ <span class="special">--</span> <span class="identifier">Top</span> <span class="identifier">element</span>
+ <span class="identifier">item</span> <span class="special">:</span> <span class="identifier">G</span> <span class="identifier">is</span>
+ <span class="identifier">require</span>
+ <span class="identifier">not_empty</span><span class="special">:</span> <span class="keyword">not</span> <span class="identifier">empty</span> <span class="special">--</span> <span class="identifier">i</span><span class="special">.</span><span class="identifier">e</span><span class="special">.,</span> <span class="identifier">count</span> <span class="special">&gt;</span> <span class="number">0</span>
+
+ <span class="identifier">end</span>
+
+<span class="identifier">feature</span> <span class="special">--</span> <span class="identifier">Status</span> <span class="identifier">report</span><span class="special">.</span>
+
+ <span class="special">--</span> <span class="identifier">Is</span> <span class="identifier">stack</span> <span class="identifier">empty</span><span class="special">?</span>
+ <span class="identifier">empty</span> <span class="special">:</span> <span class="identifier">BOOLEAN</span> <span class="identifier">is</span>
+ <span class="identifier">ensure</span>
+
+ <span class="identifier">empty_definition</span><span class="special">:</span> <span class="identifier">result</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">count</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span>
+
+ <span class="identifier">end</span>
+
+ <span class="special">--</span> <span class="identifier">Is</span> <span class="identifier">stack</span> <span class="identifier">full</span><span class="special">?</span>
+ <span class="identifier">full</span> <span class="special">:</span> <span class="identifier">BOOLEAN</span> <span class="identifier">is</span>
+ <span class="identifier">ensure</span>
+
+ <span class="identifier">full_definition</span><span class="special">:</span> <span class="identifier">result</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">count</span> <span class="special">=</span> <span class="identifier">capacity</span><span class="special">)</span>
+
+ <span class="identifier">end</span>
+
+<span class="identifier">feature</span> <span class="special">--</span> <span class="identifier">Element</span> <span class="identifier">change</span><span class="special">.</span>
+
+ <span class="special">--</span> <span class="identifier">Add</span> <span class="identifier">x</span> <span class="identifier">on</span> <span class="identifier">top</span><span class="special">.</span>
+ <span class="identifier">put</span> <span class="special">(</span> <span class="identifier">x</span> <span class="special">:</span> <span class="identifier">G</span> <span class="special">)</span> <span class="identifier">is</span>
+ <span class="identifier">require</span>
+ <span class="identifier">not_full</span><span class="special">:</span> <span class="keyword">not</span> <span class="identifier">full</span>
+
+ <span class="identifier">ensure</span>
+
+ <span class="identifier">not_empty</span><span class="special">:</span> <span class="keyword">not</span> <span class="identifier">empty</span>
+ <span class="identifier">added_to_top</span><span class="special">:</span> <span class="identifier">item</span> <span class="special">=</span> <span class="identifier">x</span>
+ <span class="identifier">one_more_item</span><span class="special">:</span> <span class="identifier">count</span> <span class="special">=</span> <span class="identifier">old</span> <span class="identifier">count</span> <span class="special">+</span> <span class="number">1</span>
+
+ <span class="identifier">end</span>
+
+ <span class="special">--</span> <span class="identifier">Remove</span> <span class="identifier">top</span> <span class="identifier">element</span><span class="special">.</span>
+ <span class="identifier">remove</span> <span class="identifier">is</span>
+ <span class="identifier">require</span>
+ <span class="identifier">not_empty</span><span class="special">:</span> <span class="keyword">not</span> <span class="identifier">empty</span> <span class="special">--</span> <span class="identifier">i</span><span class="special">.</span><span class="identifier">e</span><span class="special">.,</span> <span class="identifier">count</span> <span class="special">&gt;</span> <span class="number">0</span>
+
+ <span class="identifier">ensure</span>
+
+ <span class="identifier">not_full</span><span class="special">:</span> <span class="keyword">not</span> <span class="identifier">full</span>
+ <span class="identifier">one_fewer_item</span><span class="special">:</span> <span class="identifier">count</span> <span class="special">=</span> <span class="identifier">old</span> <span class="identifier">count</span> <span class="special">-</span> <span class="number">1</span>
+
+ <span class="identifier">end</span>
+
+
+
+
+
+<span class="identifier">end</span> <span class="special">--</span> <span class="keyword">class</span> <span class="identifier">interface</span> <span class="identifier">STACK4</span>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+</pre>
+<p>
+ </p>
+ </td>
+</tr></tbody>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__meyer97___stack3__error_codes_instead_of_preconditions"></a><a class="link" href="examples.html#contract__.examples.__meyer97___stack3__error_codes_instead_of_preconditions" title="[Meyer97] Stack3: Error codes instead of preconditions">[Meyer97]
+ Stack3: Error codes instead of preconditions</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"stack4.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Dispenser LIFO and max capacity using error codes.</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">stack3</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// no class invariant</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">enum</span> <span class="identifier">Error</span> <span class="special">{</span> <span class="comment">// Error codes.</span>
+ <span class="identifier">NO_ERROR</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span>
+ <span class="identifier">OVERFLOW_ERROR</span><span class="special">,</span>
+ <span class="identifier">UNDERFLOW_ERROR</span><span class="special">,</span>
+ <span class="identifier">SIZE_ERROR</span>
+ <span class="special">};</span>
+
+ <span class="comment">// Initialization.</span>
+
+ <span class="comment">// Create stack for max of n elements, if n &lt; 0 set error (no precondition).</span>
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">stack3</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;)</span> <span class="identifier">n</span><span class="special">,</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">none</span><span class="special">,</span> <span class="keyword">default</span> <span class="identifier">T</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">none_</span><span class="special">(</span><span class="identifier">none</span><span class="special">),</span> <span class="identifier">representation_</span><span class="special">(</span><span class="number">0</span><span class="special">),</span> <span class="identifier">error_</span><span class="special">(</span><span class="identifier">NO_ERROR</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="special">(</span><span class="identifier">n</span> <span class="special">&lt;</span> <span class="number">0</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">error</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">SIZE_ERROR</span><span class="special">),</span> <span class="comment">// error if impossible</span>
+ <span class="special">(</span><span class="identifier">n</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">)</span> <span class="special">==</span> <span class="special">!</span><span class="identifier">error</span><span class="special">(),</span> <span class="comment">// no error if possible</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="keyword">bool</span><span class="special">(!</span><span class="identifier">error</span><span class="special">()))</span> <span class="special">(</span> <span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">n</span> <span class="special">)</span> <span class="comment">// created if no error</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">n</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">)</span> <span class="identifier">representation_</span> <span class="special">=</span> <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;(</span><span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span> <span class="identifier">error_</span> <span class="special">=</span> <span class="identifier">SIZE_ERROR</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Destroy stack.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">stack3</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// Access.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Max number of stack elements.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">capacity</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">representation_</span><span class="special">.</span><span class="identifier">capacity</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Number of stack elements.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">representation_</span><span class="special">.</span><span class="identifier">count</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Top element if present, otherwise set error (no precondition).</span>
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">item</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">error</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">UNDERFLOW_ERROR</span><span class="special">),</span> <span class="comment">// error if impossible</span>
+ <span class="keyword">bool</span><span class="special">(!</span><span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="special">!</span><span class="identifier">error</span><span class="special">())</span> <span class="comment">// no error if possible</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(!</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">{</span>
+ <span class="identifier">error_</span> <span class="special">=</span> <span class="identifier">NO_ERROR</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="identifier">representation_</span><span class="special">.</span><span class="identifier">item</span><span class="special">();</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+ <span class="identifier">error_</span> <span class="special">=</span> <span class="identifier">UNDERFLOW_ERROR</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="identifier">none_</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Status report.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Error indicator set by various operations.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">Error</span><span class="special">)</span> <span class="special">(</span><span class="identifier">error</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">error_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Is stack empty?</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">empty</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">representation_</span><span class="special">.</span><span class="identifier">empty</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Is stack full?</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">full</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">representation_</span><span class="special">.</span><span class="identifier">full</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Element change.</span>
+
+ <span class="comment">// Add x to top if capacity left, otherwise set error (no precondition).</span>
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;)</span> <span class="identifier">x</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_full</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">full</span><span class="special">(),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">old_full</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">error</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">OVERFLOW_ERROR</span><span class="special">),</span> <span class="comment">// error if impossible</span>
+ <span class="keyword">bool</span><span class="special">(!</span><span class="identifier">old_full</span> <span class="special">==</span> <span class="special">!</span><span class="identifier">error</span><span class="special">()),</span> <span class="comment">// no error if possible</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="keyword">bool</span><span class="special">(!</span><span class="identifier">error</span><span class="special">()))</span> <span class="special">(</span>
+ <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">,</span> <span class="comment">// not empty if no error</span>
+ <span class="identifier">item</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">x</span><span class="special">,</span> <span class="comment">// added to top is no error</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">+</span> <span class="number">1</span> <span class="comment">// one more item if no error</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">full</span><span class="special">())</span> <span class="special">{</span>
+ <span class="identifier">error_</span> <span class="special">=</span> <span class="identifier">OVERFLOW_ERROR</span><span class="special">;</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+ <span class="identifier">representation_</span><span class="special">.</span><span class="identifier">put</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
+ <span class="identifier">error_</span> <span class="special">=</span> <span class="identifier">NO_ERROR</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Remove top item if possible, otherwise set error to (no precondition).</span>
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">remove</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_empty</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">empty</span><span class="special">(),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">old_empty</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">error</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">UNDERFLOW_ERROR</span><span class="special">),</span> <span class="comment">// error if impossible</span>
+ <span class="keyword">bool</span><span class="special">(!</span><span class="identifier">old_empty</span> <span class="special">==</span> <span class="special">!</span><span class="identifier">error</span><span class="special">()),</span> <span class="comment">// no error if possible</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="keyword">bool</span><span class="special">(!</span><span class="identifier">error</span><span class="special">()))</span> <span class="special">(</span>
+ <span class="identifier">full</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">,</span> <span class="comment">// not full is no error</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">-</span> <span class="number">1</span> <span class="comment">// one fewer item if no error</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">empty</span><span class="special">())</span> <span class="special">{</span>
+ <span class="identifier">error_</span> <span class="special">=</span> <span class="identifier">UNDERFLOW_ERROR</span><span class="special">;</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+ <span class="identifier">representation_</span><span class="special">.</span><span class="identifier">remove</span><span class="special">();</span>
+ <span class="identifier">error_</span> <span class="special">=</span> <span class="identifier">NO_ERROR</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">none_</span><span class="special">;</span>
+ <span class="identifier">stack4</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">representation_</span><span class="special">;</span>
+ <span class="keyword">mutable</span> <span class="identifier">Error</span> <span class="identifier">error_</span><span class="special">;</span> <span class="comment">// Mutable as changed by logically const members.</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.meyer97_gcd"></a><a class="link" href="examples.html#contract__.examples.meyer97_gcd" title="[Meyer97] GCD: Loop variant and comparison with Eiffel syntax">[Meyer97] GCD: Loop
+ variant and comparison with Eiffel syntax</a>
+</h3></div></div></div>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ ISO C++ (this library)
+ </p>
+ </th>
+<th>
+ <p>
+ Eiffel (<a class="link" href="bibliography.html" title="Bibliography">[Meyer97]</a>)
+ </p>
+ </th>
+</tr></thead>
+<tbody><tr>
+<td>
+ <p>
+
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">algorithm</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Great common divisor of given positive integers.</span>
+<span class="keyword">int</span> <span class="special">(</span><span class="identifier">gcd</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">a</span> <span class="special">&gt;</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="number">0</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">b</span><span class="special">;</span>
+
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">while</span><span class="special">(</span><span class="identifier">x</span> <span class="special">!=</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">)</span> <span class="special">{</span> <span class="comment">// Loop contracted with a variant.</span>
+ <span class="identifier">CONTRACT_BLOCK_INVARIANT</span><span class="special">(</span> <span class="comment">// Block invariant assert loop invariant.</span>
+ <span class="keyword">const</span><span class="special">(</span> <span class="identifier">x</span> <span class="special">)</span> <span class="identifier">x</span> <span class="special">&gt;</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">y</span> <span class="special">)</span> <span class="identifier">y</span> <span class="special">&gt;</span> <span class="number">0</span>
+ <span class="comment">// x and y have the same GCD as a and b.</span>
+ <span class="special">)</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="comment">// Loop variant is a non-negative and</span>
+ <span class="keyword">const</span><span class="special">(</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span> <span class="special">)</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">)</span> <span class="comment">// monotonically decreasing expression.</span>
+ <span class="special">)</span>
+
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">x</span> <span class="special">&gt;</span> <span class="identifier">y</span><span class="special">)</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">x</span> <span class="special">-</span> <span class="identifier">y</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">y</span> <span class="special">-</span> <span class="identifier">x</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+ </td>
+<td>
+ <p>
+
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">--</span> <span class="identifier">Extra</span> <span class="identifier">spacing</span> <span class="keyword">and</span> <span class="identifier">newlines</span> <span class="identifier">used</span> <span class="identifier">to</span> <span class="identifier">visually</span> <span class="identifier">align</span> <span class="identifier">with</span> <span class="keyword">this</span> <span class="identifier">library</span> <span class="identifier">code</span><span class="special">.</span>
+
+
+<span class="special">--</span> <span class="identifier">Greatest</span> <span class="identifier">common</span> <span class="identifier">divisor</span> <span class="identifier">of</span> <span class="identifier">a</span> <span class="keyword">and</span> <span class="identifier">b</span><span class="special">.</span>
+<span class="identifier">gcd</span> <span class="special">(</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">:</span> <span class="identifier">INTEGER</span> <span class="special">)</span> <span class="special">:</span> <span class="identifier">INTEGER</span> <span class="identifier">is</span>
+ <span class="identifier">require</span>
+ <span class="identifier">a</span> <span class="special">&gt;</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">b</span> <span class="special">&gt;</span><span class="number">0</span>
+ <span class="identifier">local</span>
+ <span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span> <span class="special">:</span> <span class="identifier">INTEGER</span>
+ <span class="keyword">do</span>
+ <span class="identifier">from</span>
+ <span class="identifier">x</span> <span class="special">:=</span> <span class="identifier">a</span><span class="special">;</span> <span class="identifier">y</span> <span class="special">:=</span> <span class="identifier">b</span>
+ <span class="identifier">invariant</span>
+ <span class="identifier">x</span> <span class="special">&gt;</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">y</span> <span class="special">&gt;</span> <span class="number">0</span>
+ <span class="special">--</span> <span class="identifier">x</span> <span class="keyword">and</span> <span class="identifier">y</span> <span class="identifier">have</span> <span class="identifier">the</span> <span class="identifier">same</span> <span class="identifier">GCD</span> <span class="identifier">as</span> <span class="identifier">a</span> <span class="keyword">and</span> <span class="identifier">b</span><span class="special">.</span>
+
+ <span class="identifier">variant</span>
+ <span class="identifier">x</span><span class="special">.</span><span class="identifier">max</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span>
+ <span class="identifier">until</span>
+ <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">y</span>
+ <span class="identifier">loop</span>
+ <span class="keyword">if</span> <span class="identifier">x</span> <span class="special">&gt;</span> <span class="identifier">y</span> <span class="identifier">then</span> <span class="identifier">x</span> <span class="special">:=</span> <span class="identifier">x</span> <span class="special">-</span> <span class="identifier">y</span> <span class="keyword">else</span> <span class="identifier">y</span> <span class="special">:=</span> <span class="identifier">y</span> <span class="special">-</span> <span class="identifier">x</span> <span class="identifier">end</span>
+ <span class="identifier">end</span>
+ <span class="identifier">Result</span> <span class="special">:=</span> <span class="identifier">x</span>
+ <span class="identifier">end</span>
+</pre>
+<p>
+ </p>
+ </td>
+</tr></tbody>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__meyer97___max_array__nested_loop_variants"></a><a class="link" href="examples.html#contract__.examples.__meyer97___max_array__nested_loop_variants" title="[Meyer97] Max Array: Nested loop variants">[Meyer97]
+ Max Array: Nested loop variants</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">algorithm</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">int</span> <span class="special">(</span><span class="identifier">maxarray</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">int</span> <span class="keyword">const</span><span class="special">*</span> <span class="keyword">const</span><span class="special">)</span> <span class="identifier">array</span><span class="special">,</span> <span class="special">(</span><span class="identifier">size_t</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">size</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">array</span><span class="special">,</span> <span class="comment">// array allocated</span>
+ <span class="identifier">size</span> <span class="special">&gt;=</span> <span class="number">1</span> <span class="comment">// size in range</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">maxnow</span> <span class="special">=</span> <span class="identifier">array</span><span class="special">[</span><span class="number">0</span><span class="special">];</span>
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">for</span><span class="special">(</span><span class="identifier">size_t</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="special">(</span><span class="identifier">size</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Nested loop (with variant) used to assert enclosing loop invariants.</span>
+ <span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="keyword">for</span><span class="special">(</span><span class="identifier">size_t</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">j</span> <span class="special">&lt;</span> <span class="identifier">i</span><span class="special">;</span> <span class="special">++</span><span class="identifier">j</span><span class="special">)</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">j</span> <span class="special">)</span> <span class="identifier">i</span> <span class="special">-</span> <span class="identifier">j</span> <span class="special">)</span>
+ <span class="identifier">CONTRACT_BLOCK_INVARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">maxnow</span><span class="special">,</span> <span class="identifier">array</span><span class="special">,</span> <span class="identifier">j</span> <span class="special">)</span>
+ <span class="identifier">maxnow</span> <span class="special">&gt;=</span> <span class="identifier">array</span><span class="special">[</span><span class="identifier">j</span><span class="special">]</span> <span class="special">)</span>
+ <span class="special">}</span>
+ <span class="comment">// -2 because starts from 0 (not 1) and already done element at 0.</span>
+ <span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="keyword">const</span><span class="special">(</span> <span class="identifier">size</span><span class="special">,</span> <span class="identifier">i</span> <span class="special">)</span> <span class="identifier">size</span> <span class="special">-</span> <span class="identifier">i</span> <span class="special">-</span> <span class="number">2</span> <span class="special">)</span>
+
+ <span class="identifier">maxnow</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="identifier">maxnow</span><span class="special">,</span> <span class="identifier">array</span><span class="special">[</span><span class="identifier">i</span><span class="special">]);</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">maxnow</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__mitchell02___name_list__relaxing_subcontracts"></a><a class="link" href="examples.html#contract__.examples.__mitchell02___name_list__relaxing_subcontracts" title="[Mitchell02] Name List: Relaxing subcontracts">[Mitchell02]
+ Name List: Relaxing subcontracts</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: name_list.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">list</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// List of names.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">name_list</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// non-negative count</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create an empty list.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">name_list</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// empty list</span>
+ <span class="special">)</span> <span class="special">;</span> <span class="comment">// Deferred body definition.</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy list.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">name_list</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Number of names in list.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="comment">// Postcondition non-negative count already in class invariants.</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Is name in list?</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">has</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">name</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">result</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span> <span class="comment">// does not have is empty</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Add name to list.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">name</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">has</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">false</span> <span class="comment">// not already in list</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_has_name</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">has</span><span class="special">(</span><span class="identifier">name</span><span class="special">),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="comment">// Following if-guard allows to relax subcontracts.</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_has_name</span> <span class="special">==</span> <span class="keyword">false</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">has</span><span class="special">(</span><span class="identifier">name</span><span class="special">),</span> <span class="comment">// name on list</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">+</span> <span class="number">1</span> <span class="comment">// number of names increased</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;</span> <span class="identifier">names_</span><span class="special">;</span>
+
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// List of names that allows for duplicates.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">relaxed_name_list</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="keyword">public</span> <span class="identifier">name_list</span> <span class="special">)</span> <span class="comment">// Subcontracting.</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// no subcontracted invariants</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create an empty list.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">relaxed_name_list</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy list.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">relaxed_name_list</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Add name to list.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">name</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="comment">// Relax inherited precondition.</span>
+ <span class="identifier">has</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span> <span class="comment">// already in list</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_has_name</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">has</span><span class="special">(</span><span class="identifier">name</span><span class="special">),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="comment">// Inherited postcondition not checked because of its if-guard.</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_has_name</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="comment">// count unchanged if name already in list</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"name_list.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">algorithm</span><span class="special">&gt;</span>
+
+<span class="comment">// name_list</span>
+
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">name_list</span><span class="special">,</span> <span class="identifier">name_list</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{}</span>
+
+<span class="identifier">CONTRACT_DESTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">name_list</span><span class="special">,</span> <span class="special">~</span><span class="identifier">name_list</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{}</span>
+
+<span class="keyword">int</span> <span class="identifier">name_list</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">names_</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span> <span class="special">}</span>
+
+<span class="keyword">bool</span> <span class="identifier">name_list</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">has</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">name</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">names_</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">!=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">names_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">names_</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">name</span><span class="special">);</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">name_list</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">name</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">names_</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">name</span><span class="special">);</span> <span class="special">}</span>
+
+<span class="comment">// relaxed_name_list</span>
+
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">relaxed_name_list</span><span class="special">,</span> <span class="identifier">relaxed_named_list</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{}</span>
+
+<span class="identifier">CONTRACT_DESTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">relaxed_name_list</span><span class="special">,</span> <span class="special">~</span><span class="identifier">relaxed_named_list</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{}</span>
+
+<span class="keyword">void</span> <span class="identifier">relaxed_name_list</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">name</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Must use `BODY` to call base functions (to avoid infinite recursion).</span>
+ <span class="keyword">if</span><span class="special">(!</span><span class="identifier">has</span><span class="special">(</span><span class="identifier">name</span><span class="special">))</span> <span class="identifier">name_list</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">put</span><span class="special">)(</span><span class="identifier">name</span><span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__mitchell02___dictionary__simple_key_value_map"></a><a class="link" href="examples.html#contract__.examples.__mitchell02___dictionary__simple_key_value_map" title="[Mitchell02] Dictionary: Simple key-value map">[Mitchell02]
+ Dictionary: Simple key-value map</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">utility</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">map</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Simple dictionary.</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">Key</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Value</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">dictionary</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// non-negative count</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Create empty dictionary.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">dictionary</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// empty</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Destroy dictionary.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">dictionary</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// Basic queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Number of key entires.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="comment">// Postcondition: non-negative count asserted by class invariants.</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Has entry for key?</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">has</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Key</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">key</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">result</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span> <span class="comment">// empty has no key</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">key</span><span class="special">)</span> <span class="special">!=</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Value for given key.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">Value</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">value_for</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Key</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">key</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">has</span><span class="special">(</span><span class="identifier">key</span><span class="special">)</span> <span class="special">)</span> <span class="comment">// has key</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">key</span><span class="special">)-&gt;</span><span class="identifier">second</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Put value for given key.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Key</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">key</span><span class="special">,</span> <span class="special">(</span><span class="identifier">Value</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">value</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="comment">// count increased</span>
+ <span class="identifier">has</span><span class="special">(</span><span class="identifier">key</span><span class="special">),</span> <span class="comment">// has key</span>
+ <span class="identifier">value_for</span><span class="special">(</span><span class="identifier">key</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">value</span> <span class="comment">// value for key set</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">items_</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">make_pair</span><span class="special">(</span><span class="identifier">key</span><span class="special">,</span> <span class="identifier">value</span><span class="special">));</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Remove value for given key.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">remove</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">Key</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">key</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">has</span><span class="special">(</span><span class="identifier">key</span><span class="special">)</span> <span class="special">)</span> <span class="comment">// has key</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span> <span class="comment">// count decreased</span>
+ <span class="identifier">has</span><span class="special">(</span><span class="identifier">key</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">false</span> <span class="comment">// does not have key</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">items_</span><span class="special">.</span><span class="identifier">erase</span><span class="special">(</span><span class="identifier">key</span><span class="special">);</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">Key</span><span class="special">,</span> <span class="identifier">Value</span><span class="special">&gt;</span> <span class="identifier">items_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__mitchell02___courier__subcontracting_and_static_class_invariants"></a><a class="link" href="examples.html#contract__.examples.__mitchell02___courier__subcontracting_and_static_class_invariants" title="[Mitchell02] Courier: Subcontracting and static class invariants">[Mitchell02]
+ Courier: Subcontracting and static class invariants</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: courier.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
+
+<span class="keyword">struct</span> <span class="identifier">package</span> <span class="special">{</span> <span class="comment">// Basic package information.</span>
+ <span class="keyword">double</span> <span class="identifier">weight_kg</span><span class="special">;</span> <span class="comment">// Weight in kilograms.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">location</span><span class="special">;</span> <span class="comment">// Current location.</span>
+ <span class="keyword">double</span> <span class="identifier">accepted_hour</span><span class="special">;</span> <span class="comment">// Hour when it was accepted for delivery.</span>
+ <span class="keyword">double</span> <span class="identifier">delivered_hour</span><span class="special">;</span> <span class="comment">// Hour when it was delivered.</span>
+
+ <span class="identifier">package</span><span class="special">(</span><span class="keyword">double</span> <span class="keyword">const</span> <span class="identifier">a_weight_kg</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="identifier">a_location</span> <span class="special">=</span> <span class="string">""</span><span class="special">,</span>
+ <span class="keyword">double</span> <span class="keyword">const</span> <span class="identifier">an_accepted_hour</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">,</span>
+ <span class="keyword">double</span> <span class="keyword">const</span> <span class="identifier">a_delivered_hour</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">weight_kg</span><span class="special">(</span><span class="identifier">a_weight_kg</span><span class="special">)</span>
+ <span class="special">,</span> <span class="identifier">location</span><span class="special">(</span><span class="identifier">a_location</span><span class="special">)</span>
+ <span class="special">,</span> <span class="identifier">accepted_hour</span><span class="special">(</span><span class="identifier">an_accepted_hour</span><span class="special">)</span>
+ <span class="special">,</span> <span class="identifier">delivered_hour</span><span class="special">(</span><span class="identifier">a_delivered_hour</span><span class="special">)</span>
+ <span class="special">{}</span>
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Basic courier for package delivery.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">courier</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span>
+ <span class="identifier">insurance_cover_dollar</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">min_insurance_dollar</span><span class="special">,</span> <span class="comment">// above min insurance</span>
+ <span class="keyword">static</span> <span class="keyword">class</span><span class="special">(</span> <span class="comment">// Static class invariants.</span>
+ <span class="identifier">min_insurance_dollar</span> <span class="special">&gt;</span> <span class="number">0.0</span> <span class="comment">// positive min insurance</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">static</span> <span class="keyword">double</span> <span class="identifier">min_insurance_dollar</span><span class="special">;</span>
+
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create courier with specified insurance value.</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">courier</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">double</span> <span class="keyword">const</span> <span class="identifier">an_insurance_cover_dollar</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">min_insurance_dollar</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">an_insurance_cover_dollar</span> <span class="special">&gt;</span> <span class="number">0.0</span> <span class="special">)</span> <span class="comment">// positive insurance</span>
+ <span class="special">)</span> <span class="special">;</span> <span class="comment">// Deferred body definition.</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy courier.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">courier</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Return insurance cover.</span>
+ <span class="keyword">public</span> <span class="keyword">double</span> <span class="special">(</span><span class="identifier">insurance_cover_dollar</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Deliver package to destination.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">deliver</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">package</span><span class="special">&amp;)</span> <span class="identifier">the_package</span><span class="special">,</span>
+ <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">)</span> <span class="identifier">destination</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">weight_kg</span> <span class="special">&lt;</span> <span class="number">5.0</span> <span class="comment">// within max wight</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="special">(</span><span class="identifier">the_package</span><span class="special">.</span><span class="identifier">delivered_hour</span> <span class="special">-</span> <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">accepted_hour</span><span class="special">)</span> <span class="special">&lt;=</span>
+ <span class="number">3.0</span><span class="special">,</span> <span class="comment">// within max delivery time</span>
+ <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">location</span> <span class="special">==</span> <span class="identifier">destination</span> <span class="comment">// delivered at destination</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">double</span> <span class="identifier">insurance_cover_dollar_</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Different courier for package delivery.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">different_courier</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="keyword">public</span> <span class="identifier">courier</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span>
+ <span class="identifier">insurance_cover_dollar</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">different_insurance_dollar</span><span class="special">,</span>
+ <span class="keyword">static</span> <span class="keyword">class</span><span class="special">(</span>
+ <span class="identifier">different_insurance_dollar</span> <span class="special">&gt;=</span> <span class="identifier">courier</span><span class="special">::</span><span class="identifier">min_insurance_dollar</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">static</span> <span class="keyword">double</span> <span class="identifier">different_insurance_dollar</span><span class="special">;</span>
+
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create currier with specified insurance value.</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">different_courier</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">double</span> <span class="keyword">const</span> <span class="identifier">insurance_cover_dollar</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">different_insurance_dollar</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">courier</span><span class="special">(</span><span class="identifier">insurance_cover_dollar</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">insurance_cover_dollar</span> <span class="special">&gt;</span> <span class="number">0.0</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span> <span class="comment">// Cannot separated body definition because has member initializers.</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy courier.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">different_courier</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">deliver</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">package</span><span class="special">&amp;)</span> <span class="identifier">the_package</span><span class="special">,</span>
+ <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">)</span> <span class="identifier">destination</span> <span class="special">)</span> <span class="identifier">override</span> <span class="identifier">final</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="comment">// Weaker precondition on weight (i.e., it can weight more).</span>
+ <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">weight_kg</span> <span class="special">&lt;=</span> <span class="number">8.0</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="comment">// Stronger postcondition on delivery time (i.e., faster delivery).</span>
+ <span class="special">(</span><span class="identifier">the_package</span><span class="special">.</span><span class="identifier">delivered_hour</span> <span class="special">-</span> <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">accepted_hour</span><span class="special">)</span> <span class="special">&lt;=</span> <span class="number">2.0</span>
+ <span class="comment">// Inherits "delivered at destination" postcondition.</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"courier.hpp"</span>
+
+<span class="comment">// Courier.</span>
+
+<span class="keyword">double</span> <span class="identifier">courier</span><span class="special">::</span><span class="identifier">min_insurance_dollar</span> <span class="special">=</span> <span class="number">10.0e+6</span><span class="special">;</span>
+
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">courier</span><span class="special">,</span> <span class="identifier">courier</span><span class="special">)</span> <span class="special">(</span>
+ <span class="keyword">double</span> <span class="keyword">const</span> <span class="identifier">an_insurance_cover_dollar</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">insurance_cover_dollar_</span> <span class="special">=</span> <span class="identifier">an_insurance_cover_dollar</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="identifier">CONTRACT_DESTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">courier</span><span class="special">,</span> <span class="special">~</span><span class="identifier">courier</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{}</span>
+
+<span class="keyword">double</span> <span class="identifier">courier</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">insurance_cover_dollar</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">insurance_cover_dollar_</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">courier</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">deliver</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">package</span><span class="special">&amp;</span> <span class="identifier">the_package</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="identifier">destination</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">location</span> <span class="special">=</span> <span class="identifier">destination</span><span class="special">;</span>
+ <span class="comment">// Delivery takes 2.5 hours.</span>
+ <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">delivered_hour</span> <span class="special">=</span> <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">accepted_hour</span> <span class="special">+</span> <span class="number">2.5</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="comment">// Different courier.</span>
+
+<span class="keyword">double</span> <span class="identifier">different_courier</span><span class="special">::</span><span class="identifier">different_insurance_dollar</span> <span class="special">=</span> <span class="number">20.0e+6</span><span class="special">;</span>
+
+<span class="identifier">CONTRACT_DESTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">different_courier</span><span class="special">,</span> <span class="special">~</span><span class="identifier">different_courier</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{}</span>
+
+<span class="keyword">void</span> <span class="identifier">different_courier</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">deliver</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">package</span><span class="special">&amp;</span> <span class="identifier">the_package</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="identifier">destination</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">location</span> <span class="special">=</span> <span class="identifier">destination</span><span class="special">;</span>
+ <span class="comment">// Delivery takes only 0.5 hours.</span>
+ <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">delivered_hour</span> <span class="special">=</span> <span class="identifier">the_package</span><span class="special">.</span><span class="identifier">accepted_hour</span> <span class="special">+</span> <span class="number">0.5</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__mitchell02___stack__simple_stack_dispenser"></a><a class="link" href="examples.html#contract__.examples.__mitchell02___stack__simple_stack_dispenser" title="[Mitchell02] Stack: Simple stack dispenser">[Mitchell02]
+ Stack: Simple stack dispenser</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Simple stack.</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">stack</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// non-negative count</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Create empty stack.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">stack</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// empty</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Destroy stack.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">stack</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// Basic queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Number of items.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Item at index in [1, count()] (as in Eiffel).</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">item_at</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">index</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">index</span> <span class="special">&gt;</span> <span class="number">0</span><span class="special">,</span> <span class="comment">// positive index</span>
+ <span class="identifier">index</span> <span class="special">&lt;=</span> <span class="identifier">count</span><span class="special">()</span> <span class="comment">// index within count</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">index</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Derived queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// If no items.</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">is_empty</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="comment">// consistent with count</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Top item.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">item</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// not empty</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">item_at</span><span class="special">(</span><span class="identifier">count</span><span class="special">())</span> <span class="comment">// item on top</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">item_at</span><span class="special">(</span><span class="identifier">count</span><span class="special">());</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Push item to the top.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">new_item</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="comment">// count increased</span>
+ <span class="identifier">item</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">new_item</span> <span class="comment">// item set</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">items_</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">new_item</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Pop top item.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">remove</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// not empty</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">-</span> <span class="number">1</span> <span class="comment">// count decreased</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">items_</span><span class="special">.</span><span class="identifier">resize</span><span class="special">(</span><span class="identifier">items_</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">items_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__mitchell02___simple_queue__simple_queue_dispenser"></a><a class="link" href="examples.html#contract__.examples.__mitchell02___simple_queue__simple_queue_dispenser" title="[Mitchell02] Simple Queue: Simple queue dispenser">[Mitchell02]
+ Simple Queue: Simple queue dispenser</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
+
+<span class="comment">// Importance ordering used to model assertion computational complexity.</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_1</span> <span class="number">0</span> <span class="comment">// O(1) constant (default)</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_N</span> <span class="number">1</span> <span class="comment">// O(n) linear</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">simple_queue</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// non-negative count</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Create empty queue.</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">simple_queue</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">the_capacity</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">the_capacity</span> <span class="special">&gt;</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// positive capacity</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">the_capacity</span><span class="special">,</span> <span class="comment">// capacity set</span>
+ <span class="identifier">is_empty</span><span class="special">()</span> <span class="comment">// empty</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">items_</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span><span class="identifier">the_capacity</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// Destroy queue.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">simple_queue</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// Basic queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Items in the queue (in their order).</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">items</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Max number of items queue can hold.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">capacity</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">capacity</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Derived queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Number of items.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="keyword">int</span><span class="special">(</span><span class="identifier">items</span><span class="special">().</span><span class="identifier">size</span><span class="special">())</span> <span class="comment">// return items count</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Item at head.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">head</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">is_empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">items</span><span class="special">().</span><span class="identifier">at</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="comment">// return item on top</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="number">0</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// If queue contains no item.</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">is_empty</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="comment">// consistent with count</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// If queue has no room for another item.</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">is_full</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span>
+ <span class="keyword">int</span><span class="special">(</span><span class="identifier">items</span><span class="special">().</span><span class="identifier">size</span><span class="special">()))</span> <span class="comment">// consistent with size and capacity</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">items_</span><span class="special">.</span><span class="identifier">capacity</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Remove head item and shift all other items.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">remove</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">is_empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_items</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">items</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span> <span class="comment">// count decreased</span>
+ <span class="comment">// Expensive assertion to check so marked using importance.</span>
+ <span class="identifier">all_equal</span><span class="special">(</span><span class="identifier">items</span><span class="special">(),</span> <span class="identifier">old_items</span><span class="special">,</span> <span class="number">1</span> <span class="comment">/* shifted */</span><span class="special">),</span> <span class="identifier">importance</span> <span class="identifier">O_N</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">items_</span><span class="special">.</span><span class="identifier">erase</span><span class="special">(</span><span class="identifier">items_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">());</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Add item to tail.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">put</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">item</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">&lt;</span> <span class="identifier">capacity</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="keyword">auto</span> <span class="identifier">old_items</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">items</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="comment">// count increased</span>
+ <span class="identifier">items</span><span class="special">().</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">item</span><span class="special">,</span> <span class="comment">// second last item</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">2</span><span class="special">)</span> <span class="special">(</span>
+ <span class="comment">// Expensive assertion to check so marked using importance.</span>
+ <span class="identifier">all_equal</span><span class="special">(</span><span class="identifier">items</span><span class="special">(),</span> <span class="identifier">old_items</span><span class="special">),</span> <span class="identifier">importance</span> <span class="identifier">O_N</span>
+ <span class="special">)</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">items_</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">item</span><span class="special">);</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+
+ <span class="comment">/** @todo make this static */</span>
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Postcondition helper.</span>
+ <span class="keyword">private</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">all_equal</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">left</span><span class="special">,</span>
+ <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">right</span><span class="special">,</span> <span class="identifier">size_t</span> <span class="identifier">offset</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">0</span>
+ <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">left</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">offset</span> <span class="special">)</span> <span class="comment">// correct offset</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="identifier">size_t</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">offset</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">i</span> <span class="special">-</span> <span class="identifier">offset</span><span class="special">)</span> <span class="special">!=</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">i</span><span class="special">))</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">items_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__mitchell02___customer_manager__contracts_instead_of_defensive_programming"></a><a class="link" href="examples.html#contract__.examples.__mitchell02___customer_manager__contracts_instead_of_defensive_programming" title="[Mitchell02] Customer Manager: Contracts instead of Defensive Programming">[Mitchell02]
+ Customer Manager: Contracts instead of Defensive Programming</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: customer_manager.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">map</span><span class="special">&gt;</span>
+
+<span class="keyword">class</span> <span class="identifier">basic_customer_details</span> <span class="special">{</span> <span class="comment">// Basic customer information.</span>
+ <span class="keyword">friend</span> <span class="keyword">class</span> <span class="identifier">customer_manager</span><span class="special">;</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">identifier</span><span class="special">;</span>
+
+ <span class="keyword">explicit</span> <span class="identifier">basic_customer_details</span><span class="special">(</span><span class="identifier">identifier</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">an_id</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">id</span><span class="special">(</span><span class="identifier">an_id</span><span class="special">),</span> <span class="identifier">name</span><span class="special">(),</span> <span class="identifier">address</span><span class="special">(),</span> <span class="identifier">birthday</span><span class="special">()</span>
+ <span class="special">{}</span>
+
+<span class="keyword">protected</span><span class="special">:</span>
+ <span class="identifier">identifier</span> <span class="identifier">id</span><span class="special">;</span> <span class="comment">// Customer identifier.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">name</span><span class="special">;</span> <span class="comment">// Customer name.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">address</span><span class="special">;</span> <span class="comment">// Customer address.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">birthday</span><span class="special">;</span> <span class="comment">// Customer date of birth.</span>
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Manage customers.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">customer_manager</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="identifier">count</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span> <span class="comment">// non-negative count</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">customer_manager</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="comment">// Cannot use member initializes because deferring body definition.</span>
+ <span class="special">)</span> <span class="special">;</span> <span class="comment">// Deferred body definition.</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">customer_manager</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Basic queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="comment">// Postcondition: non-negative count asserted by class invariants</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// There is a customer with given identifier.</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">id_active</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">basic_customer_details</span><span class="special">::</span><span class="identifier">identifier</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">id</span> <span class="special">)</span>
+ <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Derived queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Name of customer with given identifier.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">name_for</span><span class="special">)</span> <span class="special">(</span>
+ <span class="special">(</span><span class="identifier">basic_customer_details</span><span class="special">::</span><span class="identifier">identifier</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">id</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">id_active</span><span class="special">(</span><span class="identifier">id</span><span class="special">)</span> <span class="special">)</span> <span class="comment">// id active</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Add given customer.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">add</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">basic_customer_details</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">details</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">id_active</span><span class="special">(</span><span class="identifier">details</span><span class="special">.</span><span class="identifier">id</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span> <span class="comment">// id not active</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_count</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">count</span><span class="special">(),</span>
+ <span class="identifier">count</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_count</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="comment">// count increased</span>
+ <span class="identifier">id_active</span><span class="special">(</span><span class="identifier">details</span><span class="special">.</span><span class="identifier">id</span><span class="special">)</span> <span class="comment">// id active</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Set name of customer with given identifier.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">set_name</span><span class="special">)</span> <span class="special">(</span>
+ <span class="special">(</span><span class="identifier">basic_customer_details</span><span class="special">::</span><span class="identifier">identifier</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">id</span><span class="special">,</span>
+ <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">name</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">id_active</span><span class="special">(</span><span class="identifier">id</span><span class="special">)</span> <span class="special">)</span> <span class="comment">// id active</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">name_for</span><span class="special">(</span><span class="identifier">id</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">name</span> <span class="special">)</span> <span class="comment">// name set</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">class</span> <span class="identifier">agent</span> <span class="special">{};</span> <span class="comment">// Customer agent.</span>
+
+ <span class="keyword">struct</span> <span class="identifier">customer</span> <span class="special">:</span> <span class="identifier">basic_customer_details</span> <span class="special">{</span> <span class="comment">// Basic customer.</span>
+ <span class="identifier">agent</span> <span class="identifier">managing_agent</span><span class="special">;</span> <span class="comment">// Customer agent.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">last_contact</span><span class="special">;</span> <span class="comment">// Customer last contacted.</span>
+
+ <span class="keyword">explicit</span> <span class="identifier">customer</span><span class="special">(</span><span class="identifier">basic_customer_details</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">details</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">basic_customer_details</span><span class="special">(</span><span class="identifier">details</span><span class="special">),</span> <span class="identifier">managing_agent</span><span class="special">()</span>
+ <span class="special">,</span> <span class="identifier">last_contact</span><span class="special">()</span>
+ <span class="special">{}</span>
+ <span class="special">};</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">basic_customer_details</span><span class="special">::</span><span class="identifier">identifier</span><span class="special">,</span> <span class="identifier">customer</span><span class="special">&gt;</span> <span class="identifier">customers_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"customer_manager.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">utility</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">customer_manager</span><span class="special">,</span> <span class="identifier">customer_manager</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{}</span>
+
+<span class="identifier">CONTRACT_DESTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">customer_manager</span><span class="special">,</span> <span class="special">~</span><span class="identifier">customer_manager</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="special">{}</span>
+
+<span class="keyword">int</span> <span class="identifier">customer_manager</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">customers_</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span> <span class="special">}</span>
+
+<span class="keyword">bool</span> <span class="identifier">customer_manager</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">id_active</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">basic_customer_details</span><span class="special">::</span><span class="identifier">identifier</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">id</span><span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">customers_</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">id</span><span class="special">)</span> <span class="special">!=</span> <span class="identifier">customers_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
+<span class="special">}</span>
+
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">customer_manager</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">name_for</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">basic_customer_details</span><span class="special">::</span><span class="identifier">identifier</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">id</span><span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="comment">// Find != end because of `id_active()` pre so no defensive programming.</span>
+ <span class="keyword">return</span> <span class="identifier">customers_</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">id</span><span class="special">)-&gt;</span><span class="identifier">second</span><span class="special">.</span><span class="identifier">name</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">customer_manager</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">basic_customer_details</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">details</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">customers_</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">make_pair</span><span class="special">(</span><span class="identifier">details</span><span class="special">.</span><span class="identifier">id</span><span class="special">,</span> <span class="identifier">customer</span><span class="special">(</span><span class="identifier">details</span><span class="special">)));</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">customer_manager</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">set_name</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">basic_customer_details</span><span class="special">::</span><span class="identifier">identifier</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">id</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">name</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Find != end because of `id_active()` pre so no defensive programming.</span>
+ <span class="identifier">customers_</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">id</span><span class="special">)-&gt;</span><span class="identifier">second</span><span class="special">.</span><span class="identifier">name</span> <span class="special">=</span> <span class="identifier">name</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__mitchell02___observer__contracts_for_pure_virtual_functions"></a><a class="link" href="examples.html#contract__.examples.__mitchell02___observer__contracts_for_pure_virtual_functions" title="[Mitchell02] Observer: Contracts for pure virtual functions">[Mitchell02]
+ Observer: Contracts for pure virtual functions</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: observer.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Observer.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">observer</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// no invariant</span>
+
+ <span class="keyword">friend</span> <span class="keyword">class</span> <span class="identifier">subject</span><span class="special">;</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create observer.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">observer</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy observer.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">observer</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+<span class="keyword">protected</span><span class="special">:</span>
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// If up to date with its subject.</span>
+ <span class="keyword">protected</span> <span class="keyword">virtual</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">up_to_date_with_subject</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="keyword">new</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Update and inform its subject.</span>
+ <span class="keyword">protected</span> <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">update</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">new</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">up_to_date_with_subject</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// up-to-date</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: subject.hpp</span>
+<span class="preprocessor">#include</span> <span class="string">"observer.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">list</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">algorithm</span><span class="special">&gt;</span>
+
+<span class="comment">// Importance ordering used to model assertion computational complexity.</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_1</span> <span class="number">0</span> <span class="comment">// O(1) constant (default)</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_N</span> <span class="number">1</span> <span class="comment">// O(n) linear</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Subject for observer design pattern.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">subject</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span>
+ <span class="identifier">all_observers_valid</span><span class="special">(</span><span class="identifier">observers</span><span class="special">()),</span> <span class="identifier">importance</span> <span class="identifier">O_N</span> <span class="comment">// observes valid</span>
+ <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Construct subject with no observer.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">subject</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy subject.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">subject</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// Queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// If given observer is attached.</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">attached</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*</span> <span class="keyword">const</span><span class="special">)</span> <span class="identifier">obs</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">obs</span> <span class="special">)</span> <span class="comment">// not null</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">observers_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">observers_</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">obs</span><span class="special">)</span> <span class="special">!=</span>
+ <span class="identifier">observers_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Remember given object as an observer.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">attach</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">observer</span><span class="special">*</span> <span class="keyword">const</span><span class="special">)</span> <span class="identifier">obs</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">obs</span><span class="special">,</span> <span class="comment">// not null</span>
+ <span class="identifier">attached</span><span class="special">(</span><span class="identifier">obs</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">false</span> <span class="comment">// not already attached</span>
+ <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_observers</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">observers</span><span class="special">(),</span>
+ <span class="identifier">attached</span><span class="special">(</span><span class="identifier">obs</span><span class="special">),</span> <span class="comment">// attached</span>
+ <span class="identifier">other_observers_unchanged</span><span class="special">(</span><span class="identifier">old_observers</span><span class="special">,</span> <span class="identifier">observers</span><span class="special">(),</span> <span class="identifier">obs</span><span class="special">),</span>
+ <span class="identifier">importance</span> <span class="identifier">O_N</span> <span class="comment">// others not changed (frame rule)</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">observers_</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">obs</span><span class="special">);</span>
+ <span class="special">}</span>
+
+<span class="keyword">protected</span><span class="special">:</span>
+ <span class="comment">// Queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// All observers attached to this subject.</span>
+ <span class="keyword">protected</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;)</span> <span class="special">(</span><span class="identifier">observers</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Create list of pointers to const observers.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">observer</span><span class="special">*&gt;</span> <span class="identifier">obs</span><span class="special">;</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span><span class="special">*&gt;::</span><span class="identifier">const_iterator</span>
+ <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">observers_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span> <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">observers_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">obs</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(*</span><span class="identifier">i</span><span class="special">);</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">obs</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Update all attached observers.</span>
+ <span class="keyword">protected</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">notify</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">all_observers_updated</span><span class="special">(</span><span class="identifier">observers</span><span class="special">())</span> <span class="special">)</span> <span class="comment">// all updated</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span><span class="special">*&gt;::</span><span class="identifier">iterator</span>
+ <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">observers_</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span> <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">observers_</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Class invariant ensures no null pointers in observers but</span>
+ <span class="comment">// class invariants not checked for non-public members so check.</span>
+ <span class="identifier">CONTRACT_BLOCK_INVARIANT</span><span class="special">(</span> <span class="number">0</span> <span class="special">!=</span> <span class="special">*</span><span class="identifier">i</span> <span class="special">)</span> <span class="comment">// pointer not null</span>
+ <span class="special">(*</span><span class="identifier">i</span><span class="special">)-&gt;</span><span class="identifier">update</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="comment">// Contract helpers.</span>
+
+ <span class="comment">/** @todo make these static */</span>
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">all_observers_valid</span><span class="special">)</span> <span class="special">(</span>
+ <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">observers</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;::</span><span class="identifier">const_iterator</span>
+ <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">observers</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span> <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">observers</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(!(*</span><span class="identifier">i</span><span class="special">))</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">other_observers_unchanged</span><span class="special">)</span> <span class="special">(</span>
+ <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">old</span><span class="special">,</span>
+ <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">now</span><span class="special">,</span>
+ <span class="special">(</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*)</span> <span class="identifier">obs</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">obs</span> <span class="special">)</span> <span class="comment">// not null</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;</span> <span class="identifier">remaining</span> <span class="special">=</span> <span class="identifier">now</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">remove</span><span class="special">(</span><span class="identifier">remaining</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">remaining</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">obs</span><span class="special">);</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;::</span><span class="identifier">const_iterator</span>
+ <span class="identifier">remaining_it</span> <span class="special">=</span> <span class="identifier">remaining</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;::</span><span class="identifier">const_iterator</span> <span class="identifier">old_it</span> <span class="special">=</span> <span class="identifier">old</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
+ <span class="keyword">while</span><span class="special">(</span><span class="identifier">remaining</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">!=</span> <span class="identifier">remaining_it</span> <span class="special">&amp;&amp;</span> <span class="identifier">old</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">!=</span> <span class="identifier">old_it</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(*</span><span class="identifier">remaining_it</span> <span class="special">!=</span> <span class="special">*</span><span class="identifier">old_it</span><span class="special">)</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">remaining_it</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">old_it</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">all_observers_updated</span><span class="special">)</span> <span class="special">(</span>
+ <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">observers</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span> <span class="keyword">const</span><span class="special">*&gt;::</span><span class="identifier">const_iterator</span>
+ <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">observers</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span> <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">observers</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(!(*</span><span class="identifier">i</span><span class="special">))</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">if</span><span class="special">(!(*</span><span class="identifier">i</span><span class="special">)-&gt;</span><span class="identifier">up_to_date_with_subject</span><span class="special">())</span> <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">observer</span><span class="special">*&gt;</span> <span class="identifier">observers_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"observer/observer.hpp"</span>
+<span class="preprocessor">#include</span> <span class="string">"observer/subject.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
+
+<span class="keyword">class</span> <span class="identifier">concrete_subject</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">subject</span> <span class="special">{</span> <span class="comment">// Implement an actual subject.</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">state</span><span class="special">;</span> <span class="comment">// Some state being observed.</span>
+
+ <span class="identifier">concrete_subject</span><span class="special">():</span> <span class="identifier">state_</span><span class="special">()</span> <span class="special">{}</span>
+
+ <span class="keyword">void</span> <span class="identifier">set_state</span> <span class="special">(</span><span class="identifier">state</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">the_state</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Set state being observed.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Changing state to "</span> <span class="special">&lt;&lt;</span> <span class="identifier">the_state</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">state_</span> <span class="special">=</span> <span class="identifier">the_state</span><span class="special">;</span>
+ <span class="identifier">notify</span><span class="special">();</span> <span class="comment">// Notify observers.</span>
+ <span class="special">}</span>
+
+ <span class="identifier">state</span> <span class="identifier">get_state</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">state_</span><span class="special">;</span> <span class="special">}</span> <span class="comment">// Get state being observed.</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">state</span> <span class="identifier">state_</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Implement of actual observer.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">concrete_observer</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="keyword">public</span> <span class="identifier">observer</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create concrete observer.</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">concrete_observer</span><span class="special">)</span> <span class="special">(</span>
+ <span class="special">(</span><span class="identifier">concrete_subject</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="identifier">the_subject</span><span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">subject_</span><span class="special">(</span><span class="identifier">the_subject</span><span class="special">),</span> <span class="identifier">observed_state_</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+<span class="keyword">private</span><span class="special">:</span> <span class="comment">// Implement base virtual functions.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">up_to_date_with_subject</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="identifier">override</span> <span class="identifier">final</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span> <span class="comment">// For simplicity, always up-to-date.</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">update</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="identifier">override</span> <span class="identifier">final</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">observed_state_</span> <span class="special">=</span> <span class="identifier">subject_</span><span class="special">.</span><span class="identifier">get_state</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Observed state "</span> <span class="special">&lt;&lt;</span> <span class="identifier">observed_state_</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">concrete_subject</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">subject_</span><span class="special">;</span>
+ <span class="identifier">concrete_subject</span><span class="special">::</span><span class="identifier">state</span> <span class="identifier">observed_state_</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"Constructing objects"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">concrete_subject</span> <span class="identifier">sbj</span><span class="special">;</span>
+ <span class="identifier">concrete_observer</span> <span class="identifier">ob</span><span class="special">(</span><span class="identifier">sbj</span><span class="special">);</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"Attaching observer "</span> <span class="special">&lt;&lt;</span> <span class="special">&amp;</span><span class="identifier">ob</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">sbj</span><span class="special">.</span><span class="identifier">attach</span><span class="special">(&amp;</span><span class="identifier">ob</span><span class="special">);</span>
+
+ <span class="identifier">concrete_subject</span><span class="special">::</span><span class="identifier">state</span> <span class="identifier">st</span> <span class="special">=</span> <span class="special">-</span><span class="number">10</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"Setting state to "</span> <span class="special">&lt;&lt;</span> <span class="identifier">st</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">sbj</span><span class="special">.</span><span class="identifier">set_state</span><span class="special">(</span><span class="identifier">st</span><span class="special">);</span>
+
+ <span class="identifier">st</span> <span class="special">=</span> <span class="special">+</span><span class="number">10</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"Re-setting state to "</span> <span class="special">&lt;&lt;</span> <span class="identifier">st</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">sbj</span><span class="special">.</span><span class="identifier">set_state</span><span class="special">(</span><span class="identifier">st</span><span class="special">);</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"Destructing objects"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.mitchell02_counter"></a><a class="link" href="examples.html#contract__.examples.mitchell02_counter" title="[Mitchell02] Counter: Subcontracting and virtual specifiers (final, override, new, and pure)">[Mitchell02]
+ Counter: Subcontracting and virtual specifiers (final, override, new, and pure)</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: push_button.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Basic button.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">push_button</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// no invariant</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create an enabled button.</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">push_button</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">enabled_</span><span class="special">(</span><span class="keyword">true</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">enabled</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// enabled</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy button.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">push_button</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// Queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// If button enabled.</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">enabled</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">enabled_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Enable this button.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">enable</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">enabled</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// enabled</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">enabled_</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Disable this button.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">disable</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">enabled</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span> <span class="comment">// disabled</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">enabled_</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Invoked externally when this button is clicked.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">on_bn_clicked</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">new</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">enabled</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// enabled</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="comment">// Contract for pure virtual function.</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">bool</span> <span class="identifier">enabled_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: decrement_button.hpp</span>
+<span class="preprocessor">#include</span> <span class="string">"push_button.hpp"</span>
+<span class="preprocessor">#include</span> <span class="string">"counter.hpp"</span>
+<span class="preprocessor">#include</span> <span class="string">"../observer/observer.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Button that decrements counter.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">decrement_button</span><span class="special">)</span> <span class="identifier">final</span> <span class="comment">// Contract for final class.</span>
+ <span class="identifier">extends</span><span class="special">(</span> <span class="keyword">public</span> <span class="identifier">push_button</span><span class="special">,</span> <span class="keyword">protected</span> <span class="identifier">observer</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// no invariant</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create button associated with given counter.</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">decrement_button</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">counter</span><span class="special">&amp;)</span> <span class="identifier">the_counter</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">counter_ref_</span><span class="special">(</span><span class="identifier">the_counter</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">enabled</span><span class="special">()</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">the_counter</span><span class="special">.</span><span class="identifier">value</span><span class="special">()</span> <span class="special">&gt;</span> <span class="number">0</span><span class="special">)</span> <span class="comment">// enabled iff positive value</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">attach</span><span class="special">(</span><span class="keyword">this</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy button.</span>
+ <span class="keyword">public</span> <span class="special">(~</span><span class="identifier">decrement_button</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">on_bn_clicked</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="identifier">override</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">old_value</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">value</span><span class="special">(),</span>
+ <span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">value</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_value</span> <span class="special">-</span> <span class="number">1</span> <span class="comment">// counter decremented</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">decrement</span><span class="special">();</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">up_to_date_with_subject</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="identifier">override</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span> <span class="comment">// For simplicity, always up-to-date.</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">update</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="identifier">override</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">enabled</span><span class="special">()</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">value</span><span class="special">()</span> <span class="special">&gt;</span> <span class="number">0</span><span class="special">)</span> <span class="comment">// enabled if positive value</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">value</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="identifier">disable</span><span class="special">();</span>
+ <span class="keyword">else</span> <span class="identifier">enable</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">counter</span><span class="special">&amp;</span> <span class="identifier">counter_ref_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: counter.hpp</span>
+<span class="preprocessor">#include</span> <span class="string">"../observer/subject.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Positive integer counter.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">counter</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="keyword">public</span> <span class="identifier">subject</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// no invariants</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Construct counter with specified value.</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">counter</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a_value</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">10</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">value_</span><span class="special">(</span><span class="identifier">a_value</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">value</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">a_value</span> <span class="special">)</span> <span class="comment">// value set</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy counter.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">counter</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// Queries.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Current counter value.</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">value</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">value_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="comment">// Commands.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Decrement counter value.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">decrement</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">old_value</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">value</span><span class="special">(),</span>
+ <span class="identifier">value</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">old_value</span> <span class="special">-</span> <span class="number">1</span> <span class="comment">// decremented</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="special">--</span><span class="identifier">value_</span><span class="special">;</span>
+ <span class="identifier">notify</span><span class="special">();</span> <span class="comment">// Notifies all attached observers.</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">value_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: view_of_counter.hpp</span>
+<span class="preprocessor">#include</span> <span class="string">"counter.hpp"</span>
+<span class="preprocessor">#include</span> <span class="string">"../observer/observer.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Show current value of associated counter.</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">view_of_counter</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="keyword">private</span> <span class="identifier">observer</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// no invariant</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Creation.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span> <span class="comment">// Create viewer associated with given counter.</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">view_of_counter</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">counter</span><span class="special">&amp;)</span> <span class="identifier">the_counter</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">counter_ref_</span><span class="special">(</span><span class="identifier">the_counter</span><span class="special">)</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">attach</span><span class="special">(</span><span class="keyword">this</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"&gt; Counter started at "</span> <span class="special">&lt;&lt;</span>
+ <span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">value</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span> <span class="comment">// Destroy viewer.</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">view_of_counter</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">up_to_date_with_subject</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="identifier">override</span> <span class="identifier">final</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span> <span class="comment">// For simplicity, always up-to-date.</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">update</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="identifier">override</span> <span class="identifier">final</span> <span class="comment">// Contract final function.</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"&gt; Counter changed to "</span> <span class="special">&lt;&lt;</span>
+ <span class="identifier">counter_ref_</span><span class="special">.</span><span class="identifier">value</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">counter</span><span class="special">&amp;</span> <span class="identifier">counter_ref_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"counter/counter.hpp"</span>
+<span class="preprocessor">#include</span> <span class="string">"counter/decrement_button.hpp"</span>
+<span class="preprocessor">#include</span> <span class="string">"counter/view_of_counter.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">counter</span> <span class="identifier">cnt</span><span class="special">(</span><span class="number">3</span><span class="special">);</span>
+ <span class="identifier">view_of_counter</span> <span class="identifier">view</span><span class="special">(</span><span class="identifier">cnt</span><span class="special">);</span>
+ <span class="identifier">decrement_button</span> <span class="identifier">dec</span><span class="special">(</span><span class="identifier">cnt</span><span class="special">);</span>
+
+ <span class="keyword">char</span> <span class="identifier">ch</span> <span class="special">=</span> <span class="char">'\0'</span><span class="special">;</span>
+ <span class="keyword">while</span><span class="special">(</span><span class="identifier">ch</span> <span class="special">!=</span> <span class="char">'q'</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Simple text-based menu selection.</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">dec</span><span class="special">.</span><span class="identifier">enabled</span><span class="special">())</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"(-) Decrement counter"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"(q) Quit"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Select: "</span><span class="special">;</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cin</span> <span class="special">&gt;&gt;</span> <span class="identifier">ch</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="char">'q'</span> <span class="special">==</span> <span class="identifier">ch</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="keyword">if</span> <span class="special">(</span><span class="char">'-'</span> <span class="special">==</span> <span class="identifier">ch</span> <span class="special">&amp;&amp;</span> <span class="identifier">dec</span><span class="special">.</span><span class="identifier">enabled</span><span class="special">())</span> <span class="special">{</span>
+ <span class="identifier">dec</span><span class="special">.</span><span class="identifier">on_bn_clicked</span><span class="special">();</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Invalid selection '"</span> <span class="special">&lt;&lt;</span> <span class="identifier">ch</span> <span class="special">&lt;&lt;</span> <span class="string">"'"</span>
+ <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__stroustrup97___string__throw_when_contract_is_broken"></a><a class="link" href="examples.html#contract__.examples.__stroustrup97___string__throw_when_contract_is_broken" title="[Stroustrup97] String: Throw when contract is broken">[Stroustrup97]
+ String: Throw when contract is broken</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="comment">// In header: string.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstring</span><span class="special">&gt;</span>
+
+<span class="comment">// Adapted from an example presented in [Stroustrup1997] to illustrate</span>
+<span class="comment">// importance of class invariants. Simple preconditions were added where it</span>
+<span class="comment">// made sense. This should be compiled with postconditions checking turned off</span>
+<span class="comment">// because postconditions are deliberately not used.</span>
+<span class="comment">// See [Stroustrup1997] for a discussion on the importance of class invariants,</span>
+<span class="comment">// and on pros and cons of using pre and post conditions.</span>
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">String</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span>
+ <span class="comment">// It would be better to assert conditions separately so to generate</span>
+ <span class="comment">// more informative error in case they fail.</span>
+ <span class="identifier">p</span> <span class="special">&amp;&amp;</span> <span class="identifier">sz</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">&amp;&amp;</span> <span class="identifier">TOO_LARGE</span> <span class="special">&gt;=</span> <span class="identifier">sz</span> <span class="special">&amp;&amp;</span> <span class="special">!</span><span class="identifier">p</span><span class="special">[</span><span class="identifier">sz</span><span class="special">]</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="keyword">throw</span> <span class="identifier">Invariant</span><span class="special">()</span>
+ <span class="special">)</span>
+
+ <span class="keyword">int</span> <span class="identifier">sz</span><span class="special">;</span>
+ <span class="keyword">char</span><span class="special">*</span> <span class="identifier">p</span><span class="special">;</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Broken contracts throw user defined exceptions.</span>
+ <span class="keyword">class</span> <span class="identifier">Range</span> <span class="special">{};</span> <span class="comment">// exception classes</span>
+ <span class="keyword">class</span> <span class="identifier">Invariant</span> <span class="special">{};</span>
+ <span class="keyword">class</span> <span class="identifier">Null</span> <span class="special">{};</span>
+ <span class="keyword">class</span> <span class="identifier">Too_large</span> <span class="special">{};</span>
+
+ <span class="keyword">enum</span> <span class="special">{</span> <span class="identifier">TOO_LARGE</span> <span class="special">=</span> <span class="number">16000</span> <span class="special">};</span> <span class="comment">// length limit</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">String</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*)</span> <span class="identifier">q</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">q</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="keyword">throw</span> <span class="identifier">Null</span><span class="special">(),</span>
+ <span class="identifier">strlen</span><span class="special">(</span><span class="identifier">q</span><span class="special">)</span> <span class="special">&lt;=</span> <span class="identifier">TOO_LARGE</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="keyword">throw</span> <span class="identifier">Too_large</span><span class="special">()</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span> <span class="comment">// Deferred body definition.</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">String</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">String</span><span class="special">&amp;)</span> <span class="identifier">s</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(~</span><span class="identifier">String</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="keyword">char</span><span class="special">&amp;)</span> <span class="keyword">operator</span><span class="special">([])(</span><span class="identifier">at</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">i</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">&amp;&amp;</span> <span class="identifier">sz</span> <span class="special">&gt;</span> <span class="identifier">i</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="keyword">throw</span> <span class="identifier">Range</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">size</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">;</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Not public so it does not check class invariants.</span>
+ <span class="keyword">private</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">init</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*)</span> <span class="identifier">q</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"string.hpp"</span>
+
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">String</span><span class="special">,</span> <span class="identifier">String</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">q</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">init</span><span class="special">(</span><span class="identifier">q</span><span class="special">);</span> <span class="special">}</span>
+
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">String</span><span class="special">,</span> <span class="identifier">String</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">String</span><span class="special">&amp;</span> <span class="identifier">s</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">init</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">p</span><span class="special">);</span> <span class="special">}</span>
+
+<span class="identifier">CONTRACT_DESTRUCTOR_BODY</span><span class="special">(</span><span class="identifier">String</span><span class="special">,</span> <span class="special">~</span><span class="identifier">String</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="keyword">delete</span><span class="special">[]</span> <span class="identifier">p</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="keyword">char</span><span class="special">&amp;</span> <span class="identifier">String</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="keyword">operator</span><span class="special">([])(</span><span class="identifier">at</span><span class="special">))</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">p</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span> <span class="special">}</span>
+
+<span class="keyword">int</span> <span class="identifier">String</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">size</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">sz</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">String</span><span class="special">::</span><span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="identifier">init</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">q</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">sz</span> <span class="special">=</span> <span class="identifier">strlen</span><span class="special">(</span><span class="identifier">q</span><span class="special">);</span>
+ <span class="identifier">p</span> <span class="special">=</span> <span class="keyword">new</span> <span class="keyword">char</span><span class="special">[</span><span class="identifier">sz</span> <span class="special">+</span> <span class="number">1</span><span class="special">];</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">sz</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="identifier">p</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">q</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span>
+ <span class="identifier">p</span><span class="special">[</span><span class="identifier">sz</span><span class="special">]</span> <span class="special">=</span> <span class="char">'\0'</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"string.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
+
+<span class="comment">// Handler that re-throws contract broken exceptions instead of terminating.</span>
+<span class="keyword">void</span> <span class="identifier">throwing_handler</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">contract</span><span class="special">::</span><span class="identifier">from</span><span class="special">&amp;</span> <span class="identifier">context</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">context</span> <span class="special">==</span> <span class="identifier">contract</span><span class="special">::</span><span class="identifier">FROM_DESTRUCTOR</span><span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Cannot throw from within destructor for STL exception safety.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">clog</span> <span class="special">&lt;&lt;</span> <span class="string">"Ignored destructor contract failure"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+ <span class="comment">// Failure handlers always called with active an exception.</span>
+ <span class="keyword">throw</span><span class="special">;</span> <span class="comment">// Re-throw active exception thrown by precondition.</span>
+ <span class="special">}</span>
+<span class="special">}</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Setup contract failure handlers that throw (instead of terminate).</span>
+ <span class="identifier">contract</span><span class="special">::</span><span class="identifier">set_precondition_broken</span><span class="special">(&amp;</span><span class="identifier">throwing_handler</span><span class="special">);</span>
+ <span class="identifier">contract</span><span class="special">::</span><span class="identifier">set_postcondition_broken</span><span class="special">(&amp;</span><span class="identifier">throwing_handler</span><span class="special">);</span>
+ <span class="identifier">contract</span><span class="special">::</span><span class="identifier">set_class_invariant_broken</span><span class="special">(&amp;</span><span class="identifier">throwing_handler</span><span class="special">);</span>
+ <span class="identifier">contract</span><span class="special">::</span><span class="identifier">set_block_invariant_broken</span><span class="special">(&amp;</span><span class="identifier">throwing_handler</span><span class="special">);</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"constructor()"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">String</span> <span class="identifier">s</span><span class="special">(</span><span class="string">"A"</span><span class="special">);</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"operator[0]"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">s</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"operator[1] (throws)"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">s</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span> <span class="special">&lt;&lt;</span> <span class="string">"destructor()"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.cline90_vector"></a><a class="link" href="examples.html#contract__.examples.cline90_vector" title="[Cline90] Vector: Comparison with A++ proposal syntax">[Cline90] Vector:
+ Comparison with A++ proposal syntax</a>
+</h3></div></div></div>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ ISO C++ (this library)
+ </p>
+ </th>
+<th>
+ <p>
+ A++ Proposals <a class="link" href="bibliography.html" title="Bibliography">[Cline90]</a>
+ </p>
+ </th>
+</tr></thead>
+<tbody><tr>
+<td>
+ <p>
+
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// In header: vector.hpp</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// NOTE: Incomplete set of assertions addressing only `size`.</span>
+
+ <span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">count</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">10</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">data_</span><span class="special">(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">[</span><span class="identifier">count</span><span class="special">]),</span> <span class="identifier">size_</span><span class="special">(</span><span class="identifier">count</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">size_</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="identifier">data_</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">T</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">vector</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">delete</span><span class="special">[]</span> <span class="identifier">data_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">size</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="comment">// Postcondition: Result non-negative checked by class invariant.</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">size_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">resize</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span>
+ <span class="comment">// A++ `init` is equivalent to this library OLDOF but not needed here.</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">T</span><span class="special">*</span> <span class="identifier">slice</span> <span class="special">=</span> <span class="keyword">new</span> <span class="identifier">T</span><span class="special">[</span><span class="identifier">count</span><span class="special">];</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">count</span> <span class="special">&amp;&amp;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">size_</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="identifier">slice</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">data_</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span>
+ <span class="keyword">delete</span><span class="special">[]</span> <span class="identifier">data_</span><span class="special">;</span>
+ <span class="identifier">data_</span> <span class="special">=</span> <span class="identifier">slice</span><span class="special">;</span>
+ <span class="identifier">size_</span> <span class="special">=</span> <span class="identifier">count</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">T</span><span class="special">&amp;)</span> <span class="keyword">operator</span><span class="special">([])(</span><span class="identifier">at</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">index</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span>
+ <span class="identifier">index</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">,</span>
+ <span class="identifier">index</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">()</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">data_</span><span class="special">[</span><span class="identifier">index</span><span class="special">];</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">T</span><span class="special">*</span> <span class="identifier">data_</span><span class="special">;</span>
+ <span class="keyword">int</span> <span class="identifier">size_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+ </td>
+<td>
+ <p>
+
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// Extra spacing and newlines used to visually align with this library code.</span>
+
+
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
+<span class="keyword">class</span> <span class="identifier">vector</span>
+<span class="special">{</span>
+<span class="identifier">legal</span><span class="special">:</span> <span class="comment">// Class invariants (legal).</span>
+ <span class="identifier">size</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">;</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">explicit</span> <span class="identifier">vector</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">count</span> <span class="special">=</span> <span class="number">10</span> <span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">data_</span><span class="special">(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">[</span><span class="identifier">count</span><span class="special">]),</span> <span class="identifier">size_</span><span class="special">(</span><span class="identifier">count</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">size_</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="identifier">data_</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">T</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">vector</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">delete</span><span class="special">[]</span> <span class="identifier">data_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="keyword">int</span> <span class="identifier">size</span> <span class="special">(</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">size_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="keyword">void</span> <span class="identifier">resize</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="special">{</span>
+ <span class="identifier">T</span><span class="special">*</span> <span class="identifier">slice</span> <span class="special">=</span> <span class="keyword">new</span> <span class="identifier">T</span><span class="special">[</span><span class="identifier">count</span><span class="special">];</span>
+ <span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">count</span> <span class="special">&amp;&amp;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">size_</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="identifier">slice</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">data_</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span>
+ <span class="keyword">delete</span><span class="special">[]</span> <span class="identifier">data_</span><span class="special">;</span>
+ <span class="identifier">data_</span> <span class="special">=</span> <span class="identifier">slice</span><span class="special">;</span>
+ <span class="identifier">size_</span> <span class="special">=</span> <span class="identifier">count</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">T</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">[]</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">index</span> <span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">data_</span><span class="special">[</span><span class="identifier">index</span><span class="special">];</span>
+ <span class="special">}</span>
+
+<span class="identifier">axioms</span><span class="special">:</span> <span class="comment">// Preconditions (require) and postconditions (promise).</span>
+ <span class="special">[</span> <span class="keyword">int</span> <span class="identifier">count</span><span class="special">;</span> <span class="identifier">require</span> <span class="identifier">count</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">promise</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span> <span class="special">]</span> <span class="identifier">vector</span><span class="special">(</span><span class="identifier">count</span><span class="special">);</span>
+ <span class="special">[</span> <span class="keyword">int</span> <span class="identifier">count</span><span class="special">;</span> <span class="identifier">require</span> <span class="identifier">count</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">promise</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span> <span class="special">]</span> <span class="identifier">resize</span><span class="special">(</span><span class="identifier">count</span><span class="special">);</span>
+ <span class="special">[</span> <span class="keyword">int</span> <span class="identifier">index</span><span class="special">;</span> <span class="identifier">require</span> <span class="identifier">index</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">&amp;&amp;</span> <span class="identifier">index</span> <span class="special">&lt;</span> <span class="identifier">size</span><span class="special">()</span> <span class="special">]</span> <span class="special">(*</span><span class="keyword">this</span><span class="special">)[</span><span class="identifier">x</span><span class="special">];</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">T</span><span class="special">*</span> <span class="identifier">data_</span><span class="special">;</span>
+ <span class="keyword">int</span> <span class="identifier">size_</span><span class="special">;</span>
+<span class="special">};</span>
+
+
+
+
+
+
+
+
+
+
+
+</pre>
+<p>
+ </p>
+ </td>
+</tr></tbody>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__cline90___vector_stack__subcontracting_from_abstract_data_type"></a><a class="link" href="examples.html#contract__.examples.__cline90___vector_stack__subcontracting_from_abstract_data_type" title="[Cline90] Vector-Stack: Subcontracting from Abstract Data Type">[Cline90]
+ Vector-Stack: Subcontracting from Abstract Data Type</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"vector.hpp"</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Stack Abstract Data Type (ADT).</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">stack_adt</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// NOTE: Incomplete set of assertions addressing only empty/full issues.</span>
+
+ <span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="comment">// no invariants</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">stack_adt</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="comment">// Postcondition: empty (cannot be checked because empty's</span>
+ <span class="comment">// postcondition uses length with is pure virtual during construction.</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"adt\n"</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(~</span><span class="identifier">stack_adt</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">full</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">length</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">capacity</span><span class="special">())</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">length</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">capacity</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">empty</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">length</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">length</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">length</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">capacity</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">push</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">value</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">full</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="comment">// Contract for pure virtual function.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">(</span><span class="identifier">pop</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">full</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">clear</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// Vector-based stack.</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">vstack</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="keyword">public</span> <span class="identifier">stack_adt</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span>
+ <span class="identifier">length</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">,</span>
+ <span class="identifier">length</span><span class="special">()</span> <span class="special">&lt;</span> <span class="identifier">capacity</span><span class="special">()</span>
+ <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">vstack</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">count</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">10</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span>
+ <span class="identifier">vect_</span><span class="special">(</span><span class="identifier">count</span><span class="special">),</span> <span class="comment">// OK, initializers executed after preconditions.</span>
+ <span class="identifier">length_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span>
+ <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">length</span><span class="special">()</span> <span class="special">==</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">capacity</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">vstack</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// NOTE: All following inherit contracts from `stack_adt`.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">length</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span> <span class="identifier">override</span> <span class="identifier">final</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">length_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">capacity</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">push</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">value</span> <span class="special">)</span> <span class="identifier">override</span> <span class="identifier">final</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">vect_</span><span class="special">[</span><span class="identifier">length_</span><span class="special">++]</span> <span class="special">=</span> <span class="identifier">value</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">(</span><span class="identifier">pop</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="identifier">override</span> <span class="identifier">final</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">vect_</span><span class="special">[--</span><span class="identifier">length_</span><span class="special">];</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">clear</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="identifier">override</span> <span class="identifier">final</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">length_</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">vect_</span><span class="special">;</span>
+ <span class="keyword">int</span> <span class="identifier">length_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__cline90___stack__a_very_simple_stack"></a><a class="link" href="examples.html#contract__.examples.__cline90___stack__a_very_simple_stack" title="[Cline90] Stack: A very simple stack">[Cline90]
+ Stack: A very simple stack</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">stack</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// NOTE: Incomplete set of assertions addressing only `empty` and `full`.</span>
+
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">stack</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">count</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">data_</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">count</span> <span class="special">&gt;=</span> <span class="number">0</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span>
+ <span class="identifier">empty</span><span class="special">(),</span>
+ <span class="identifier">full</span><span class="special">()</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">count</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span>
+ <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">data_</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span><span class="identifier">count</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">stack</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">empty</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">data_</span><span class="special">.</span><span class="identifier">empty</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">bool</span> <span class="special">(</span><span class="identifier">full</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">data_</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">data_</span><span class="special">.</span><span class="identifier">capacity</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">push</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="identifier">value</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">full</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">data_</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">value</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">(</span><span class="identifier">pop</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">full</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">T</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">data_</span><span class="special">.</span><span class="identifier">back</span><span class="special">();</span>
+ <span class="identifier">data_</span><span class="special">.</span><span class="identifier">pop_back</span><span class="special">();</span>
+ <span class="keyword">return</span> <span class="identifier">value</span><span class="special">;</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">data_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__cline90___calendar__a_very_simple_calendar"></a><a class="link" href="examples.html#contract__.examples.__cline90___calendar__a_very_simple_calendar" title="[Cline90] Calendar: A very simple calendar">[Cline90]
+ Calendar: A very simple calendar</a>
+</h3></div></div></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">contract</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">calendar</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span>
+ <span class="identifier">month</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">1</span><span class="special">,</span>
+ <span class="identifier">month</span><span class="special">()</span> <span class="special">&lt;=</span> <span class="number">12</span><span class="special">,</span>
+ <span class="identifier">date</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="number">1</span><span class="special">,</span>
+ <span class="identifier">date</span><span class="special">()</span> <span class="special">&lt;=</span> <span class="identifier">days_in</span><span class="special">(</span><span class="identifier">month_</span><span class="special">)</span>
+ <span class="special">)</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="special">(</span><span class="identifier">calendar</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">month_</span><span class="special">(</span><span class="number">1</span><span class="special">),</span> <span class="identifier">date_</span><span class="special">(</span><span class="number">31</span><span class="special">)</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">month</span><span class="special">()</span> <span class="special">==</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">date</span><span class="special">()</span> <span class="special">==</span> <span class="number">31</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_DESTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">virtual</span> <span class="special">(~</span><span class="identifier">calendar</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">month</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">month_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">date</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">date_</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">reset</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">new_month</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">new_month</span> <span class="special">&gt;=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">new_month</span> <span class="special">&lt;=</span> <span class="number">12</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="identifier">month</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">new_month</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">month_</span> <span class="special">=</span> <span class="identifier">new_month</span><span class="special">;</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="comment">/** @todo make this static */</span>
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">int</span> <span class="special">(</span><span class="identifier">days_in</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">month</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="number">31</span><span class="special">;</span> <span class="comment">// For simplicity, assume all months have 31 days.</span>
+ <span class="special">}</span>
+
+ <span class="keyword">int</span> <span class="identifier">month_</span><span class="special">,</span> <span class="identifier">date_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </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 &#169; 2008-2012 Lorenzo Caminiti<p>
+ Use, modification, and distribution is subject to the Boost Software License,
+ Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
+ Documentation at http://contractpp.sourceforge.net.
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="grammar.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/contract/libs/contract/doc/html2/contract__/bibliography.html
==============================================================================
--- (empty file)
+++ sandbox/contract/libs/contract/doc/html2/contract__/bibliography.html 2011-09-04 13:37:15 EDT (Sun, 04 Sep 2011)
@@ -0,0 +1,154 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Bibliography</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Contract++ 0.4.x">
+<link rel="up" href="../index.html" title="Contract++ 0.4.x">
+<link rel="prev" href="grammar.html" title="Appendix: Grammar">
+<link rel="next" href="release_notes.html" title="Release Notes">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="grammar.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="release_notes.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="contract__.bibliography"></a><a class="link" href="bibliography.html" title="Bibliography">Bibliography</a>
+</h2></div></div></div>
+<p>
+ [Bright04] W. Bright. <a href="http://www.digitalmars.com/d/2.0/dbc.html" target="_top"><span class="emphasis"><em>Contract
+ Programming for the D Programming Language.</em></span></a> 2004.
+ </p>
+<p>
+ [Bright04b] W. Bright. <a href="http://www.digitalmars.com/ctg/contract.html" target="_top"><span class="emphasis"><em>Contract
+ Programming for the Digital Mars C++ Compiler.</em></span></a> 2004.
+ </p>
+<p>
+ [C^2] Aechmea. <a href="http://www.programmersheaven.com/app/news/DisplayNews.aspx?NewsID=3843" target="_top"><span class="emphasis"><em>C^2
+ Contract Programming add-on for C++.</em></span></a> 2005.
+ </p>
+<p>
+ [Chrome02] RemObjects. <a href="http://blogs.remobjects.com/blogs/mh/2008/05/01/p216" target="_top"><span class="emphasis"><em>Chromes:
+ Contract Programming for Object Pascal in .NET.</em></span></a> 2002.
+ </p>
+<p>
+ [Cline90] M. Cline and D. Lea. "The Behaviour of C++ Classes" and
+ "Using Annotated C++". <span class="emphasis"><em>Proc. of the Symposium on Object
+ Oriented Programming Emphasizing Practical Applications</em></span>, Maris College,
+ 19090.
+ </p>
+<p>
+ [iContract] O. Enseling. <a href="http://www.javaworld.com/javaworld/jw-02-2001/jw-0216-cooltools.html" target="_top"><span class="emphasis"><em>iContract:
+ Contract Programming for Java.</em></span></a> 2001.
+ </p>
+<p>
+ [Jcontract] Parasoft. <a href="http://www.parasoft.com/jsp/products/article.jsp?label=product_info_Jcontract" target="_top"><span class="emphasis"><em>Jcontract:
+ Contract Programming for Java.</em></span></a>
+ </p>
+<p>
+ [Maley99] D. Maley and I. Spence. <a href="http://www.computer.org/portal/web/csdl/doi/10.1109/TOOLS.1999.779000" target="_top"><span class="emphasis"><em>Emulating
+ Design by Contract in C++.</em></span></a> Proceedings of TOOLS, IEEE Computer
+ Society, 1999.
+ </p>
+<p>
+ [Meyer97] B. Meyer. <span class="emphasis"><em>Object Oriented Software Construction.</em></span>
+ Prentice-Hall, 2nd edition, 1997.
+ </p>
+<p>
+ [Mitchell02] R. Mitchell and J. McKim. <span class="emphasis"><em>Design by Contract, by Example.</em></span>
+ Addison-Wesley, 2002.
+ </p>
+<p>
+ [N1613] T. Ottosen. <span class="emphasis"><em>Proposal to add Design by Contract to C++.</em></span>
+ The C++ Standards Committee, N1613,
+ 2004.
+ </p>
+<p>
+ [N1653] C. Nelson. <span class="emphasis"><em>Working draft changes for C99 preprocessor synchronization.</em></span>
+ C++ Standards Committee N1653,
+ 2004.
+ </p>
+<p>
+ [N1669] T. Ottosen. <span class="emphasis"><em>Proposal to add Contract Programming to C++ (revision
+ 1).</em></span> The C++ Standards Committee, N1669,
+ 2004.
+ </p>
+<p>
+ [N1773] D. Abrahams, L. Crowl, T. Ottosen, and J. Widman. <span class="emphasis"><em>Proposal
+ to add Contract Programming to C++ (revision 2).</em></span> The C++ Standards
+ Committee, N1773,
+ 2005.
+ </p>
+<p>
+ [N1866] L. Crowl and T. Ottosen. <span class="emphasis"><em>Proposal to add Contract Programming
+ to C++ (revision 3).</em></span> The C++ Standards Committee, N1866,
+ 2005.
+ </p>
+<p>
+ [N1895] H. Sutter and F. Glassborow. <span class="emphasis"><em>Delegating Constructors, revision
+ 2.</em></span> C++ Standards Committee, N1895,
+ 2005.
+ </p>
+<p>
+ [N1962] L. Crowl and T. Ottosen. <span class="emphasis"><em>Proposal to add Contract Programming
+ to C++ (revision 4).</em></span> The C++ Standards Committee, N1962,
+ 2006.
+ </p>
+<p>
+ [N2081] D. Gregor, B. Stroustrup. <span class="emphasis"><em>Concepts (revision 1).</em></span>
+ The C++ Standards Committee, N2081,
+ 2006.
+ </p>
+<p>
+ [N2906] B. Stroustrup. <span class="emphasis"><em>Simplifying the sue of concepts.</em></span>
+ The C++ Standards Committee, N2906,
+ 2009.
+ </p>
+<p>
+ [SPARKAda] Praxis. <a href="http://www.praxis-his.com/sparkada/language.asp" target="_top"><span class="emphasis"><em>SPARKAda
+ (Ada-like Language with Contract Programming).</em></span></a>
+ </p>
+<p>
+ [Spec#] Microsoft. <a href="http:://research.microsoft.com/en-us/projects/specsharp/" target="_top"><span class="emphasis"><em>Spec#
+ (C# Extension).</em></span></a>
+ </p>
+<p>
+ [Stroustrup97] B. Stroustrup. <span class="emphasis"><em>The C++ Programming Language.</em></span>
+ Prentice-Hall, 2nd Edition, 1997
+ </p>
+<p>
+ [Tandin04] A. Tandin. <a href="http://www.codeproject.com/KB/macros/DbC_and_Doxygen.aspx" target="_top"><span class="emphasis"><em>Design
+ by Contract macros for C++ and link to Doxygen.</em></span></a> 2004.
+ </p>
+<p>
+ [Wilson06] M. Wilson. <span class="emphasis"><em>Contract Programming 101 -- The Nuclear Reactor
+ and the Deep Space Probe.</em></span> <a href="http://www.artima.com/cppsource/deepspace.html" target="_top">The
+ C++ Source</a>, 2006.
+ </p>
+</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 &#169; 2008-2012 Lorenzo Caminiti<p>
+ Use, modification, and distribution is subject to the Boost Software License,
+ Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
+ Documentation at http://contractpp.sourceforge.net.
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="grammar.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="release_notes.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/contract/libs/contract/doc/html2/contract__/grammar.html
==============================================================================
--- (empty file)
+++ sandbox/contract/libs/contract/doc/html2/contract__/grammar.html 2011-09-04 13:37:15 EDT (Sun, 04 Sep 2011)
@@ -0,0 +1,1055 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Appendix: Grammar</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Contract++ 0.4.x">
+<link rel="up" href="../index.html" title="Contract++ 0.4.x">
+<link rel="prev" href="examples.html" title="Appendix: Examples">
+<link rel="next" href="bibliography.html" title="Bibliography">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="examples.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="bibliography.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="contract__.grammar"></a><a class="link" href="grammar.html" title="Appendix: Grammar">Appendix: Grammar</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section">Preprocessor DSEL</span></dt>
+<dt><span class="section"><a href="grammar.html#contract__.grammar.differences_with_c___syntax">Differences
+ with C++ Syntax</a></span></dt>
+<dt><span class="section">Lexical Conventions</span></dt>
+<dt><span class="section">Macro Interface</span></dt>
+<dt><span class="section">Class Declarations</span></dt>
+<dt><span class="section">Template Parameters</span></dt>
+<dt><span class="section">Types</span></dt>
+<dt><span class="section">Base Classes</span></dt>
+<dt><span class="section">Function Declarations</span></dt>
+<dt><span class="section"><a href="grammar.html#contract__.grammar.function_and_operator_names">Function
+ and Operator Names</a></span></dt>
+<dt><span class="section"><a href="grammar.html#contract__.grammar.exception_specifications">Exception
+ Specifications</a></span></dt>
+<dt><span class="section">Function Parameters</span></dt>
+<dt><span class="section"><a href="grammar.html#contract__.grammar.result_and_old_of_declarations">Result
+ and Old-Of Declarations</a></span></dt>
+<dt><span class="section">Class Invariants</span></dt>
+<dt><span class="section">Assertions</span></dt>
+<dt><span class="section">Loop Variants</span></dt>
+<dt><span class="section">Terminals</span></dt>
+</dl></div>
+<p>
+ The syntax used by this library macros effectively defies a new language within
+ C++. More precisely, this library defines a new Domain-Specific Embedded Language
+ (DSEL) that the authors have named <span class="emphasis"><em>L++</em></span>. This section illustrates
+ the complete L++ grammar.
+ </p>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.preprocessor_dsel"></a><a class="link" href="grammar.html#contract__.grammar.preprocessor_dsel" title="Preprocessor DSEL">Preprocessor DSEL</a>
+</h3></div></div></div>
+<p>
+ The domain of L++ is the specification of C++ program interfaces and L++
+ host language is obviously C++.
+ </p>
+<p>
+ It is important to note that in contrast with other C++ DSEL which are parsed
+ using C++ template meta-programming (e.g., Boost.Phoenix and Boost.Lambda),
+ L++ is parsed "one meta-programming level higher" using C++ preprocessor
+ meta-programming. Using both processor and template meta-programming allows
+ L++ to implement rules like the following:
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>if a member function is not public then it does not check the class invariants</em></span>
+</pre>
+<p>
+ This rule cannot be implemented using only template meta-programming because
+ (at lest to the authors' knowledge) it is not possible to check if a function
+ is public using a C++ template meta-function like <code class="computeroutput"><span class="identifier">is_public</span><span class="special">&lt;</span></code><span class="emphasis"><em>function-type</em></span><code class="computeroutput"><span class="special">&gt;</span></code>. Instead a macro <code class="computeroutput"><span class="identifier">IS_PUBLIC</span><span class="special">(</span></code><span class="emphasis"><em>function-decl</em></span><code class="computeroutput"><span class="special">)</span></code> can be written to parse the function declaration
+ and expand to <code class="computeroutput"><span class="number">1</span></code> if and only if
+ the function is public:
+ </p>
+<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">IS_PUBLIC</span><span class="special">(</span><span class="identifier">function_decl</span><span class="special">)</span> <span class="special">...</span>
+
+<span class="identifier">IS_PUBLIC</span><span class="special">(</span> <span class="keyword">public</span> <span class="keyword">void</span> <span class="identifier">f</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">x</span> <span class="special">)</span> <span class="special">)</span> <span class="comment">// expand to 1</span>
+<span class="identifier">IS_PUBLIC</span><span class="special">(</span> <span class="keyword">private</span> <span class="keyword">void</span> <span class="identifier">g</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">y</span> <span class="special">)</span> <span class="special">)</span> <span class="comment">// expand to 0</span>
+</pre>
+<p>
+ More in general, macros can parse L++ class and function declarations extracting
+ <span class="emphasis"><em>any</em></span> declaration trait (if a constructor is <code class="computeroutput"><span class="keyword">explicit</span></code>, if a member function is <code class="computeroutput"><span class="keyword">virtual</span></code>, if a base class if <code class="computeroutput"><span class="keyword">protected</span></code>, etc).
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.differences_with_c___syntax"></a><a class="link" href="grammar.html#contract__.grammar.differences_with_c___syntax" title="Differences with C++ Syntax">Differences
+ with C++ Syntax</a>
+</h3></div></div></div>
+<p>
+ Spaces and new lines do not matter in L++ however the following lexical conventions
+ are followed to improve readability:
+ </p>
+<div class="orderedlist"><ol class="orderedlist" type="1">
+<li class="listitem">
+ Round parenthesis are spaced when they specify a list of tokens <code class="computeroutput"><span class="special">(</span> </code><span class="emphasis"><em>token-list</em></span> <code class="computeroutput"><span class="special">)</span></code>. For example, function parameters <code class="computeroutput"><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span> <span class="special">)</span></code>.
+ </li>
+<li class="listitem">
+ Round parenthesis are not spaced when they wrap a single token <code class="computeroutput"><span class="special">(</span></code><span class="emphasis"><em>token</em></span><code class="computeroutput"><span class="special">)</span></code>. For example, a function name <code class="computeroutput"><span class="special">(</span><span class="identifier">myfunc</span><span class="special">)</span></code>.
+ </li>
+</ol></div>
+<div class="warning"><table border="0" summary="Warning">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../doc/src/images/warning.png"></td>
+<th align="left">Warning</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ A bug in the MSVC preprocessor makes it not accept the following expression
+ <code class="computeroutput"><span class="special">(</span><span class="identifier">type</span><span class="special">)</span><span class="identifier">name</span></code>
+ without a space between the parenthesized type and the name. Therefore,
+ MSVC programmers should make sure to always introduce at least a space
+ or new line between type and name <code class="computeroutput"><span class="special">(</span><span class="identifier">type</span><span class="special">)</span> <span class="identifier">name</span></code> (this form is also more readable).
+ </p></td></tr>
+</table></div>
+<p>
+ The following is a summary of the differences between L++ and usual C++ declaration
+ syntax:
+ </p>
+<div class="orderedlist"><ol class="orderedlist" type="1">
+<li class="listitem">
+ Use round parenthesis <code class="computeroutput"><span class="special">(</span> <span class="special">...</span> <span class="special">)</span></code>
+ instead of angular parenthesis <code class="computeroutput"><span class="special">&lt;</span>
+ <span class="special">...</span> <span class="special">&gt;</span></code>
+ to declare template parameter lists (note that template instantiations
+ are not template declarations and they still use angular parenthesis).
+ </li>
+<li class="listitem">
+ Use round parenthesis <code class="computeroutput"><span class="special">(</span> <span class="special">...</span> <span class="special">)</span></code>
+ instead of angular parenthesis <code class="computeroutput"><span class="special">&lt;</span>
+ <span class="special">...</span> <span class="special">&gt;</span></code>
+ after a class template name to specify template specialization parameters.
+ </li>
+<li class="listitem">
+ Wrap class and function names within round parenthesis <code class="computeroutput"><span class="special">(</span></code>/name<code class="computeroutput"><span class="special">/)</span></code>.
+ </li>
+<li class="listitem">
+ Use <code class="computeroutput"><span class="identifier">extend</span><span class="special">(</span>
+ <span class="special">...</span> <span class="special">)</span></code>
+ instead of the comma symbol <code class="computeroutput"><span class="special">:</span></code>
+ to inherit from base classes.
+ </li>
+<li class="listitem">
+ Use <code class="computeroutput"><span class="keyword">default</span> </code><span class="emphasis"><em>default-value</em></span>
+ instead of the symbol <code class="computeroutput"><span class="special">=</span> </code><span class="emphasis"><em>default-value</em></span>
+ to specify template and function parameter default values.
+ </li>
+<li class="listitem">
+ Always specify the access level <code class="computeroutput"><span class="keyword">public</span></code>,
+ <code class="computeroutput"><span class="keyword">protected</span></code>, or <code class="computeroutput"><span class="keyword">private</span></code> and without the trailing comma
+ <code class="computeroutput"><span class="special">:</span></code> for every constructor,
+ destructor, and member function declaration.
+ </li>
+<li class="listitem">
+ Wrap the function result and parameter types within round parenthesis
+ <code class="computeroutput"><span class="special">(</span></code><span class="emphasis"><em>type</em></span><code class="computeroutput"><span class="special">)</span></code>. The wrapping parenthesis are allowed
+ but not required for types that only use keywords and contain no non-alphanumeric
+ symbol. For example: Both <code class="computeroutput"><span class="special">(</span><span class="keyword">const</span> <span class="keyword">unsigned</span>
+ <span class="keyword">int</span><span class="special">)</span></code>
+ and <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">unsigned</span>
+ <span class="keyword">int</span></code> are allowed; Only <code class="computeroutput"><span class="special">(</span><span class="keyword">int</span><span class="special">&amp;)</span></code>
+ and not <code class="computeroutput"><span class="keyword">int</span><span class="special">&amp;</span></code>
+ is allowed because of the non-alphanumeric symbol <code class="computeroutput"><span class="special">&amp;</span></code>;
+ Only <code class="computeroutput"><span class="special">(</span><span class="identifier">my_type</span><span class="special">)</span></code> is allowed because <code class="computeroutput"><span class="identifier">my_type</span></code>
+ is not a keyword.
+ </li>
+<li class="listitem">
+ Use <code class="computeroutput"><span class="identifier">initialize</span><span class="special">(</span>
+ <span class="special">...</span> <span class="special">)</span></code>
+ instead of the comma <code class="computeroutput"><span class="special">:</span> <span class="special">...</span></code> to specify constructor member initializers.
+ </li>
+<li class="listitem">
+ Separate list elements using commas <code class="computeroutput"><span class="special">...</span>
+ <span class="special">,</span> <span class="special">...</span></code>
+ if variadic macros are supported (preferred) or round parenthesis <code class="computeroutput"><span class="special">(...)</span> <span class="special">(...)</span></code>
+ regardless of variadic macro support. Specify empty lists using <code class="computeroutput"><span class="special">(</span> <span class="special">)</span></code> if
+ empty empty macro parameters are supported, <code class="computeroutput"><span class="special">(</span>
+ <span class="keyword">void</span> <span class="special">)</span></code>
+ if variadic macros are supported (preferred), or <code class="computeroutput"><span class="special">(</span>
+ <span class="special">(</span><span class="keyword">void</span><span class="special">)</span> <span class="special">)</span></code> regardless
+ or empty and variaid macro support.
+ </li>
+<li class="listitem">
+ Assertions, default parameter values, and select assertion if-conditions
+ must start with an alphanumeric letter or an open round parenthesis
+ <code class="computeroutput"><span class="number">0</span><span class="special">-</span><span class="number">9</span><span class="special">,</span> <span class="identifier">a</span><span class="special">-</span><span class="identifier">z</span><span class="special">,</span> <span class="identifier">A</span><span class="special">-</span><span class="identifier">Z</span><span class="special">,</span> <span class="special">(</span></code>. For
+ example, use <code class="computeroutput"><span class="identifier">x</span> <span class="special">==</span>
+ <span class="keyword">false</span></code>, <code class="computeroutput"><span class="keyword">bool</span><span class="special">(!</span><span class="identifier">x</span><span class="special">)</span></code> or <code class="computeroutput"><span class="special">(!</span><span class="identifier">x</span><span class="special">)</span></code>
+ instead of <code class="computeroutput"><span class="special">!</span><span class="identifier">x</span></code>
+ which starts with the non alphanumeric symbol <code class="computeroutput"><span class="special">!</span></code>.
+ Similarly use <code class="computeroutput"><span class="special">(</span><span class="number">1.23</span><span class="special">)</span></code> or <code class="computeroutput"><span class="keyword">double</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span></code>
+ instead of <code class="computeroutput"><span class="number">1.23</span></code> because
+ <code class="computeroutput"><span class="number">1.23</span></code> is a C++ non-alphanumeric
+ token (it contains <code class="computeroutput"><span class="special">.</span></code>).
+ </li>
+</ol></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.lexical_conventions"></a><a class="link" href="grammar.html#contract__.grammar.lexical_conventions" title="Lexical Conventions">Lexical Conventions</a>
+</h3></div></div></div>
+<p>
+ The following conventions are followed by this grammar:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ <code class="computeroutput"><span class="special">[</span><span class="identifier">tokens</span><span class="special">]</span></code> indicates either <code class="computeroutput"><span class="identifier">tokens</span></code>
+ or nothing.
+ </li>
+<li class="listitem">
+ <code class="computeroutput"><span class="special">{</span><span class="identifier">expr</span><span class="special">}</span></code> indicates the result of the enclosed
+ expression <code class="computeroutput"><span class="identifier">expr</span></code>.
+ </li>
+<li class="listitem">
+ <code class="computeroutput"><span class="identifier">tokens1</span> <span class="special">|</span>
+ <span class="identifier">tokens2</span></code> indicates either <code class="computeroutput"><span class="identifier">tokens1</span></code> or <code class="computeroutput"><span class="identifier">tokens2</span></code>.
+ </li>
+<li class="listitem">
+ <code class="computeroutput"><span class="identifier">tokens</span><span class="special">*</span></code>
+ indicates <code class="computeroutput"><span class="identifier">tokens</span></code> repeated
+ zero or more times.
+ </li>
+<li class="listitem">
+ Terminals are indicated in bold <span class="bold"><strong><code class="literal">symbol</code></strong></span>.
+ </li>
+<li class="listitem">
+ Non-terminals are indicated in italic <span class="emphasis"><em><code class="literal">symbol</code></em></span>.
+ </li>
+</ul></div>
+<div class="important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ The following grammar is written assuming variadic macros support and therefore
+ it uses comma separated list of tokens <code class="computeroutput"><span class="identifier">token1</span><span class="special">,</span> <span class="identifier">token2</span><span class="special">,</span> <span class="special">...</span></code>. The
+ same grammar holds with parenthesized token lists <code class="computeroutput"><span class="special">(</span><span class="identifier">token1</span><span class="special">)</span> <span class="special">(</span><span class="identifier">token2</span><span class="special">)</span> <span class="special">...</span></code> for
+ compilers that do not support varidiac macros or if programmers want to
+ avoid using variaidc macros to write fully ISO C++ compliant code.
+ </p></td></tr>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.macro_interface"></a><a class="link" href="grammar.html#contract__.grammar.macro_interface" title="Macro Interface">Macro Interface</a>
+</h3></div></div></div>
+<p>
+ This library uses the following macros:
+ </p>
+<pre class="programlisting"><span class="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="emphasis"><em>class-decl</em></span> <span class="special">)</span>
+
+<span class="identifier">CONTRACT_CLASS_INVARIANT</span><span class="special">(</span> <span class="emphasis"><em>[class-invariants]</em></span> <span class="special">)</span>
+<span class="identifier">CONTRACT_CLASS_INVARIANT_TPL</span><span class="special">(</span> <span class="emphasis"><em>[class-invariants]</em></span> <span class="special">)</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="emphasis"><em>function-decl</em></span> <span class="special">)</span>
+<span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="emphasis"><em>function-decl</em></span> <span class="special">)</span>
+
+<span class="identifier">CONTRACT_BLOCK_INVARIANT</span><span class="special">(</span> <span class="emphasis"><em>assertions</em></span> <span class="special">)</span>
+<span class="identifier">CONTRACT_BLOCK_INVARIANT_TPL</span><span class="special">(</span> <span class="emphasis"><em>assertions</em></span> <span class="special">)</span>
+
+<span class="identifier">CONTRACT_LOOP</span><span class="special">(</span> <span class="bold"><strong>loop-decl</strong></span> <span class="special">)</span>
+<span class="identifier">CONTRACT_LOOP_VARIANT</span><span class="special">(</span> <span class="emphasis"><em>loop-variant</em></span> <span class="special">)</span>
+<span class="identifier">CONTRACT_LOOP_VARIANT_TPL</span><span class="special">(</span> <span class="emphasis"><em>loop-variant</em></span> <span class="special">)</span>
+
+<span class="identifier">CONTRACT_FREE_BODY</span><span class="special">(</span><span class="emphasis"><em>function-name</em></span><span class="special">)</span>
+<span class="identifier">CONTRACT_MEMBER_BODY</span><span class="special">(</span><span class="emphasis"><em>function-name</em></span><span class="special">)</span>
+<span class="identifier">CONTRACT_CONSTRUCTOR_BODY</span><span class="special">(</span><span class="bold"><strong>class-type</strong></span><span class="special">,</span> <span class="bold"><strong>class-name</strong></span><span class="special">)</span>
+<span class="identifier">CONTRACT_DESTRUCTOR_BODY</span><span class="special">(</span><span class="bold"><strong>class-type</strong></span><span class="special">,</span> <span class="special">~</span><span class="bold"><strong>class-name</strong></span><span class="special">)</span>
+</pre>
+<p>
+ The macros with the trailing <code class="computeroutput"><span class="identifier">_TPL</span></code>
+ must be used when the enclosing scope is type dependant (e.g., within a class
+ template).
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.class_declarations"></a><a class="link" href="grammar.html#contract__.grammar.class_declarations" title="Class Declarations">Class Declarations</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>class-decl:</em></span>
+ <span class="emphasis"><em>[[</em></span><span class="keyword">export</span><span class="emphasis"><em>]</em></span> <span class="keyword">template</span><span class="special">(</span> <span class="emphasis"><em>[template-params]</em></span> <span class="special">)</span> <span class="emphasis"><em>[</em></span><span class="identifier">requires</span><span class="special">(</span> <span class="bold"><strong>boost-concept</strong></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span><span class="emphasis"><em>]]</em></span>
+ <span class="emphasis"><em>{</em></span><span class="keyword">class</span> <span class="emphasis"><em>|</em></span> <span class="keyword">struct</span><span class="emphasis"><em>}</em></span> <span class="special">(</span><span class="bold"><strong>class-name</strong></span><span class="special">)</span><span class="emphasis"><em>[</em></span><span class="special">(</span> <span class="bold"><strong>template-specialization-type</strong></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span><span class="emphasis"><em>] [</em></span><span class="identifier">final</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>[</em></span><span class="identifier">extends</span><span class="special">(</span> <span class="emphasis"><em>base</em></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span><span class="emphasis"><em>]</em></span>
+</pre>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.template_parameters"></a><a class="link" href="grammar.html#contract__.grammar.template_parameters" title="Template Parameters">Template Parameters</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>template-params:</em></span>
+ <span class="keyword">void</span> <span class="special">|</span> <span class="emphasis"><em>{template-param</em></span><span class="special">,</span> <span class="special">...</span><span class="emphasis"><em>}</em></span>
+
+<span class="emphasis"><em>template-param:</em></span>
+ <span class="emphasis"><em>type-template-param | value-template-param</em></span>
+
+<span class="emphasis"><em>type-template-param:</em></span>
+ <span class="emphasis"><em>{</em></span><span class="keyword">class</span> <span class="emphasis"><em>|</em></span> <span class="keyword">typename</span><span class="emphasis"><em>}</em></span> <span class="bold"><strong>type-name</strong></span> <span class="emphasis"><em>[</em></span><span class="special">,</span> <span class="keyword">default</span> <span class="bold"><strong>default-type</strong></span><span class="emphasis"><em>]</em></span>
+
+<span class="emphasis"><em>value-template-param:</em></span>
+ <span class="emphasis"><em>type</em></span> <span class="bold"><strong>value-name</strong></span> <span class="emphasis"><em>[</em></span><span class="special">,</span> <span class="keyword">default</span> <span class="bold"><strong>default-value</strong></span><span class="emphasis"><em>]</em></span>
+</pre>
+<p>
+ Note that if <code class="computeroutput"><span class="keyword">typename</span></code> appears
+ within <span class="emphasis"><em><code class="literal">type</code></em></span> for a <span class="emphasis"><em><code class="literal">value-template-param</code></em></span>
+ then it will be wrapped within parenthesis <code class="computeroutput"><span class="special">(</span><span class="keyword">typename</span> <span class="special">...)</span></code>
+ so it is distinguishable from the <code class="computeroutput"><span class="keyword">typename</span></code>
+ in <span class="emphasis"><em><code class="literal">type-template-param</code></em></span>.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.types"></a><a class="link" href="grammar.html#contract__.grammar.types" title="Types">Types</a>
+</h3></div></div></div>
+<p>
+ This is the type used to specify value template parameter types, function
+ result types, function parameter types, etc. As specified by the following
+ grammar rules, extra parenthesis around this type are always allowed but
+ they are required only around user-defined types <code class="computeroutput"><span class="special">(</span><span class="identifier">mytype</span><span class="special">)</span></code>
+ or types containing non-alphanumeric symbols <code class="computeroutput"><span class="special">(</span><span class="keyword">int</span><span class="special">*)</span></code>.
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>type:</em></span>
+ <span class="emphasis"><em>keyword-type |</em></span> <span class="special">(</span><span class="emphasis"><em>keyword-type</em></span><span class="special">)</span> <span class="emphasis"><em>|</em></span> <span class="special">(</span><span class="bold"><strong>type</strong></span><span class="special">)</span>
+
+<span class="emphasis"><em>keyword-type:</em></span>
+ <span class="emphasis"><em>type-qualifier* fundamental-type type-qualifier*</em></span>
+
+<span class="emphasis"><em>type-qualifier:</em></span>
+ <span class="keyword">const</span> <span class="emphasis"><em>|</em></span> <span class="keyword">volatile</span> <span class="emphasis"><em>|</em></span> <span class="keyword">long</span> <span class="emphasis"><em>|</em></span> <span class="keyword">short</span> <span class="emphasis"><em>|</em></span> <span class="keyword">signed</span> <span class="emphasis"><em>|</em></span> <span class="keyword">unsigned</span>
+
+<span class="emphasis"><em>fundamental-type:</em></span>
+ <span class="keyword">void</span> <span class="emphasis"><em>|</em></span> <span class="keyword">bool</span> <span class="emphasis"><em>|</em></span> <span class="keyword">char</span> <span class="emphasis"><em>|</em></span> <span class="keyword">double</span> <span class="emphasis"><em>|</em></span> <span class="keyword">float</span> <span class="emphasis"><em>|</em></span> <span class="keyword">int</span> <span class="emphasis"><em>|</em></span> <span class="keyword">wchar_t</span> <span class="emphasis"><em>|</em></span> <span class="identifier">size_t</span> <span class="emphasis"><em>|</em></span> <span class="identifier">ptrdiff_t</span>
+</pre>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.base_classes"></a><a class="link" href="grammar.html#contract__.grammar.base_classes" title="Base Classes">Base Classes</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>base:</em></span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">virtual</span><span class="emphasis"><em>] [</em></span><span class="keyword">public</span> <span class="emphasis"><em>|</em></span> <span class="keyword">protected</span> <span class="emphasis"><em>|</em></span> <span class="keyword">private</span><span class="emphasis"><em>]</em></span> <span class="bold"><strong>base-type</strong></span>
+</pre>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.function_declarations"></a><a class="link" href="grammar.html#contract__.grammar.function_declarations" title="Function Declarations">Function Declarations</a>
+</h3></div></div></div>
+<p>
+ Grammatic rules used to declare any function (free functions, member functions,
+ constructors, destructors, and operators). The usual constraints of C++ function
+ declarations apply (for example, it is not possible to declare a static virtual
+ member function, only constructors can use the class name as the function
+ name, etc).
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>function-decl:</em></span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">public</span> <span class="emphasis"><em>|</em></span> <span class="keyword">protected</span> <span class="emphasis"><em>|</em></span> <span class="keyword">private</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>[[</em></span><span class="keyword">export</span><span class="emphasis"><em>] [</em></span><span class="keyword">template</span><span class="special">(</span> <span class="emphasis"><em>template-param</em></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span> <span class="emphasis"><em>[</em></span><span class="identifier">requires</span><span class="special">(</span> <span class="bold"><strong>concept</strong></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span><span class="emphasis"><em>]]</em></span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">explicit</span><span class="emphasis"><em>] [</em></span><span class="keyword">inline</span><span class="emphasis"><em>] [</em></span><span class="keyword">extern</span><span class="emphasis"><em>] [</em></span><span class="keyword">static</span><span class="emphasis"><em>] [</em></span><span class="keyword">virtual</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>[type] function-name</em></span> <span class="special">(</span> <span class="emphasis"><em>[function-params]</em></span> <span class="special">)</span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">const</span><span class="emphasis"><em>] [</em></span><span class="keyword">volatile</span><span class="emphasis"><em>] [</em></span><span class="identifier">override</span> <span class="emphasis"><em>|</em></span> <span class="keyword">new</span><span class="emphasis"><em>] [</em></span><span class="identifier">final</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">throw</span><span class="special">(</span> <span class="emphasis"><em>[expections]</em></span> <span class="special">)</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>[</em></span><span class="identifier">initialize</span><span class="special">(</span> <span class="bold"><strong>member-initializer</strong></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>[</em></span><span class="identifier">precondition</span><span class="special">(</span> <span class="emphasis"><em>assertion</em></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>[</em></span><span class="identifier">postcondition</span><span class="special">(</span> <span class="emphasis"><em>result-oldof-assertions</em></span> <span class="special">)</span><span class="emphasis"><em>]</em></span>
+</pre>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.function_and_operator_names"></a><a class="link" href="grammar.html#contract__.grammar.function_and_operator_names" title="Function and Operator Names">Function
+ and Operator Names</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>function-name:</em></span>
+ <span class="special">(</span><span class="bold"><strong>function-name</strong></span><span class="special">)</span> <span class="emphasis"><em>|</em></span> <span class="special">(</span><span class="bold"><strong>class-name</strong></span><span class="special">)</span> <span class="emphasis"><em>|</em></span> <span class="special">(~</span><span class="bold"><strong>class_name</strong></span><span class="special">)</span> <span class="emphasis"><em>| operator-name</em></span>
+
+<span class="emphasis"><em>operator-name:</em></span>
+ <span class="keyword">operator</span><span class="special">(</span><span class="bold"><strong>operator-symbol</strong></span><span class="special">)(</span><span class="bold"><strong>operator-arbitrary-name</strong></span><span class="special">)</span> <span class="emphasis"><em>|</em></span> <span class="keyword">operator</span> <span class="emphasis"><em>type |</em></span>
+ <span class="keyword">operator</span> <span class="keyword">new</span> <span class="emphasis"><em>|</em></span> <span class="keyword">operator</span> <span class="keyword">delete</span> <span class="emphasis"><em>|</em></span> <span class="keyword">operator</span> <span class="identifier">comma</span>
+</pre>
+<p>
+ Operator names are specified by the usual operator symbol followed by an
+ arbitrary alphanumeric name, for example:
+ </p>
+<pre class="programlisting"><span class="keyword">operator</span><span class="special">([])(</span><span class="identifier">at</span><span class="special">)</span>
+<span class="keyword">operator</span><span class="special">(+)(</span><span class="identifier">plus</span><span class="special">)</span>
+<span class="keyword">operator</span><span class="special">(())(</span><span class="identifier">call</span><span class="special">)</span>
+<span class="keyword">operator</span><span class="special">(</span><span class="keyword">new</span><span class="special">[])(</span><span class="identifier">new_array</span><span class="special">)</span>
+<span class="keyword">operator</span><span class="special">(</span><span class="keyword">delete</span><span class="special">[])(</span><span class="identifier">delete_array</span><span class="special">)</span>
+</pre>
+<p>
+ Implicit type conversion operators use the same syntax, for example:
+ </p>
+<pre class="programlisting"><span class="keyword">operator</span><span class="special">(</span><span class="keyword">int</span><span class="special">*)(</span><span class="identifier">int_ptr</span><span class="special">)</span>
+<span class="keyword">operator</span><span class="special">(</span><span class="identifier">mytype</span> <span class="keyword">const</span><span class="special">&amp;)(</span><span class="identifier">mytype_const_ref</span><span class="special">)</span>
+</pre>
+<p>
+ However, if the type does not contain any alphanumeric symbol then the parenthesis
+ and the arbitrary name are optional, for example both the following are valid:
+ </p>
+<pre class="programlisting"><span class="keyword">operator</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">)(</span><span class="identifier">const_int</span><span class="special">)</span>
+<span class="keyword">operator</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="comment">// Simpler.</span>
+
+<span class="keyword">operator</span><span class="special">(</span><span class="identifier">mytype</span><span class="special">)(</span><span class="identifier">mytype_t</span><span class="special">)</span>
+<span class="keyword">operator</span> <span class="special">(</span><span class="identifier">mytype</span><span class="special">)</span> <span class="comment">// Simpler.</span>
+</pre>
+<p>
+ Similarly, the parenthesis and arbitrary name are optional for the <code class="computeroutput"><span class="keyword">new</span></code> and <code class="computeroutput"><span class="keyword">delete</span></code>
+ operators so all the followings are valid:
+ </p>
+<pre class="programlisting"><span class="keyword">operator</span><span class="special">(</span><span class="keyword">new</span><span class="special">)(</span><span class="identifier">new_ptr</span><span class="special">)</span>
+<span class="keyword">operator</span> <span class="keyword">new</span> <span class="comment">// Simpler.</span>
+
+<span class="keyword">operator</span><span class="special">(</span><span class="keyword">delete</span><span class="special">)(</span><span class="identifier">delete_ptr</span><span class="special">)</span>
+<span class="keyword">operator</span> <span class="keyword">delete</span> <span class="comment">// Simpler.</span>
+</pre>
+<p>
+ Finally, the comma symbol <code class="computeroutput"><span class="special">,</span></code>
+ can never be used (because for macros a comma <code class="computeroutput"><span class="special">,</span></code>
+ has the special meaning of separating the macro parameters) so the "keyword"
+ <code class="computeroutput"><span class="identifier">comma</span></code> must be used to specify
+ the comma operator:
+ </p>
+<pre class="programlisting"><span class="keyword">operator</span><span class="special">(,)(</span><span class="identifier">comma</span><span class="special">)</span> <span class="comment">// Error.</span>
+<span class="keyword">operator</span> <span class="identifier">comma</span> <span class="comment">// OK.</span>
+</pre>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.exception_specifications"></a><a class="link" href="grammar.html#contract__.grammar.exception_specifications" title="Exception Specifications">Exception
+ Specifications</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>exceptions:</em></span>
+ <span class="keyword">void</span> <span class="special">|</span> <span class="emphasis"><em>{</em></span><span class="bold"><strong>exception-type</strong></span><span class="special">,</span> <span class="special">...</span><span class="emphasis"><em>}</em></span>
+</pre>
+<p>
+ The keyword <code class="computeroutput"><span class="keyword">void</span></code> is used for
+ no-throw <code class="computeroutput"><span class="keyword">throw</span><span class="special">(</span>
+ <span class="keyword">void</span> <span class="special">)</span></code>.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.function_parameters"></a><a class="link" href="grammar.html#contract__.grammar.function_parameters" title="Function Parameters">Function Parameters</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>function-params:</em></span>
+ <span class="keyword">void</span> <span class="emphasis"><em>| positional-function-params | shuffled-function-params</em></span>
+
+<span class="emphasis"><em>positional-function-params:</em></span>
+ <span class="emphasis"><em>positional-function-param</em></span><span class="special">,</span> <span class="special">...</span>
+
+<span class="emphasis"><em>shuffled-function-params:</em></span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">namespace</span> <span class="emphasis"><em>tag-namespace</em></span><span class="special">,</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>named-function-params | deduced-function-params |</em></span>
+ <span class="emphasis"><em>{named-function-params</em></span><span class="special">,</span> <span class="emphasis"><em>deduced-function-params}</em></span>
+
+<span class="emphasis"><em>named-function-params:</em></span>
+ <span class="emphasis"><em>named-function-param</em></span><span class="special">,</span> <span class="special">...</span>
+
+<span class="emphasis"><em>deduced-function-params:</em></span>
+ <span class="identifier">deduce</span><span class="special">(</span> <span class="emphasis"><em>named-function-param</em></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span>
+
+<span class="emphasis"><em>function-param:</em></span>
+ <span class="emphasis"><em>positional-function-param | named-function-param</em></span>
+
+<span class="emphasis"><em>positional-function-param:</em></span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">auto</span> <span class="emphasis"><em>|</em></span> <span class="keyword">register</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>type</em></span> <span class="bold"><strong>value-name</strong></span>
+ <span class="emphasis"><em>[</em></span><span class="special">,</span> <span class="keyword">default</span> <span class="bold"><strong>defaul-value</strong></span><span class="emphasis"><em>]</em></span>
+
+<span class="emphasis"><em>named-function-param:</em></span>
+ <span class="emphasis"><em>[</em></span><span class="identifier">in</span> <span class="emphasis"><em>|</em></span> <span class="identifier">out</span> <span class="emphasis"><em>|</em></span> <span class="identifier">inout</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>{</em></span><span class="keyword">auto</span> <span class="emphasis"><em>|</em></span> <span class="identifier">requires</span><span class="special">(</span><span class="emphasis"><em>predicate-metafunction</em></span><span class="special">)</span> <span class="emphasis"><em>| type}</em></span> <span class="bold"><strong>value-name</strong></span>
+ <span class="emphasis"><em>[</em></span><span class="special">,</span> <span class="keyword">default</span> <span class="bold"><strong>default-value</strong></span><span class="emphasis"><em>]</em></span>
+</pre>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.result_and_old_of_declarations"></a><a class="link" href="grammar.html#contract__.grammar.result_and_old_of_declarations" title="Result and Old-Of Declarations">Result
+ and Old-Of Declarations</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>result_oldof_assertions:</em></span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">auto</span> <span class="bold"><strong>var-name</strong></span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span> <span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>[oldof</em></span><span class="special">,</span> <span class="special">...</span><span class="emphasis"><em>]</em></span>
+ <span class="emphasis"><em>assertion</em></span><span class="special">,</span> <span class="special">...</span>
+</pre>
+<p>
+ If present, result and old-ofs declarations should appear at the top because
+ they will always be visible to all assertions plus these declarations cannot
+ be nested (within select-assertions, etc). The result declaration type is
+ always <code class="computeroutput"><span class="keyword">auto</span></code> because the function
+ result type is know and already specified by the function declaration.
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>oldof:</em></span>
+ <span class="emphasis"><em>{</em></span><span class="keyword">auto</span> <span class="emphasis"><em>| type}</em></span> <span class="bold"><strong>var-name</strong></span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="bold"><strong>oldof-expr</strong></span>
+</pre>
+<p>
+ The macro "operator" <code class="computeroutput"><span class="identifier">CONTRACT_OLDOF</span></code>
+ does not require but allows parenthesis around the value expression <span class="bold"><strong><code class="literal">oldof-expr</code></strong></span> (this is as specified
+ for the <code class="computeroutput"><span class="identifier">oldof</span></code> operator in
+ <a class="link" href="bibliography.html" title="Bibliography">[N1962]</a> and similarly to the
+ <code class="computeroutput"><span class="keyword">sizeof</span></code> operator which requires
+ parenthesis when applied to a type expression <code class="computeroutput"><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span></code> but not when applied to a value expression
+ <code class="computeroutput"><span class="keyword">sizeof</span> <span class="identifier">size</span><span class="special">()</span></code>). The old-of declaration type is automatically
+ deduced (using Boost.Typeof) when specified as <code class="computeroutput"><span class="keyword">auto</span></code>
+ instead of <span class="emphasis"><em><code class="literal">type</code></em></span>. For example, all
+ the followings are valid:
+ </p>
+<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">()</span>
+<span class="keyword">auto</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">size</span><span class="special">())</span> <span class="comment">// Extra parenthesis around expression (optional).</span>
+<span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span> <span class="identifier">size</span><span class="special">()</span> <span class="comment">// Do not use Boost.Typeof.</span>
+<span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span> <span class="identifier">old_size</span> <span class="special">=</span> <span class="identifier">CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">size</span><span class="special">())</span> <span class="comment">// No Boost.Typeof and extra parenthesis.</span>
+</pre>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.class_invariants"></a><a class="link" href="grammar.html#contract__.grammar.class_invariants" title="Class Invariants">Class Invariants</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>class-invariants:</em></span>
+ <span class="keyword">void</span> <span class="emphasis"><em>| {class-invariant</em></span><span class="special">,</span> <span class="special">...</span><span class="emphasis"><em>}</em></span>
+
+<span class="emphasis"><em>class-invariant:</em></span>
+ <span class="emphasis"><em>assertion |</em></span>
+ <span class="keyword">volatile</span> <span class="keyword">class</span><span class="special">(</span> <span class="keyword">void</span> <span class="emphasis"><em>| [assertion</em></span><span class="special">,</span> <span class="special">...</span><span class="emphasis"><em>]</em></span> <span class="special">)</span> <span class="emphasis"><em>|</em></span>
+ <span class="keyword">static</span> <span class="keyword">class</span><span class="special">(</span> <span class="keyword">void</span> <span class="emphasis"><em>| [assertion</em></span>, <span class="special">...</span><span class="emphasis"><em>]</em></span> <span class="special">)</span>
+</pre>
+<p>
+ Volatile class invariants are assumed to have the same assertions as the
+ class invariants unless explicitly specified. Static class invariants are
+ assumed to assert nothing unless explicitly specified.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.assertions"></a><a class="link" href="grammar.html#contract__.grammar.assertions" title="Assertions">Assertions</a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="emphasis"><em>assertion:</em></span>
+ <span class="emphasis"><em>expr-assertion | select-assertion |</em></span>
+ <span class="keyword">using</span> <span class="bold"><strong>using-directive</strong></span> <span class="emphasis"><em>|</em></span> <span class="keyword">namespace</span> <span class="bold"><strong>namespace-alias</strong></span>
+</pre>
+<p>
+ Some basic name visibility manipulations are allowed at the local scope where
+ the assertions are being declared in case they are ever needed to simplify
+ the assertion expressions. Therefore, using-directives and namespace-aliases
+ are allowed where assertions are declaraed (this will affect all assertion
+ in the specific declaration scope). Note that these name visibility manipulations
+ have no effect on the program run-time state and therefore they do not compromise
+ the assertion constant-correctness requirement.
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>expr-assertion:</em></span>
+ <span class="emphasis"><em>bool-expr |</em></span> <span class="identifier">static_assert</span><span class="special">(</span><span class="bold"><strong>static-bool-expr</strong></span><span class="special">,</span> <span class="bold"><strong>string-literal</strong></span><span class="special">)</span>
+ <span class="emphasis"><em>[</em></span><span class="special">,</span> <span class="identifier">importance</span> <span class="bold"><strong>natural-literal</strong></span><span class="emphasis"><em>]</em></span>
+
+<span class="emphasis"><em>select-assertion:</em></span>
+ <span class="keyword">if</span><span class="special">(</span><span class="emphasis"><em>bool-expr</em></span><span class="special">)</span> <span class="special">(</span> <span class="emphasis"><em>expr-assertion</em></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="emphasis"><em>[</em></span><span class="keyword">else</span> <span class="special">(</span> <span class="emphasis"><em>expr-assertion</em></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span><span class="emphasis"><em>]</em></span>
+</pre>
+<p>
+ Note that select-assertions cannot be nested into one another. Furthermore,
+ it is not possible to specify importance ordering for the entire select-assertion
+ if-then-else expression. Eventual importance ordering must be specified for
+ the single assertions within the select-assertion if-then-else expression.
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>bool-epxr:</em></span>
+ <span class="bold"><strong>runtime-bool-expr</strong></span> <span class="emphasis"><em>|</em></span> <span class="keyword">const</span><span class="special">(</span> <span class="emphasis"><em>[type]</em></span> <span class="bold"><strong>inscope-var</strong></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span> <span class="bold"><strong>const-bool-expr</strong></span>
+</pre>
+<p>
+ Constant-expressions <code class="computeroutput"><span class="keyword">const</span><span class="special">(</span>
+ <span class="special">...</span> <span class="special">)</span> </code><span class="bold"><strong><code class="literal">const-bool-expr</code></strong></span> can be used to
+ assert conditions and to check the select-assertion if-condition so to fully
+ enforce the assertion constant-correctness requirement. However, function
+ arguments, result value, old-of values, and the object <code class="computeroutput"><span class="keyword">this</span></code>
+ are automatically made <code class="computeroutput"><span class="keyword">const</span></code>
+ by this library so explicit constant-expressions only need to be used to
+ assert conditions on global variables, etc. The type of the in-scope variable
+ <span class="bold"><strong><code class="literal">inscope_var</code></strong></span> to access
+ as <code class="computeroutput"><span class="keyword">const</span></code> is optional and it
+ is automatically deduced using Boost.Tyepof when it is not specified.
+ </p>
+<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>
+ Alternatively, assertions could be programmed as follow:
+ </p>
+<pre class="programlisting">postcondition(
+ var(auto result = return)
+ var(auto old_size = CONTRACT_OLDOF size())
+ assert(size() == old_size + 1)
+ const_assert(x, y, x == y)
+ static_assert(sizeof(T) &lt; sizeof(int), "size")
+ if(const(x, y, x == y)) (
+ ...
+ ) else (
+ ...
+ )
+)
+</pre>
+<p>
+ An advantage of this syntax is that is does not require variadic commas
+ <code class="computeroutput"><span class="special">,</span></code> or sequencing parenthesis
+ <code class="computeroutput"><span class="special">()</span></code> to separate the assertions.
+ However, this syntax is overall more verbose, it uses more parenthesis,
+ it deviates more from <a class="link" href="bibliography.html" title="Bibliography">[N1962]</a>
+ (and Eiffel) that just list boolean expressions, and it looks less readable
+ because of <code class="computeroutput"><span class="identifier">var</span><span class="special">(...)</span></code>
+ when compared to the syntax adopted by this library.
+ </p>
+</td></tr>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.loop_variants"></a><a class="link" href="grammar.html#contract__.grammar.loop_variants" title="Loop Variants">Loop Variants</a>
+</h3></div></div></div>
+<p>
+ A loop variant must be a non-negative integral expression that monotonically
+ decreases at each subsequent loop iteration.
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>loop-variant:</em></span>
+ <span class="bold"><strong>natural-expr</strong></span> <span class="emphasis"><em>|</em></span> <span class="keyword">const</span><span class="special">(</span> <span class="emphasis"><em>[type]</em></span> <span class="bold"><strong>inscope-var</strong></span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span> <span class="bold"><strong>const-natural-expr</strong></span>
+ <span class="emphasis"><em>[</em></span><span class="special">,</span> <span class="identifier">importance</span> <span class="bold"><strong>natural-literal</strong></span><span class="emphasis"><em>]</em></span>
+</pre>
+<p>
+ The loop variant can be specified using a constant-expression <code class="computeroutput"><span class="keyword">const</span><span class="special">(</span> <span class="special">...</span>
+ <span class="special">)</span> </code><span class="bold"><strong><code class="literal">const-natural-expr</code></strong></span>
+ so to fully enforce the assertion constant-correctness requirement.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.grammar.terminals"></a><a class="link" href="grammar.html#contract__.grammar.terminals" title="Terminals">Terminals</a>
+</h3></div></div></div>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ Terminal
+ </p>
+ </th>
+<th>
+ <p>
+ Description
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">loop-decl</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A loop declaration: <code class="computeroutput"><span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span>
+ <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">i</span> <span class="special">&lt;</span>
+ <span class="number">10</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span></code>, <code class="computeroutput"><span class="keyword">while</span><span class="special">(</span><span class="identifier">i</span>
+ <span class="special">&lt;</span> <span class="number">10</span><span class="special">)</span></code>, etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">class-type</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The class type. For class templates this must include the template
+ instantiation parameters: <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Alloc</span><span class="special">&gt;</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">class-name</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The class name. For class templates this must not include the template
+ instantiation parameters: <code class="computeroutput"><span class="identifier">vector</span></code>.
+ (For non-template classes, the class type and name are the same.)
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">boost-concept</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A concept type defined accordingly to Boost.Concept: <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">InputIterator</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">template-specialization-type</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The type of a template specialization: <code class="computeroutput"><span class="keyword">void</span>
+ <span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">T</span><span class="special">)</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">type-name</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The name of type parameter: <code class="computeroutput"><span class="identifier">T</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">default-type</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A default parameter type: <code class="computeroutput"><span class="keyword">int</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">value-name</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The name of a value parameter: <code class="computeroutput"><span class="identifier">x</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">default-value</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A default parameter value: <code class="computeroutput"><span class="number">10</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">type</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A type: <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">int</span> <span class="keyword">const</span><span class="special">&amp;</span></code>, <code class="computeroutput"><span class="identifier">mytype</span></code>,
+ etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">base-type</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A base class type: <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">member-initializer</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A member initialization expression: <code class="computeroutput"><span class="identifier">vector_</span><span class="special">(</span><span class="identifier">count</span><span class="special">)</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">function-name</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A function name: <code class="computeroutput"><span class="identifier">f</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">operator-symbol</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ An operator symbolic name: <code class="computeroutput"><span class="special">[]</span></code>,
+ <code class="computeroutput"><span class="special">+</span></code>, etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">operator-arbitrary-name</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ An arbitrary name that does not contain any non-alphanumeric symbol:
+ <code class="computeroutput"><span class="identifier">at</span></code>, <code class="computeroutput"><span class="identifier">plus</span></code>, etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">exception-type</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The type of an exception: <code class="computeroutput"><span class="keyword">int</span></code>,
+ <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>, etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">var-name</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The name of a variable being declared: <code class="computeroutput"><span class="identifier">result</span></code>,
+ <code class="computeroutput"><span class="identifier">old_size</span></code>, etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">oldof-expr</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The expression of an old-of declaration: <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>, <code class="computeroutput"><span class="identifier">x</span>
+ <span class="special">+</span> <span class="number">10</span></code>,
+ etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">using-directive</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A using directive: <code class="computeroutput"><span class="keyword">namespace</span>
+ <span class="identifier">std</span></code>, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code>,
+ etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">namespace-alias</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A namespace alias: <code class="computeroutput"><span class="identifier">mpl</span>
+ <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">static-bool-expr</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A static boolean expression that can be evaluated at compile-time:
+ <code class="computeroutput"><span class="number">1</span> <span class="special">==</span>
+ <span class="number">2</span></code>, <code class="computeroutput"><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">&gt;=</span>
+ <span class="keyword">sizeof</span><span class="special">(</span><span class="keyword">int</span><span class="special">)</span></code>,
+ etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">runtime-bool-expr</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A boolean expression that can be evaluated at run-time: <code class="computeroutput"><span class="identifier">x</span> <span class="special">==</span>
+ <span class="identifier">y</span></code>, <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span>
+ <span class="identifier">old_size</span> <span class="special">+</span>
+ <span class="number">1</span></code>, etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">const-bool-expr</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A boolean expression that can be evaluated at run-time but only
+ using some specified variables in constant-correct context: <code class="computeroutput"><span class="identifier">x</span> <span class="special">==</span>
+ <span class="identifier">y</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">inscope-var</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ The name of a variable visible from the current scope: <code class="computeroutput"><span class="identifier">x</span></code>, <code class="computeroutput"><span class="identifier">y</span></code>,
+ etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">natural-expr</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A expression that evaluates at run-time to a non-negative integer
+ number: <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span>
+ <span class="special">-</span> <span class="identifier">i</span></code>,
+ <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span>
+ <span class="identifier">y</span><span class="special">)</span></code>,
+ etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">const-natural-expr</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A expression that evaluates at run-time to a non-negative integer
+ number but inly using some specified variables in constant-correct
+ context: <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span>
+ <span class="special">-</span> <span class="identifier">i</span></code>,
+ <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span>
+ <span class="identifier">y</span><span class="special">)</span></code>,
+ etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">string-literal</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A string token: <code class="computeroutput"><span class="string">"abc"</span></code>,
+ <code class="computeroutput"><span class="string">"invalid size"</span></code>,
+ etc.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="bold"><strong><code class="literal">natural-literal</code></strong></span>
+ </p>
+ </td>
+<td>
+ <p>
+ A non-negative integer token: <code class="computeroutput"><span class="number">0</span></code>,
+ <code class="computeroutput"><span class="number">1</span></code>, <code class="computeroutput"><span class="number">123</span></code>...
+ </p>
+ </td>
+</tr>
+</tbody>
+</table></div>
+</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 &#169; 2008-2012 Lorenzo Caminiti<p>
+ Use, modification, and distribution is subject to the Boost Software License,
+ Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
+ Documentation at http://contractpp.sourceforge.net.
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="examples.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="bibliography.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/contract/libs/contract/doc/html2/contract__/release_notes.html
==============================================================================
--- (empty file)
+++ sandbox/contract/libs/contract/doc/html2/contract__/release_notes.html 2011-09-04 13:37:15 EDT (Sun, 04 Sep 2011)
@@ -0,0 +1,76 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Release Notes</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Contract++ 0.4.x">
+<link rel="up" href="../index.html" title="Contract++ 0.4.x">
+<link rel="prev" href="bibliography.html" title="Bibliography">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="bibliography.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="contract__.release_notes"></a><a class="link" href="release_notes.html" title="Release Notes">Release Notes</a>
+</h2></div></div></div>
+<div class="toc"><dl><dt><span class="section">To-Do</span></dt></dl></div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.release_notes.to_do"></a><a class="link" href="release_notes.html#contract__.release_notes.to_do" title="To-Do">To-Do</a>
+</h3></div></div></div>
+<p>
+ Remaining open items:
+ </p>
+<div class="orderedlist"><ol class="orderedlist" type="1">
+<li class="listitem">
+ Include all necessary headers for all files.
+ </li>
+<li class="listitem">
+ Program concept checking for functions (not just class).
+ </li>
+<li class="listitem">
+ Fix static member function contract (see some examples that fails).
+ </li>
+<li class="listitem">
+ Implement named parameters.
+ </li>
+<li class="listitem">
+ Allows const( [(type_)] var, ... ) with optional (type_) for const assertions,
+ select-assertion if-conditions, and loop variants.
+ </li>
+<li class="listitem">
+ Add support for exception spec.
+ </li>
+<li class="listitem">
+ Replace all PP_NOT with PP_COMPL when no bool conversion is needed.
+ </li>
+</ol></div>
+</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 &#169; 2008-2012 Lorenzo Caminiti<p>
+ Use, modification, and distribution is subject to the Boost Software License,
+ Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
+ Documentation at http://contractpp.sourceforge.net.
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="bibliography.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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>
+</div>
+</body>
+</html>

Added: sandbox/contract/libs/contract/doc/html2/index.html
==============================================================================
--- (empty file)
+++ sandbox/contract/libs/contract/doc/html2/index.html 2011-09-04 13:37:15 EDT (Sun, 04 Sep 2011)
@@ -0,0 +1,64 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Contract++ 0.4.x</title>
+<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="index.html" title="Contract++ 0.4.x">
+<link rel="next" href="contract__/examples.html" title="Appendix: Examples">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav"><a accesskey="n" href="contract__/examples.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
+<div class="preface">
+<div class="titlepage"><div>
+<div><h2 class="title">
+<a name="contract__"></a>Contract++ 0.4.x </h2></div>
+<div><div class="authorgroup"><div class="author"><h3 class="author">
+<span class="firstname">Lorenzo</span> <span class="surname">Caminiti</span>
+</h3></div></div></div>
+<div><p class="copyright">Copyright &#169; 2008-2012 Lorenzo Caminiti</p></div>
+<div><div class="legalnotice">
+<a name="id808786"></a><p>
+ Use, modification, and distribution is subject to the Boost Software License,
+ Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
+ Documentation at http://contractpp.sourceforge.net.
+ </p>
+</div></div>
+</div></div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="section">Introduction</span></dt>
+<dt><span class="section">Appendix: Examples</span></dt>
+<dt><span class="section">Appendix: Grammar</span></dt>
+<dt><span class="section">Bibliography</span></dt>
+<dt><span class="section">Release Notes</span></dt>
+</dl>
+</div>
+<p>
+ The Contract++ library implements Contract Programming (a.k.a., Design by Contract,
+ DbC) for the C++ programming language. This library also supports virtual specifiers
+ (<code class="computeroutput"><span class="identifier">final</span></code>, <code class="computeroutput"><span class="keyword">virtual</span></code>,
+ and <code class="computeroutput"><span class="keyword">new</span></code>), concepts, and named parameters.
+ </p>
+<div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="contract__.Introduction"></a><a class="link" href="index.html#contract__.Introduction" title="Introduction">Introduction</a>
+</h2></div></div></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: September 04, 2011 at 17:34:44 GMT</small></p></td>
+<td align="right"><div class="copyright-footer"></div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav"><a accesskey="n" href="contract__/examples.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
+</body>
+</html>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk