Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75368 - in sandbox/contract/libs/contract/doc/html: . contract__
From: lorcaminiti_at_[hidden]
Date: 2011-11-06 21:22:26


Author: lcaminiti
Date: 2011-11-06 21:22:24 EST (Sun, 06 Nov 2011)
New Revision: 75368
URL: http://svn.boost.org/trac/boost/changeset/75368

Log:
Docs.
Added:
   sandbox/contract/libs/contract/doc/html/contract__/examples.html (contents, props changed)
Removed:
   sandbox/contract/libs/contract/doc/html/contract__/example.html
Text files modified:
   sandbox/contract/libs/contract/doc/html/index.html | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)

Deleted: sandbox/contract/libs/contract/doc/html/contract__/example.html
==============================================================================
--- sandbox/contract/libs/contract/doc/html/contract__/example.html 2011-11-06 21:22:24 EST (Sun, 06 Nov 2011)
+++ (empty file)
@@ -1,5105 +0,0 @@
-<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++ proposed 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_assertion_computational_complexity">[N1962]
- Factorial: Recursion and assertion computational complexity</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_and_comparison_with_d_syntax">[N1962]
- Square Root: Default parameters and comparison with D syntax</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++ proposed syntax</a></span></dt>
-<dt><span class="section"><a href="examples.html#contract__.examples.__cline90___stack__function_try_blocks_and_exception_specifications">[Cline90]
- Stack: Function-try-blocks and exception specifications</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___calendar__a_very_simple_calendar">[Cline90]
- Calendar: A very simple calendar</a></span></dt>
-<dt><span class="section"><a href="examples.html#contract__.examples.__contracts___increment__assertion_requirements_also_for_old_of">[Contracts]
- Increment: Assertion requirements also for old-of</a></span></dt>
-<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___depth_first_search__required_and_optional_named_parameters">[Named
- Parameters] Depth First Search: Required and optional named parameters</a></span></dt>
-<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___python__def___deduced_named_parameters">[Named
- Parameters] Python <code class="computeroutput"><span class="identifier">def</span></code>: Deduced
- named parameters</a></span></dt>
-<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___python__class___named_template_parameters">[Named
- Parameters] Python <code class="computeroutput"><span class="keyword">class</span></code>: Named
- template parameters</a></span></dt>
-<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___calls__member_functions_with_named_parameters">[Named
- Parameters] Calls: Member functions with named parameters</a></span></dt>
-<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___my_class__constructors_with_named_parameters">[Named
- Parameters] My Class: Constructors with named parameters</a></span></dt>
-<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___positive_number__fine_grained_parameter_name_control">[Named
- Parameters] Positive Number: Fine-grained parameter name control</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++ proposed 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++ proposed 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++ proposed syntax">[N1962] Vector: Comparison
- with C++ proposed 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">type_traits</span><span class="special">/</span><span class="identifier">has_equal_to</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">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="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// New vector interface (with contracts).</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">postcondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">empty</span><span class="special">()</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="special">)</span> <span class="comment">// Member initializers.</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">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="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="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">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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="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">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">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="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">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">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="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="special">)</span> <span class="special">{}</span>
-
- <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// With concept requirements.</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="identifier">postcondition</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">int</span><span class="special">(</span><span class="identifier">size</span><span class="special">())</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="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">postcondition</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">int</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="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="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">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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="special">)</span> <span class="special">{}</span>
-
- <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Operator symbol and (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">result</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span><span class="special">,</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">,</span>
- <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">,</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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 `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 (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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// Or, `not` 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="keyword">not</span> <span class="identifier">empty</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">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="keyword">not</span> <span class="identifier">empty</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">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">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="keyword">not</span> <span class="identifier">empty</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="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: Range [begin(), end()) contains [first, last).</span>
- <span class="identifier">postcondition</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">int</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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()) is invalid</span>
- <span class="comment">// else: [pos, end()) is 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">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">prior</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">prior</span><span class="special">(</span><span class="identifier">old_pos</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span>
- <span class="comment">// Range [pos, end()) is invalid.</span>
- <span class="special">)</span> <span class="comment">// Else, range [begin(), end()) is 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">// Range [first, last) is not contained in [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="keyword">not</span> <span class="identifier">empty</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">// Range [post, end()) is 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">// Range [first, last) is 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">right</span> <span class="special">==</span> <span class="identifier">old_self</span><span class="special">,</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==</span> <span class="special">(</span> <span class="identifier">vector</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">left</span><span class="special">,</span> <span class="identifier">vector</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">right</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">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">private</span><span class="special">:</span>
- <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Contract helper.</span>
- <span class="keyword">private</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="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">static</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">!=</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">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>
-</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="comment">// For simplicity, assume EqualityComparable&lt;T&gt; and all_equal defined.</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="identifier">postcondition</span> <span class="special">{</span> <span class="keyword">not</span> <span class="identifier">empty</span><span class="special">();</span> <span class="special">}</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">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="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="identifier">vect_</span><span class="special">(</span><span class="identifier">al</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="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="identifier">vect_</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">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="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="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="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="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="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="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="identifier">postcondition</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">int</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">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">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="identifier">postcondition</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">int</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="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="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="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">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="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="keyword">not</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">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="keyword">not</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">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="keyword">not</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">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="keyword">not</span> <span class="identifier">empty</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">precondition</span> <span class="special">{</span>
-
- <span class="comment">// Range [first, last) is not contained in [begin(), end()).</span>
- <span class="special">}</span>
- <span class="identifier">postcondition</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">int</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="keyword">if</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="comment">// Range [begin(), end()) is invalid.</span>
- <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
- <span class="comment">// Range [pos, end()) is 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="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="comment">// Range [pos, end()) is invalid.</span>
- <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
- <span class="comment">// Range [begin(), end()) is 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="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="comment">// Range [first, last) is not contained in [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="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="keyword">not</span> <span class="identifier">empty</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="comment">// Range [pos, end()) is invalid.</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="comment">// Range [first, last) is invalid.</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">right</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="special">*</span><span class="keyword">this</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="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>
-</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_assertion_computational_complexity"></a><a class="link" href="examples.html#contract__.examples.__n1962___factorial__recursion_and_assertion_computational_complexity" title="[N1962] Factorial: Recursion and assertion computational complexity">[N1962]
- Factorial: Recursion and assertion computational complexity</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 requirements 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="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="preprocessor">#define</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="identifier">O_1</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 requirements are used</span>
- <span class="comment">// to 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">requires</span> <span class="identifier">O_FACTN</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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_and_comparison_with_d_syntax"></a><a class="link" href="examples.html#contract__.examples.__n1962___square_root__default_parameters_and_comparison_with_d_syntax" title="[N1962] Square Root: Default parameters and comparison with D syntax">[N1962]
- Square Root: Default parameters and comparison with D syntax</a>
-</h3></div></div></div>
-<div class="informaltable"><table class="table">
-<colgroup>
-<col>
-<col>
-</colgroup>
-<thead><tr>
-<th>
- <p>
- C++03 (this library)
- </p>
- </th>
-<th>
- <p>
- D (__D__)
- </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">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>
- </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="identifier">real</span> <span class="identifier">mysqrt</span> <span class="special">(</span> <span class="identifier">real</span> <span class="identifier">x</span> <span class="special">)</span> <span class="comment">// No default parameters in D.</span>
- <span class="identifier">in</span> <span class="special">{</span> <span class="identifier">assert</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="special">}</span>
- <span class="identifier">out</span><span class="special">(</span><span class="identifier">root</span><span class="special">)</span> <span class="special">{</span>
-
- <span class="identifier">assert</span><span class="special">(</span> <span class="identifier">std</span><span class="special">.</span><span class="identifier">math</span><span class="special">.</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="number">1e6</span> <span class="special">);</span>
- <span class="special">}</span>
-<span class="identifier">body</span> <span class="special">{</span>
- <span class="keyword">return</span> <span class="identifier">std</span><span class="special">.</span><span class="identifier">math</span><span class="special">.</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>
- </td>
-</tr></tbody>
-</table></div>
-</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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="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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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_TPL</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_TPL</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_TPL</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">// Range [i, i + n] is 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="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">());</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="comment">// Equality needed to find value.</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="comment">// Precondition: Range [first, last) is valid.</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_TPL</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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 assertion requirements 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">// constant computational complexity O(1)</span>
-<span class="preprocessor">#define</span> <span class="identifier">O_BODY</span> <span class="number">10</span> <span class="comment">// same computation complexity of the body</span>
-<span class="preprocessor">#define</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="identifier">O_1</span> <span class="comment">// only check assertions with complexity within O(1)</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="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">requires</span> <span class="identifier">O_BODY</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="special">&amp;&amp;</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;::</span><span class="identifier">value</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;::</span><span class="identifier">value</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_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">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="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">requires</span> <span class="identifier">O_BODY</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="special">&amp;&amp;</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;::</span><span class="identifier">value</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;::</span><span class="identifier">value</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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_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">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="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="comment">// Precondition: Range [first, last) is valid.</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">&gt;::</span><span class="identifier">value</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_TPL</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="comment">// Support up to 5 function parameters (must #define before any #include).</span>
-<span class="preprocessor">#define</span> <span class="identifier">CONTRACT_CONFIG_FUNCTION_ARITY_MAX</span> <span class="number">6</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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="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="comment">// Precondition: Range [first1, last1) is valid.</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">OutIter</span><span class="special">&gt;::</span><span class="identifier">value</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: Range [first, last) is valid.</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_TPL</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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="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: Iterator 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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</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="identifier">value</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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="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="special">,</span>
- <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</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="keyword">not</span> <span class="identifier">full</span><span class="special">()</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="keyword">not</span> <span class="identifier">empty</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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</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="keyword">not</span> <span class="identifier">full</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">postcondition</span><span class="special">(</span>
- <span class="keyword">bool</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="keyword">bool</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="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="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">not</span> <span class="identifier">old_full</span> <span class="special">==</span> <span class="keyword">not</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">not</span> <span class="identifier">error</span><span class="special">())</span> <span class="special">(</span>
- <span class="keyword">not</span> <span class="identifier">empty</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">not</span> <span class="identifier">old_empty</span> <span class="special">==</span> <span class="keyword">not</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">not</span> <span class="identifier">error</span><span class="special">())</span> <span class="special">(</span>
- <span class="keyword">not</span> <span class="identifier">full</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="keyword">not</span> <span class="identifier">result</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="keyword">not</span> <span class="identifier">has</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</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="keyword">not</span> <span class="identifier">old_has_name</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_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">relaxed_name_list</span><span class="special">,</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="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="keyword">not</span> <span class="identifier">result</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="keyword">not</span> <span class="identifier">has</span><span class="special">(</span><span class="identifier">key</span><span class="special">)</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="keyword">double</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">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="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="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="keyword">double</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">// Assertion requirements 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="preprocessor">#define</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="identifier">O_1</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="keyword">not</span> <span class="identifier">is_empty</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="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="keyword">not</span> <span class="identifier">is_empty</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 decreased</span>
- <span class="comment">// Expensive assertion to check so marked with its complexity.</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">requires</span> <span class="identifier">O_N</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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 with its complexity</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">requires</span> <span class="identifier">O_N</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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">// Contract helpers.</span>
-
- <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
- <span class="keyword">private</span> <span class="keyword">static</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="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="keyword">not</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="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">// Assertion requirements 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="preprocessor">#define</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="identifier">O_1</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="comment">// observes valid</span>
- <span class="identifier">requires</span> <span class="identifier">O_N</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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="keyword">not</span> <span class="identifier">attached</span><span class="special">(</span><span class="identifier">obs</span><span class="special">)</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="comment">// others not changed (frame rule)</span>
- <span class="identifier">requires</span> <span class="identifier">O_N</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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="keyword">const</span><span class="special">(</span> <span class="identifier">i</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="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
- <span class="keyword">private</span> <span class="keyword">static</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="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">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="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="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="keyword">not</span> <span class="identifier">enabled</span><span class="special">()</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">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="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="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">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="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="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++ proposed syntax">[Cline90] Vector:
- Comparison with A++ proposed 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">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="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="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="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___stack__function_try_blocks_and_exception_specifications"></a><a class="link" href="examples.html#contract__.examples.__cline90___stack__function_try_blocks_and_exception_specifications" title="[Cline90] Stack: Function-try-blocks and exception specifications">[Cline90]
- Stack: Function-try-blocks and exception specifications</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">exception</span><span class="special">&gt;</span>
-<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="keyword">new</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="keyword">struct</span> <span class="identifier">out_of_memory</span> <span class="special">{};</span>
- <span class="keyword">struct</span> <span class="identifier">error</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">capacity</span> <span class="special">)</span>
- <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">capacity</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">capacity</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span>
- <span class="special">)</span>
- <span class="comment">// Function-try-blocks are programmed within the macros only for</span>
- <span class="comment">// constructors with member initializers otherwise they are programmed</span>
- <span class="comment">// with the body definition and outside the macros.</span>
- <span class="keyword">try</span> <span class="identifier">initialize</span><span class="special">(</span> <span class="comment">// Try-block for both constructor initializers and body.</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">capacity</span><span class="special">]),</span>
- <span class="identifier">capacity_</span><span class="special">(</span><span class="identifier">capacity</span><span class="special">),</span>
- <span class="identifier">size_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span>
- <span class="special">)</span> <span class="keyword">catch</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_alloc</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">(</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"out of memory for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack: "</span> <span class="special">&lt;&lt;</span>
- <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</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="keyword">throw</span> <span class="identifier">out_of_memory</span><span class="special">();</span>
- <span class="special">)</span> <span class="keyword">catch</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">(</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"error for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</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="keyword">throw</span><span class="special">;</span> <span class="comment">// Re-throw STL exception.</span>
- <span class="special">)</span> <span class="keyword">catch</span><span class="special">(...)</span> <span class="special">(</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"unknown error for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack"</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">throw</span> <span class="identifier">error</span><span class="special">();</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">capacity_</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">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="keyword">try</span> <span class="special">{</span> <span class="comment">// Function-try-block (outside the macro).</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">catch</span><span class="special">(...)</span> <span class="special">{</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"error for stack destruction, terminating"</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">terminate</span><span class="special">();</span> <span class="comment">// Destructor should never throw.</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">size_</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">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">size_</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="keyword">throw</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span><span class="special">,</span> <span class="identifier">error</span> <span class="special">)</span> <span class="comment">// Ex spec.</span>
- <span class="identifier">precondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">full</span><span class="special">()</span> <span class="special">)</span>
- <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
- <span class="special">)</span> <span class="keyword">try</span> <span class="special">{</span> <span class="comment">// Function-try-block (outside the macro).</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">value</span><span class="special">;</span>
- <span class="special">}</span> <span class="keyword">catch</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">{</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"error for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity_</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</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="keyword">throw</span><span class="special">;</span> <span class="comment">// Re-throw STL exception.</span>
- <span class="special">}</span> <span class="keyword">catch</span><span class="special">(...)</span> <span class="special">{</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"unknown error for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity_</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack"</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">throw</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="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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
- <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">full</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">size_</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">capacity_</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>
-</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="keyword">not</span> <span class="identifier">full</span><span class="special">()</span> <span class="special">)</span>
- <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">not</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="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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
- <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">full</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="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">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="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">length_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">)</span> <span class="comment">// OK, executed after precond.</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___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">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="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="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="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
- <span class="keyword">private</span> <span class="keyword">static</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="identifier">precondition</span><span class="special">(</span> <span class="identifier">month</span> <span class="special">&gt;=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">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="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="identifier">result</span> <span class="special">&lt;=</span> <span class="number">31</span> <span class="special">)</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 class="section">
-<div class="titlepage"><div><div><h3 class="title">
-<a name="contract__.examples.__contracts___increment__assertion_requirements_also_for_old_of"></a><a class="link" href="examples.html#contract__.examples.__contracts___increment__assertion_requirements_also_for_old_of" title="[Contracts] Increment: Assertion requirements also for old-of">[Contracts]
- Increment: Assertion requirements also for old-of</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_greater</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">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">iostream</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">PreIncrementable</span> <span class="special">{</span>
- <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">x</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">&amp;</span> <span class="special">);</span>
-<span class="keyword">public</span><span class="special">:</span>
- <span class="identifier">BOOST_CONCEPT_USAGE</span><span class="special">(</span><span class="identifier">PreIncrementable</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="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">PreIncrementable</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="identifier">T</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">inc</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</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">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
- <span class="comment">// skip this old-of copy if `has_oldof&lt;T&gt;::value` is false</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="comment">// skip this assertion if `has_oldof&lt;T&gt;::value` is false</span>
- <span class="identifier">value</span> <span class="special">&gt;</span> <span class="identifier">old_value</span><span class="special">,</span> <span class="comment">// also skip if T has no operator&gt;</span>
- <span class="identifier">requires</span> <span class="identifier">contract</span><span class="special">::</span><span class="identifier">has_oldof</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span> <span class="special">&amp;&amp;</span> <span class="comment">// need old-of</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_greater</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">,</span> <span class="comment">// need &gt;</span>
- <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">value</span><span class="special">,</span> <span class="comment">// skip this assertion if T has no operator==</span>
- <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span> <span class="comment">// need ==</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">value</span><span class="special">;</span>
-<span class="special">}</span>
-
-<span class="keyword">struct</span> <span class="identifier">counter</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="comment">// cannot copy (for some reason...)</span>
- <span class="identifier">counter</span> <span class="special">(</span> <span class="special">)</span> <span class="special">:</span> <span class="identifier">number_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">{}</span>
-
- <span class="identifier">counter</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">++</span> <span class="special">(</span> <span class="special">)</span> <span class="special">{</span> <span class="special">++</span><span class="identifier">number_</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">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">&gt;</span> <span class="special">(</span> <span class="identifier">counter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">left</span><span class="special">,</span> <span class="identifier">counter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">right</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">number_</span> <span class="special">&gt;</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">number_</span><span class="special">;</span> <span class="special">}</span>
-
- <span class="keyword">void</span> <span class="identifier">print</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">number_</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">private</span><span class="special">:</span>
- <span class="keyword">int</span> <span class="identifier">number_</span><span class="special">;</span>
-<span class="special">};</span>
-
-<span class="comment">// specialization disables old-of for non-copyable `counter` (no type trait can</span>
-<span class="comment">// be implemented in C++ to automatically and portably detect copy constructor)</span>
-<span class="keyword">namespace</span> <span class="identifier">contract</span> <span class="special">{</span>
- <span class="keyword">template</span><span class="special">&lt;&gt;</span> <span class="keyword">struct</span> <span class="identifier">has_oldof</span><span class="special">&lt;</span><span class="identifier">counter</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">false_</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="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</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">inc</span><span class="special">(</span><span class="identifier">i</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="comment">// check entire contract for `int` type</span>
-
- <span class="identifier">counter</span> <span class="identifier">c</span><span class="special">;</span>
- <span class="identifier">inc</span><span class="special">(</span><span class="identifier">c</span><span class="special">).</span><span class="identifier">print</span><span class="special">();</span> <span class="comment">// cannot copy `counter` so skip assertions with old-of</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.__named_parameters___depth_first_search__required_and_optional_named_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___depth_first_search__required_and_optional_named_parameters" title="[Named Parameters] Depth First Search: Required and optional named parameters">[Named
- Parameters] Depth First Search: Required and optional named 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">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity</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">graph</span><span class="special">/</span><span class="identifier">adjacency_list</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">graph</span><span class="special">/</span><span class="identifier">depth_first_search</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">graph</span><span class="special">/</span><span class="identifier">graph_traits</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">range</span><span class="special">/</span><span class="identifier">irange</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">pending</span><span class="special">/</span><span class="identifier">indirect_cmp</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">type_traits</span><span class="special">/</span><span class="identifier">is_convertible</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">type_traits</span><span class="special">/</span><span class="identifier">is_integral</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">type_traits</span><span class="special">/</span><span class="identifier">is_same</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="identifier">placeholders</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">and</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">namespace</span> <span class="identifier">graphs</span>
-<span class="special">{</span>
-
-<span class="comment">// Some helper graph metafunctions.</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_incidence_and_vertex_list_graph</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">and_</span><span class="special">&lt;</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</span><span class="special">&lt;</span>
- <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">traversal_category</span>
- <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">incidence_graph_tag</span>
- <span class="special">&gt;</span>
- <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</span><span class="special">&lt;</span>
- <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">traversal_category</span>
- <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">vertex_list_graph_tag</span>
- <span class="special">&gt;</span>
- <span class="special">&gt;</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">,</span> <span class="keyword">typename</span> <span class="identifier">Key</span> <span class="special">&gt;</span>
-<span class="keyword">struct</span> <span class="identifier">is_property_map_of_key</span> <span class="special">:</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span><span class="identifier">Key</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">property_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">key_type</span><span class="special">&gt;</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">,</span> <span class="keyword">typename</span> <span class="identifier">Key</span> <span class="special">&gt;</span>
-<span class="keyword">struct</span> <span class="identifier">is_integral_property_map_of_key</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">and_</span><span class="special">&lt;</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_integral</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">property_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span>
- <span class="special">,</span> <span class="identifier">is_property_map_of_key</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Key</span><span class="special">&gt;</span>
- <span class="special">&gt;</span>
-<span class="special">{};</span>
-
-<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">Size</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">IndexMap</span> <span class="special">&gt;</span>
-<span class="identifier">boost</span><span class="special">::</span><span class="identifier">iterator_property_map</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_color_type</span><span class="special">*,</span> <span class="identifier">IndexMap</span><span class="special">,</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_color_type</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_color_type</span><span class="special">&amp;&gt;</span>
-<span class="identifier">default_color_map</span> <span class="special">(</span> <span class="identifier">Size</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">num_vertices</span><span class="special">,</span> <span class="identifier">IndexMap</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">index_map</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">boost</span><span class="special">::</span><span class="identifier">default_color_type</span><span class="special">&gt;</span> <span class="identifier">colors</span><span class="special">(</span><span class="identifier">num_vertices</span><span class="special">);</span>
- <span class="keyword">return</span> <span class="special">&amp;</span><span class="identifier">colors</span><span class="special">[</span><span class="number">0</span><span class="special">];</span>
-<span class="special">}</span>
-
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">graph</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">visitor</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">root_vertex</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">index_map</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">color_map</span><span class="special">)</span>
-
-<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
-<span class="keyword">void</span> <span class="special">(</span><span class="identifier">depth_first_search</span><span class="special">)</span> <span class="special">(</span>
- <span class="comment">// Required named parameter (no default value) with type requirement.</span>
- <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">is_incidence_and_vertex_list_graph</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="identifier">_</span><span class="special">&gt;)</span> <span class="identifier">graph</span><span class="special">,</span>
- <span class="comment">// Optional named parameter (with default values) of any type (auto).</span>
- <span class="identifier">in</span> <span class="keyword">auto</span> <span class="identifier">visitor</span><span class="special">,</span> <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">dfs_visitor</span><span class="special">&lt;&gt;(),</span>
- <span class="comment">// Optional named parameter (default value) with specific type.</span>
- <span class="identifier">in</span> <span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">graph</span><span class="special">::</span><span class="identifier">_</span><span class="special">&gt;::</span>
- <span class="identifier">vertex_descriptor</span><span class="special">)</span> <span class="identifier">root_vertex</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="special">*</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">vertices</span><span class="special">(</span><span class="identifier">graph</span><span class="special">).</span><span class="identifier">first</span><span class="special">,</span>
- <span class="comment">// Optional named parameter (default value) with type requirement.</span>
- <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span>
- <span class="identifier">is_integral_property_map_of_key</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="identifier">_</span>
- <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">graph</span><span class="special">::</span><span class="identifier">_</span><span class="special">&gt;::</span>
- <span class="identifier">vertex_descriptor</span>
- <span class="special">&gt;)))</span> <span class="identifier">index_map</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">get</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">vertex_index</span><span class="special">,</span> <span class="identifier">graph</span><span class="special">),</span>
- <span class="comment">// Optional output named parameter (default value) with type req.</span>
- <span class="identifier">in</span> <span class="identifier">out</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span>
- <span class="identifier">is_property_map_of_key</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="identifier">_</span>
- <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">graph</span><span class="special">::</span><span class="identifier">_</span><span class="special">&gt;::</span>
- <span class="identifier">vertex_descriptor</span>
- <span class="special">&gt;)))</span> <span class="identifier">color_map</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="identifier">default_color_map</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">num_vertices</span><span class="special">(</span><span class="identifier">graph</span><span class="special">),</span> <span class="identifier">index_map</span><span class="special">)</span>
- <span class="special">)</span>
-<span class="special">)</span> <span class="special">{</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">depth_first_search</span><span class="special">(</span><span class="identifier">graph</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">visitor</span><span class="special">(</span><span class="identifier">visitor</span><span class="special">).</span>
- <span class="identifier">color_map</span><span class="special">(</span><span class="identifier">color_map</span><span class="special">).</span><span class="identifier">root_vertex</span><span class="special">(</span><span class="identifier">root_vertex</span><span class="special">).</span>
- <span class="identifier">vertex_index_map</span><span class="special">(</span><span class="identifier">index_map</span><span class="special">));</span>
-<span class="special">}</span>
-
-<span class="special">}</span> <span class="comment">// namespace graphs</span>
-
-<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">TimeMap</span> <span class="special">&gt;</span>
-<span class="keyword">class</span> <span class="identifier">dfs_time_visitor</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_dfs_visitor</span>
-<span class="special">{</span>
- <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">property_traits</span><span class="special">&lt;</span> <span class="identifier">TimeMap</span> <span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="identifier">T</span><span class="special">;</span>
-<span class="keyword">public</span><span class="special">:</span>
- <span class="identifier">dfs_time_visitor</span><span class="special">(</span><span class="identifier">TimeMap</span> <span class="identifier">dmap</span><span class="special">,</span> <span class="identifier">TimeMap</span> <span class="identifier">fmap</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">t</span><span class="special">)</span>
- <span class="special">:</span> <span class="identifier">dmap_</span><span class="special">(</span><span class="identifier">dmap</span><span class="special">),</span> <span class="identifier">fmap_</span><span class="special">(</span><span class="identifier">fmap</span><span class="special">),</span> <span class="identifier">time_</span><span class="special">(</span><span class="identifier">t</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">V</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">G</span> <span class="special">&gt;</span>
- <span class="keyword">void</span> <span class="identifier">discover_vertex</span> <span class="special">(</span> <span class="identifier">V</span> <span class="identifier">u</span><span class="special">,</span> <span class="identifier">G</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">g</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span> <span class="identifier">put</span><span class="special">(</span><span class="identifier">dmap_</span><span class="special">,</span> <span class="identifier">u</span><span class="special">,</span> <span class="identifier">time_</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">V</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">G</span> <span class="special">&gt;</span>
- <span class="keyword">void</span> <span class="identifier">finish_vertex</span> <span class="special">(</span> <span class="identifier">V</span> <span class="identifier">u</span><span class="special">,</span> <span class="identifier">G</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">g</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span> <span class="identifier">put</span><span class="special">(</span><span class="identifier">fmap_</span><span class="special">,</span> <span class="identifier">u</span><span class="special">,</span> <span class="identifier">time_</span><span class="special">++);</span> <span class="special">}</span>
-
- <span class="identifier">TimeMap</span> <span class="identifier">dmap_</span><span class="special">;</span>
- <span class="identifier">TimeMap</span> <span class="identifier">fmap_</span><span class="special">;</span>
- <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">time_</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="keyword">void</span> <span class="special">)</span>
-<span class="special">{</span>
- <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adjacency_list</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">vecS</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">vecS</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">directedS</span><span class="special">&gt;</span> <span class="identifier">G</span><span class="special">;</span>
- <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">G</span><span class="special">&gt;::</span><span class="identifier">vertices_size_type</span> <span class="identifier">size_type</span><span class="special">;</span>
-
- <span class="keyword">enum</span> <span class="special">{</span><span class="identifier">u</span><span class="special">,</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">w</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">z</span><span class="special">,</span> <span class="identifier">N</span><span class="special">};</span>
- <span class="keyword">char</span> <span class="identifier">names</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="char">'u'</span><span class="special">,</span> <span class="char">'v'</span><span class="special">,</span> <span class="char">'w'</span><span class="special">,</span> <span class="char">'x'</span><span class="special">,</span> <span class="char">'y'</span><span class="special">,</span> <span class="char">'z'</span><span class="special">};</span>
- <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">E</span><span class="special">;</span>
- <span class="identifier">E</span> <span class="identifier">edges</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="identifier">E</span><span class="special">(</span><span class="identifier">u</span><span class="special">,</span> <span class="identifier">v</span><span class="special">),</span> <span class="identifier">E</span><span class="special">(</span><span class="identifier">u</span><span class="special">,</span> <span class="identifier">x</span><span class="special">),</span> <span class="identifier">E</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">v</span><span class="special">),</span> <span class="identifier">E</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="identifier">E</span><span class="special">(</span><span class="identifier
">v</span><span class="special">,</span> <span class="identifier">y</span><span class="special">),</span> <span class="identifier">E</span><span class="special">(</span><span class="identifier">w</span><span class="special">,</span> <span class="identifier">y</span><span class="special">),</span> <span class="identifier">E</span><span class="special">(</span><span class="identifier">w</span><span class="special">,</span> <span class="identifier">z</span><span class="special">),</span>
- <span class="identifier">E</span><span class="special">(</span><span class="identifier">z</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)};</span>
- <span class="identifier">G</span> <span class="identifier">g</span><span class="special">(</span><span class="identifier">edges</span><span class="special">,</span> <span class="identifier">edges</span> <span class="special">+</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">edges</span><span class="special">)</span> <span class="special">/</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">E</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">vector</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="identifier">dtime</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">num_vertices</span><span class="special">(</span><span class="identifier">g</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">size_type</span><span class="special">&gt;</span> <span class="identifier">ftime</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">num_vertices</span><span class="special">(</span><span class="identifier">g</span><span class="special">));</span>
- <span class="identifier">size_type</span> <span class="identifier">t</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
- <span class="identifier">dfs_time_visitor</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">*&gt;</span> <span class="identifier">vis</span><span class="special">(&amp;</span><span class="identifier">dtime</span><span class="special">[</span><span class="number">0</span><span class="special">],</span> <span class="special">&amp;</span><span class="identifier">ftime</span><span class="special">[</span><span class="number">0</span><span class="special">],</span> <span class="identifier">t</span><span class="special">);</span>
-
- <span class="identifier">graphs</span><span class="special">::</span><span class="identifier">depth_first_search</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span> <span class="identifier">vis</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">size_type</span><span class="special">&gt;</span> <span class="identifier">dorder</span><span class="special">(</span><span class="identifier">N</span><span class="special">);</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">integer_range</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="identifier">r</span><span class="special">(</span><span class="number">0</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">copy</span><span class="special">(</span><span class="identifier">r</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">end</span><span class="special">(),</span> <span class="identifier">dorder</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">sort</span><span class="special">(</span><span class="identifier">dorder</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">dorder</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">indirect_cmp</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">*,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="special">&gt;(&amp;</span><span class="identifier">dtime</span><span class="special">[</span><span class="number">0</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">"order of discovery: "</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">N</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</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">names</span><span class="special">[</span><span class="identifier">dorder</span><span class="special">[</span><span class="identifier">i</span><span class="special">]]</span> <span class="special">&lt;&lt;</span> <span class="string">" "</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">;</span>
-
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="identifier">forder</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">copy</span><span class="special">(</span><span class="identifier">r</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">end</span><span class="special">(),</span> <span class="identifier">forder</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">sort</span><span class="special">(</span><span class="identifier">forder</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">forder</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">indirect_cmp</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">*,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="special">&gt;(&amp;</span><span class="identifier">ftime</span><span class="special">[</span><span class="number">0</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">"order of finish: "</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">N</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</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">names</span><span class="special">[</span><span class="identifier">forder</span><span class="special">[</span><span class="identifier">i</span><span class="special">]]</span> <span class="special">&lt;&lt;</span> <span class="string">" "</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">;</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.__named_parameters___python__def___deduced_named_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___python__def___deduced_named_parameters" title="[Named Parameters] Python def: Deduced named parameters">[Named
- Parameters] Python <code class="computeroutput"><span class="identifier">def</span></code>: Deduced
- named 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">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity</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">python</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">not</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">or</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="identifier">placeholders</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">type_traits</span><span class="special">/</span><span class="identifier">is_convertible</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
-
-<span class="keyword">namespace</span> <span class="identifier">py</span>
-<span class="special">{</span>
-
-<span class="comment">// For simplicity, trivial helper implementations.</span>
-<span class="keyword">bool</span> <span class="identifier">is_valid_identifier</span> <span class="special">(</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</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="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_keyword_expression</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_PARAMETER</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">func</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">docstring</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">keywords</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">policies</span><span class="special">)</span>
-
-<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
-<span class="keyword">void</span> <span class="special">(</span><span class="identifier">def</span><span class="special">)</span> <span class="special">(</span>
- <span class="comment">// Non-deduced and required named parameters.</span>
- <span class="identifier">in</span> <span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*)</span> <span class="identifier">name</span><span class="special">,</span> <span class="comment">// Specified type.</span>
- <span class="identifier">in</span> <span class="keyword">auto</span> <span class="identifier">func</span><span class="special">,</span> <span class="comment">// Any type (auto).</span>
- <span class="comment">// Deduced and optional (with default value) named parameters.</span>
- <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*)</span> <span class="identifier">docstring</span><span class="special">,</span> <span class="keyword">default</span> <span class="string">""</span><span class="special">,</span> <span class="comment">// Specified type.</span>
- <span class="comment">// Type requirements also used to uniquely deduce parameters.</span>
- <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">is_keyword_expression</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="identifier">_</span><span class="special">&gt;)</span> <span class="identifier">keywords</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">keyword_range</span><span class="special">(),</span>
- <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENITITY_TYPE</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">not_</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="identifier">or_</span><span class="special">&lt;</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</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="identifier">_</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;</span>
- <span class="special">,</span> <span class="identifier">is_keyword_expression</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="identifier">_</span><span class="special">&gt;</span>
- <span class="special">&gt;</span>
- <span class="special">&gt;)))</span> <span class="identifier">policies</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">default_call_policies</span><span class="special">()</span>
- <span class="special">)</span>
- <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">is_valid_identifier</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span> <span class="special">)</span> <span class="comment">// Also with contract.</span>
-<span class="special">)</span> <span class="special">{</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">func</span><span class="special">,</span> <span class="identifier">docstring</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">,</span> <span class="identifier">policies</span><span class="special">);</span>
-<span class="special">}</span>
-
-<span class="special">}</span> <span class="comment">// namespace py</span>
-
-<span class="keyword">void</span> <span class="identifier">f</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">main</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">some_policies</span> <span class="special">=</span> <span class="number">123</span><span class="special">;</span>
- <span class="identifier">py</span><span class="special">::</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">some_policies</span><span class="special">,</span> <span class="string">"Documentation for f"</span><span class="special">);</span>
- <span class="identifier">py</span><span class="special">::</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">f</span><span class="special">,</span> <span class="string">"Documentation for f"</span><span class="special">,</span> <span class="identifier">some_policies</span><span class="special">);</span>
-
- <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">other_policies</span> <span class="special">=</span> <span class="string">"abc"</span><span class="special">;</span>
- <span class="identifier">py</span><span class="special">::</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">_policies</span> <span class="special">=</span> <span class="identifier">other_policies</span><span class="special">,</span> <span class="string">"Documentation for f"</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.__named_parameters___python__class___named_template_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___python__class___named_template_parameters" title="[Named Parameters] Python class: Named template parameters">[Named
- Parameters] Python <code class="computeroutput"><span class="keyword">class</span></code>: Named
- template 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">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity</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">python</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">type_traits</span><span class="special">/</span><span class="identifier">is_class</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">type_traits</span><span class="special">/</span><span class="identifier">is_base_and_derived</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="identifier">assert</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="identifier">placeholders</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">not</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">and</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">noncopyable</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">shared_ptr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
-
-<span class="keyword">namespace</span> <span class="identifier">py</span>
-<span class="special">{</span>
-
-<span class="keyword">namespace</span> <span class="identifier">detail</span> <span class="special">{</span> <span class="keyword">struct</span> <span class="identifier">bases_tag</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">B0</span> <span class="special">=</span> <span class="keyword">void</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span> <span class="special">=</span> <span class="keyword">void</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B2</span> <span class="special">=</span> <span class="keyword">void</span> <span class="special">&gt;</span>
-<span class="keyword">struct</span> <span class="identifier">bases</span> <span class="special">:</span> <span class="identifier">detail</span><span class="special">::</span><span class="identifier">bases_tag</span> <span class="special">{};</span>
-
-<span class="identifier">CONTRACT_TEMPLATE_PARAMETER</span><span class="special">(</span><span class="identifier">ClassType</span><span class="special">)</span>
-<span class="identifier">CONTRACT_TEMPLATE_PARAMETER</span><span class="special">(</span><span class="identifier">BaseList</span><span class="special">)</span>
-<span class="identifier">CONTRACT_TEMPLATE_PARAMETER</span><span class="special">(</span><span class="identifier">HeldType</span><span class="special">)</span>
-<span class="identifier">CONTRACT_TEMPLATE_PARAMETER</span><span class="special">(</span><span class="identifier">Copyable</span><span class="special">)</span>
-
-<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
-<span class="keyword">template</span><span class="special">(</span>
- <span class="comment">// Required named template parameter with type requirement.</span>
- <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_class</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="identifier">_</span><span class="special">&gt;)</span> <span class="identifier">ClassType</span><span class="special">,</span>
- <span class="comment">// Deduced and optional named template parameters with type requirements.</span>
- <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_base_and_derived</span><span class="special">&lt;</span>
- <span class="identifier">detail</span><span class="special">::</span><span class="identifier">bases_tag</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">_</span><span class="special">&gt;)))</span> <span class="identifier">BaseList</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="identifier">bases</span><span class="special">&lt;&gt;,</span>
- <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</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">or_</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="identifier">or_</span><span class="special">&lt;</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_base_and_derived</span><span class="special">&lt;</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">bases_tag</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">_</span><span class="special">&gt;</span>
- <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</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">_</span><span class="special">&gt;</span>
- <span class="special">&gt;</span>
- <span class="special">&gt;)))</span> <span class="identifier">HeldType</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="identifier">ClassType</span><span class="special">,</span>
- <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</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">_</span><span class="special">&gt;)))</span> <span class="identifier">Copyable</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="keyword">void</span>
- <span class="comment">// NOTE: Named template params do not directly support non-type params.</span>
-<span class="special">)</span>
-<span class="keyword">class</span> <span class="special">(</span><span class="identifier">class_</span><span class="special">)</span>
- <span class="identifier">extends</span><span class="special">(</span>
- <span class="keyword">public</span> <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">ClassType</span><span class="special">,</span> <span class="identifier">BaseList</span><span class="special">,</span>
- <span class="identifier">HeldType</span><span class="special">,</span> <span class="identifier">Copyable</span><span class="special">&gt;))</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="keyword">typedef</span> <span class="identifier">ClassType</span> <span class="identifier">class_type</span><span class="special">;</span>
- <span class="keyword">typedef</span> <span class="identifier">BaseList</span> <span class="identifier">base_list</span><span class="special">;</span>
- <span class="keyword">typedef</span> <span class="identifier">HeldType</span> <span class="identifier">held_type</span><span class="special">;</span>
- <span class="keyword">typedef</span> <span class="identifier">Copyable</span> <span class="identifier">copyable</span><span class="special">;</span>
-<span class="special">};</span>
-
-<span class="special">}</span> <span class="comment">// namespace py</span>
-
-<span class="keyword">struct</span> <span class="identifier">b</span> <span class="special">{</span> <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">b</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">struct</span> <span class="identifier">d</span> <span class="special">:</span> <span class="identifier">b</span> <span class="special">{</span> <span class="special">~</span><span class="identifier">d</span><span class="special">()</span> <span class="special">{}</span> <span class="special">};</span>
-
-<span class="comment">// Named parameters.</span>
-<span class="keyword">typedef</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">_ClassType</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">_Copyable</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">x1</span><span class="special">;</span>
-<span class="keyword">typedef</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">d</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">_HeldType</span><span class="special">&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">d</span><span class="special">&gt;</span> <span class="special">&gt;,</span>
- <span class="identifier">py</span><span class="special">::</span><span class="identifier">BaseList</span><span class="special">&lt;</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">x2</span><span class="special">;</span>
-<span class="comment">// Deduced parameters.</span>
-<span class="keyword">typedef</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span> <span class="special">&gt;</span> <span class="identifier">y1</span><span class="special">;</span>
-<span class="keyword">typedef</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">d</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">d</span><span class="special">&gt;,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">y2</span><span class="special">;</span>
-
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x1</span><span class="special">::</span><span class="identifier">class_type</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x1</span><span class="special">::</span><span class="identifier">base_list</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x1</span><span class="special">::</span><span class="identifier">held_type</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x1</span><span class="special">::</span><span class="identifier">copyable</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span> <span class="special">&gt;</span> <span class="special">));</span>
-
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x2</span><span class="special">::</span><span class="identifier">class_type</span><span class="special">,</span> <span class="identifier">d</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x2</span><span class="special">::</span><span class="identifier">base_list</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x2</span><span class="special">::</span><span class="identifier">held_type</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">d</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x2</span><span class="special">::</span><span class="identifier">copyable</span><span class="special">,</span> <span class="keyword">void</span> <span class="special">&gt;</span> <span class="special">));</span>
-
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y1</span><span class="special">::</span><span class="identifier">class_type</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y1</span><span class="special">::</span><span class="identifier">base_list</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y1</span><span class="special">::</span><span class="identifier">held_type</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y1</span><span class="special">::</span><span class="identifier">copyable</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span> <span class="special">&gt;</span> <span class="special">));</span>
-
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y2</span><span class="special">::</span><span class="identifier">class_type</span><span class="special">,</span> <span class="identifier">d</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y2</span><span class="special">::</span><span class="identifier">base_list</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y2</span><span class="special">::</span><span class="identifier">held_type</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">d</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
-<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y2</span><span class="special">::</span><span class="identifier">copyable</span><span class="special">,</span> <span class="keyword">void</span> <span class="special">&gt;</span> <span class="special">));</span>
-
-<span class="keyword">int</span> <span class="identifier">main</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="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.__named_parameters___calls__member_functions_with_named_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___calls__member_functions_with_named_parameters" title="[Named Parameters] Calls: Member functions with named parameters">[Named
- Parameters] Calls: Member functions with named 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">iostream</span><span class="special">&gt;</span>
-
-<span class="keyword">namespace</span> <span class="identifier">calls</span>
-<span class="special">{</span>
-
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">arg2</span><span class="special">)</span>
-
-<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
-<span class="keyword">struct</span> <span class="special">(</span><span class="identifier">callable2</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="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Member function with named parameters.</span>
- <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">call</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg2</span> <span class="special">)</span>
- <span class="special">)</span> <span class="special">{</span>
- <span class="identifier">call_impl</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="string">""</span><span class="special">);</span>
- <span class="special">}</span>
-
- <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Constant member with named parameters.</span>
- <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">call</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg2</span> <span class="special">)</span> <span class="keyword">const</span>
- <span class="special">)</span> <span class="special">{</span>
- <span class="identifier">call_impl</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="string">"const"</span><span class="special">);</span>
- <span class="special">}</span>
-
- <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Static member with named parameters.</span>
- <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">scall</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg2</span> <span class="special">)</span>
- <span class="special">)</span> <span class="special">{</span>
- <span class="identifier">call_impl</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="string">"static"</span><span class="special">);</span>
- <span class="special">}</span>
-
-<span class="keyword">private</span><span class="special">:</span>
- <span class="comment">// NOTE: Function definition with named params cannot be directly separated.</span>
- <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">call_impl</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">qualifier</span> <span class="special">)</span> <span class="special">;</span>
-<span class="special">};</span>
-
-<span class="keyword">void</span> <span class="identifier">callable2</span><span class="special">::</span><span class="identifier">call_impl</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">what</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">arg1</span> <span class="special">&lt;&lt;</span> <span class="string">", "</span> <span class="special">&lt;&lt;</span> <span class="identifier">arg2</span> <span class="special">&lt;&lt;</span> <span class="string">" ("</span> <span class="special">&lt;&lt;</span> <span class="identifier">what</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="comment">// namespace calls</span>
-
-<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
-<span class="special">{</span>
- <span class="identifier">calls</span><span class="special">::</span><span class="identifier">callable2</span><span class="special">::</span><span class="identifier">scall</span><span class="special">(</span><span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg2</span> <span class="special">=</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg1</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
-
- <span class="identifier">calls</span><span class="special">::</span><span class="identifier">callable2</span> <span class="identifier">c</span><span class="special">;</span>
- <span class="identifier">c</span><span class="special">.</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg2</span> <span class="special">=</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg1</span> <span class="special">=</span> <span class="number">4</span><span class="special">);</span>
-
- <span class="identifier">calls</span><span class="special">::</span><span class="identifier">callable2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">cc</span> <span class="special">=</span> <span class="identifier">c</span><span class="special">;</span>
- <span class="identifier">cc</span><span class="special">.</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg2</span> <span class="special">=</span> <span class="number">5</span><span class="special">,</span> <span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg1</span> <span class="special">=</span> <span class="number">6</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.__named_parameters___my_class__constructors_with_named_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___my_class__constructors_with_named_parameters" title="[Named Parameters] My Class: Constructors with named parameters">[Named
- Parameters] My Class: Constructors with named 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">iostream</span><span class="special">&gt;</span>
-
-<span class="keyword">namespace</span> <span class="identifier">mine</span> <span class="special">{</span>
-
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">index</span><span class="special">)</span>
-
-<span class="comment">// NOTE: Constructors with named parameters need to be implement in bases.</span>
-<span class="keyword">struct</span> <span class="identifier">myclass_params</span>
-<span class="special">{</span>
- <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">Name</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Index</span> <span class="special">&gt;</span>
- <span class="identifier">myclass_params</span> <span class="special">(</span> <span class="identifier">Name</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Index</span> <span class="identifier">index</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">"name = "</span> <span class="special">&lt;&lt;</span> <span class="identifier">name</span> <span class="special">&lt;&lt;</span> <span class="string">"; index = "</span> <span class="special">&lt;&lt;</span> <span class="identifier">index</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="identifier">CONTRACT_CLASS</span><span class="special">(</span>
-<span class="keyword">struct</span> <span class="special">(</span><span class="identifier">myclass</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="identifier">myclass_params</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="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span>
- <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">myclass</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">in</span> <span class="keyword">auto</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">in</span> <span class="keyword">auto</span> <span class="identifier">index</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">42</span> <span class="special">)</span>
- <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">myclass_params</span><span class="special">(</span><span class="identifier">CONTRACT_CONSTRUCTOR_PARAMETERS</span><span class="special">)</span> <span class="special">)</span>
- <span class="comment">/** @todo are contracts still checked pre &gt; inv &gt; body &gt; post &gt; inv? */</span>
- <span class="comment">/* or pre &gt; body &gt; inv &gt; post &gt; inv which is incorrect! */</span>
- <span class="special">)</span> <span class="special">{}</span>
-<span class="special">};</span>
-
-<span class="special">}</span> <span class="comment">// namespace mine</span>
-
-<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
-<span class="special">{</span>
- <span class="identifier">mine</span><span class="special">::</span><span class="identifier">myclass</span> <span class="identifier">x</span><span class="special">(</span><span class="string">"bob"</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span>
- <span class="identifier">mine</span><span class="special">::</span><span class="identifier">myclass</span> <span class="identifier">y</span><span class="special">(</span><span class="identifier">mine</span><span class="special">::</span><span class="identifier">_index</span> <span class="special">=</span> <span class="number">12</span><span class="special">,</span> <span class="identifier">mine</span><span class="special">::</span><span class="identifier">_name</span> <span class="special">=</span> <span class="string">"sally"</span><span class="special">);</span>
- <span class="identifier">mine</span><span class="special">::</span><span class="identifier">myclass</span> <span class="identifier">z</span><span class="special">(</span><span class="string">"june"</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.__named_parameters___positive_number__fine_grained_parameter_name_control"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___positive_number__fine_grained_parameter_name_control" title="[Named Parameters] Positive Number: Fine-grained parameter name control">[Named
- Parameters] Positive Number: Fine-grained parameter name control</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">type_traits</span><span class="special">/</span><span class="identifier">has_equal_to</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="identifier">placeholders</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">int</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">long</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">char</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">namespace</span> <span class="identifier">num</span>
-<span class="special">{</span>
-
-<span class="keyword">namespace</span> <span class="identifier">tag</span> <span class="comment">// Namespace `tag` already used here, use `keywords` instead.</span>
-<span class="special">{</span>
- <span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">Value</span><span class="special">;</span> <span class="comment">// Dummy declarations...</span>
- <span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">Default</span><span class="special">;</span>
- <span class="identifier">Value</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">Default</span><span class="special">();</span>
-<span class="special">}</span>
-
-<span class="comment">// Also use `Param` and `_param` postfixes instead of `_` prefix.</span>
-<span class="identifier">CONTRACT_PARAMETER_TEMPLATE</span><span class="special">((</span><span class="identifier">ValueParam</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">)</span> <span class="identifier">Value</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER_TEMPLATE</span><span class="special">((</span><span class="identifier">DefaultParam</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">)</span> <span class="identifier">Default</span><span class="special">)</span>
-<span class="identifier">CONTRACT_PARAMETER</span><span class="special">((</span><span class="identifier">value_param</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">)</span> <span class="identifier">value</span><span class="special">)</span>
-
-<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
-<span class="keyword">template</span><span class="special">(</span>
- <span class="keyword">namespace</span> <span class="identifier">keywords</span><span class="special">,</span> <span class="comment">// Use namespace `keywords` instead of `tag`.</span>
- <span class="identifier">in</span> <span class="keyword">typename</span> <span class="identifier">Value</span><span class="special">,</span> <span class="keyword">default</span> <span class="keyword">int</span><span class="special">,</span>
- <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">is_same</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="identifier">_</span><span class="special">::</span><span class="identifier">type</span><span class="special">,</span> <span class="identifier">Value</span><span class="special">&gt;)</span> <span class="identifier">Default</span><span class="special">,</span>
- <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;</span>
-<span class="special">)</span>
-<span class="keyword">struct</span> <span class="special">(</span><span class="identifier">positive</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">static</span> <span class="keyword">class</span><span class="special">(</span> <span class="identifier">Default</span><span class="special">::</span><span class="identifier">value</span> <span class="special">&gt;</span> <span class="number">0</span> <span class="special">),</span>
- <span class="identifier">get</span><span class="special">()</span> <span class="special">&gt;</span> <span class="number">0</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">positive</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">value_</span><span class="special">(</span><span class="identifier">Default</span><span class="special">::</span><span class="identifier">value</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">void</span> <span class="special">(</span><span class="identifier">set</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">namespace</span> <span class="identifier">keywords</span><span class="special">,</span> <span class="identifier">in</span> <span class="special">(</span><span class="identifier">Value</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">value</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">get</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">value</span><span class="special">,</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_euql_to</span><span class="special">&lt;</span><span class="identifier">Value</span><span class="special">&gt;::</span><span class="identifier">value</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">value</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="identifier">Value</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">get</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="keyword">private</span><span class="special">:</span>
- <span class="identifier">Value</span> <span class="identifier">value_</span><span class="special">;</span>
-<span class="special">};</span>
-
-<span class="special">}</span> <span class="comment">// namespace num</span>
-
-<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="identifier">value</span> <span class="special">)</span>
-<span class="special">{</span>
- <span class="identifier">num</span><span class="special">::</span><span class="identifier">positive</span><span class="special">&lt;</span> <span class="keyword">char</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">char_</span><span class="special">&lt;</span><span class="char">'z'</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">p</span><span class="special">;</span>
- <span class="identifier">num</span><span class="special">::</span><span class="identifier">positive</span><span class="special">&lt;</span> <span class="special">&gt;</span> <span class="identifier">q</span><span class="special">;</span>
-
- <span class="comment">// Use `...Param` instead of `_...`.</span>
- <span class="identifier">num</span><span class="special">::</span><span class="identifier">positive</span><span class="special">&lt;</span> <span class="identifier">num</span><span class="special">::</span><span class="identifier">DefaultParam</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="identifier">int_</span><span class="special">&lt;</span><span class="number">10</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">r</span><span class="special">;</span>
- <span class="identifier">num</span><span class="special">::</span><span class="identifier">positive</span><span class="special">&lt;</span>
- <span class="identifier">num</span><span class="special">::</span><span class="identifier">DefaultParam</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="identifier">long_</span><span class="special">&lt;</span><span class="number">10</span><span class="special">&gt;</span> <span class="special">&gt;</span>
- <span class="special">,</span> <span class="identifier">num</span><span class="special">::</span><span class="identifier">ValueParam</span><span class="special">&lt;</span><span class="keyword">long</span><span class="special">&gt;</span>
- <span class="special">&gt;</span> <span class="identifier">s</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="identifier">get</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">s</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="identifier">num</span><span class="special">::</span><span class="identifier">value_param</span> <span class="special">=</span> <span class="number">123</span><span class="special">);</span> <span class="comment">// Use `..._param` instead of `_...`.</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="identifier">get</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="keyword">return</span> <span class="number">0</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/html/contract__/examples.html
==============================================================================
--- (empty file)
+++ sandbox/contract/libs/contract/doc/html/contract__/examples.html 2011-11-06 21:22:24 EST (Sun, 06 Nov 2011)
@@ -0,0 +1,5105 @@
+<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++ proposed 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_assertion_computational_complexity">[N1962]
+ Factorial: Recursion and assertion computational complexity</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_and_comparison_with_d_syntax">[N1962]
+ Square Root: Default parameters and comparison with D syntax</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++ proposed syntax</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__cline90___stack__function_try_blocks_and_exception_specifications">[Cline90]
+ Stack: Function-try-blocks and exception specifications</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___calendar__a_very_simple_calendar">[Cline90]
+ Calendar: A very simple calendar</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__contracts___increment__assertion_requirements_also_for_old_of">[Contracts]
+ Increment: Assertion requirements also for old-of</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___depth_first_search__required_and_optional_named_parameters">[Named
+ Parameters] Depth First Search: Required and optional named parameters</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___python__def___deduced_named_parameters">[Named
+ Parameters] Python <code class="computeroutput"><span class="identifier">def</span></code>: Deduced
+ named parameters</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___python__class___named_template_parameters">[Named
+ Parameters] Python <code class="computeroutput"><span class="keyword">class</span></code>: Named
+ template parameters</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___calls__member_functions_with_named_parameters">[Named
+ Parameters] Calls: Member functions with named parameters</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___my_class__constructors_with_named_parameters">[Named
+ Parameters] My Class: Constructors with named parameters</a></span></dt>
+<dt><span class="section"><a href="examples.html#contract__.examples.__named_parameters___positive_number__fine_grained_parameter_name_control">[Named
+ Parameters] Positive Number: Fine-grained parameter name control</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++ proposed 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++ proposed 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++ proposed syntax">[N1962] Vector: Comparison
+ with C++ proposed 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">type_traits</span><span class="special">/</span><span class="identifier">has_equal_to</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">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="identifier">CONTRACT_CLASS</span><span class="special">(</span> <span class="comment">// New vector interface (with contracts).</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">postcondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">empty</span><span class="special">()</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="special">)</span> <span class="comment">// Member initializers.</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">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="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="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">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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="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">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">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="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">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">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="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="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_CONSTRUCTOR_TPL</span><span class="special">(</span> <span class="comment">// With concept requirements.</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="identifier">postcondition</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">int</span><span class="special">(</span><span class="identifier">size</span><span class="special">())</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="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">postcondition</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">int</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="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="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">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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Operator symbol and (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">result</span> <span class="special">==</span> <span class="special">*</span><span class="keyword">this</span><span class="special">,</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">,</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">right</span><span class="special">,</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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 `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 (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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// Or, `not` 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="keyword">not</span> <span class="identifier">empty</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">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="keyword">not</span> <span class="identifier">empty</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">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">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="keyword">not</span> <span class="identifier">empty</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="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: Range [begin(), end()) contains [first, last).</span>
+ <span class="identifier">postcondition</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">int</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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()) is invalid</span>
+ <span class="comment">// else: [pos, end()) is 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">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">prior</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">prior</span><span class="special">(</span><span class="identifier">old_pos</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span>
+ <span class="comment">// Range [pos, end()) is invalid.</span>
+ <span class="special">)</span> <span class="comment">// Else, range [begin(), end()) is 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">// Range [first, last) is not contained in [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="keyword">not</span> <span class="identifier">empty</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">// Range [post, end()) is 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">// Range [first, last) is 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">right</span> <span class="special">==</span> <span class="identifier">old_self</span><span class="special">,</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_equal_to</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==</span> <span class="special">(</span> <span class="identifier">vector</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">left</span><span class="special">,</span> <span class="identifier">vector</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">right</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">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">private</span><span class="special">:</span>
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span> <span class="comment">// Contract helper.</span>
+ <span class="keyword">private</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="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">static</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">!=</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">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>
+</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="comment">// For simplicity, assume EqualityComparable&lt;T&gt; and all_equal defined.</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="identifier">postcondition</span> <span class="special">{</span> <span class="keyword">not</span> <span class="identifier">empty</span><span class="special">();</span> <span class="special">}</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">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="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="identifier">vect_</span><span class="special">(</span><span class="identifier">al</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="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="identifier">vect_</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">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="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="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="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="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="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="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="identifier">postcondition</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">int</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">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">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="identifier">postcondition</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">int</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="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="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="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">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="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="keyword">not</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">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="keyword">not</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">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="keyword">not</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">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="keyword">not</span> <span class="identifier">empty</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">precondition</span> <span class="special">{</span>
+
+ <span class="comment">// Range [first, last) is not contained in [begin(), end()).</span>
+ <span class="special">}</span>
+ <span class="identifier">postcondition</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">int</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="keyword">if</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="comment">// Range [begin(), end()) is invalid.</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+ <span class="comment">// Range [pos, end()) is 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="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="comment">// Range [pos, end()) is invalid.</span>
+ <span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+ <span class="comment">// Range [begin(), end()) is 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="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="comment">// Range [first, last) is not contained in [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="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="keyword">not</span> <span class="identifier">empty</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="comment">// Range [pos, end()) is invalid.</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="comment">// Range [first, last) is invalid.</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">right</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="special">*</span><span class="keyword">this</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="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>
+</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_assertion_computational_complexity"></a><a class="link" href="examples.html#contract__.examples.__n1962___factorial__recursion_and_assertion_computational_complexity" title="[N1962] Factorial: Recursion and assertion computational complexity">[N1962]
+ Factorial: Recursion and assertion computational complexity</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 requirements 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="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="preprocessor">#define</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="identifier">O_1</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 requirements are used</span>
+ <span class="comment">// to 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">requires</span> <span class="identifier">O_FACTN</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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_and_comparison_with_d_syntax"></a><a class="link" href="examples.html#contract__.examples.__n1962___square_root__default_parameters_and_comparison_with_d_syntax" title="[N1962] Square Root: Default parameters and comparison with D syntax">[N1962]
+ Square Root: Default parameters and comparison with D syntax</a>
+</h3></div></div></div>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ C++03 (this library)
+ </p>
+ </th>
+<th>
+ <p>
+ D (__D__)
+ </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">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>
+ </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="identifier">real</span> <span class="identifier">mysqrt</span> <span class="special">(</span> <span class="identifier">real</span> <span class="identifier">x</span> <span class="special">)</span> <span class="comment">// No default parameters in D.</span>
+ <span class="identifier">in</span> <span class="special">{</span> <span class="identifier">assert</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="special">}</span>
+ <span class="identifier">out</span><span class="special">(</span><span class="identifier">root</span><span class="special">)</span> <span class="special">{</span>
+
+ <span class="identifier">assert</span><span class="special">(</span> <span class="identifier">std</span><span class="special">.</span><span class="identifier">math</span><span class="special">.</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="number">1e6</span> <span class="special">);</span>
+ <span class="special">}</span>
+<span class="identifier">body</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">std</span><span class="special">.</span><span class="identifier">math</span><span class="special">.</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>
+ </td>
+</tr></tbody>
+</table></div>
+</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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="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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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_TPL</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_TPL</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_TPL</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">// Range [i, i + n] is 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="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">());</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="comment">// Equality needed to find value.</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="comment">// Precondition: Range [first, last) is valid.</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_TPL</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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 assertion requirements 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">// constant computational complexity O(1)</span>
+<span class="preprocessor">#define</span> <span class="identifier">O_BODY</span> <span class="number">10</span> <span class="comment">// same computation complexity of the body</span>
+<span class="preprocessor">#define</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="identifier">O_1</span> <span class="comment">// only check assertions with complexity within O(1)</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="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">requires</span> <span class="identifier">O_BODY</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="special">&amp;&amp;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;::</span><span class="identifier">value</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;::</span><span class="identifier">value</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_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">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="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">requires</span> <span class="identifier">O_BODY</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="special">&amp;&amp;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;::</span><span class="identifier">value</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Result</span><span class="special">&gt;::</span><span class="identifier">value</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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_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">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="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="comment">// Precondition: Range [first, last) is valid.</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">Func</span><span class="special">&gt;::</span><span class="identifier">value</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_TPL</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="comment">// Support up to 5 function parameters (must #define before any #include).</span>
+<span class="preprocessor">#define</span> <span class="identifier">CONTRACT_CONFIG_FUNCTION_ARITY_MAX</span> <span class="number">6</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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="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="comment">// Precondition: Range [first1, last1) is valid.</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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">OutIter</span><span class="special">&gt;::</span><span class="identifier">value</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: Range [first, last) is valid.</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_TPL</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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="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: Iterator 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="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</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="identifier">value</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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="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="special">,</span>
+ <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</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="keyword">not</span> <span class="identifier">full</span><span class="special">()</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="keyword">not</span> <span class="identifier">empty</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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</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="keyword">not</span> <span class="identifier">full</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">postcondition</span><span class="special">(</span>
+ <span class="keyword">bool</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="keyword">bool</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="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="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">not</span> <span class="identifier">old_full</span> <span class="special">==</span> <span class="keyword">not</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">not</span> <span class="identifier">error</span><span class="special">())</span> <span class="special">(</span>
+ <span class="keyword">not</span> <span class="identifier">empty</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">not</span> <span class="identifier">old_empty</span> <span class="special">==</span> <span class="keyword">not</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">not</span> <span class="identifier">error</span><span class="special">())</span> <span class="special">(</span>
+ <span class="keyword">not</span> <span class="identifier">full</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="keyword">not</span> <span class="identifier">result</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="keyword">not</span> <span class="identifier">has</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</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="keyword">not</span> <span class="identifier">old_has_name</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_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">relaxed_name_list</span><span class="special">,</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="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="keyword">not</span> <span class="identifier">result</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="keyword">not</span> <span class="identifier">has</span><span class="special">(</span><span class="identifier">key</span><span class="special">)</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="keyword">double</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">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="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="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="keyword">double</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">// Assertion requirements 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="preprocessor">#define</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="identifier">O_1</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="keyword">not</span> <span class="identifier">is_empty</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="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="keyword">not</span> <span class="identifier">is_empty</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 decreased</span>
+ <span class="comment">// Expensive assertion to check so marked with its complexity.</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">requires</span> <span class="identifier">O_N</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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 with its complexity</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">requires</span> <span class="identifier">O_N</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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">// Contract helpers.</span>
+
+ <span class="identifier">CONTRACT_FUNCTION_TPL</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">static</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="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="keyword">not</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="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">// Assertion requirements 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="preprocessor">#define</span> <span class="identifier">COMPLEXITY_MAX</span> <span class="identifier">O_1</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="comment">// observes valid</span>
+ <span class="identifier">requires</span> <span class="identifier">O_N</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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="keyword">not</span> <span class="identifier">attached</span><span class="special">(</span><span class="identifier">obs</span><span class="special">)</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="comment">// others not changed (frame rule)</span>
+ <span class="identifier">requires</span> <span class="identifier">O_N</span> <span class="special">&lt;=</span> <span class="identifier">COMPLEXITY_MAX</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="keyword">const</span><span class="special">(</span> <span class="identifier">i</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="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">static</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="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">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="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="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="keyword">not</span> <span class="identifier">enabled</span><span class="special">()</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">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="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="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">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="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="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++ proposed syntax">[Cline90] Vector:
+ Comparison with A++ proposed 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">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="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="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="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___stack__function_try_blocks_and_exception_specifications"></a><a class="link" href="examples.html#contract__.examples.__cline90___stack__function_try_blocks_and_exception_specifications" title="[Cline90] Stack: Function-try-blocks and exception specifications">[Cline90]
+ Stack: Function-try-blocks and exception specifications</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">exception</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="keyword">new</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="keyword">struct</span> <span class="identifier">out_of_memory</span> <span class="special">{};</span>
+ <span class="keyword">struct</span> <span class="identifier">error</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">capacity</span> <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">capacity</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">capacity</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span>
+ <span class="special">)</span>
+ <span class="comment">// Function-try-blocks are programmed within the macros only for</span>
+ <span class="comment">// constructors with member initializers otherwise they are programmed</span>
+ <span class="comment">// with the body definition and outside the macros.</span>
+ <span class="keyword">try</span> <span class="identifier">initialize</span><span class="special">(</span> <span class="comment">// Try-block for both constructor initializers and body.</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">capacity</span><span class="special">]),</span>
+ <span class="identifier">capacity_</span><span class="special">(</span><span class="identifier">capacity</span><span class="special">),</span>
+ <span class="identifier">size_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span>
+ <span class="special">)</span> <span class="keyword">catch</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_alloc</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"out of memory for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack: "</span> <span class="special">&lt;&lt;</span>
+ <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</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="keyword">throw</span> <span class="identifier">out_of_memory</span><span class="special">();</span>
+ <span class="special">)</span> <span class="keyword">catch</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"error for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</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="keyword">throw</span><span class="special">;</span> <span class="comment">// Re-throw STL exception.</span>
+ <span class="special">)</span> <span class="keyword">catch</span><span class="special">(...)</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"unknown error for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack"</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">throw</span> <span class="identifier">error</span><span class="special">();</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">capacity_</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">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="keyword">try</span> <span class="special">{</span> <span class="comment">// Function-try-block (outside the macro).</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">catch</span><span class="special">(...)</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"error for stack destruction, terminating"</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">terminate</span><span class="special">();</span> <span class="comment">// Destructor should never throw.</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">size_</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">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">size_</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="keyword">throw</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span><span class="special">,</span> <span class="identifier">error</span> <span class="special">)</span> <span class="comment">// Ex spec.</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">full</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="keyword">try</span> <span class="special">{</span> <span class="comment">// Function-try-block (outside the macro).</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">value</span><span class="special">;</span>
+ <span class="special">}</span> <span class="keyword">catch</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"error for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity_</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</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="keyword">throw</span><span class="special">;</span> <span class="comment">// Re-throw STL exception.</span>
+ <span class="special">}</span> <span class="keyword">catch</span><span class="special">(...)</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"unknown error for "</span> <span class="special">&lt;&lt;</span> <span class="identifier">capacity_</span> <span class="special">&lt;&lt;</span> <span class="string">"-stack"</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">throw</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="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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">full</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">size_</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">capacity_</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>
+</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="keyword">not</span> <span class="identifier">full</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">not</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="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="keyword">not</span> <span class="identifier">empty</span><span class="special">()</span> <span class="special">)</span>
+ <span class="identifier">postcondition</span><span class="special">(</span> <span class="keyword">not</span> <span class="identifier">full</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="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">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="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">length_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">)</span> <span class="comment">// OK, executed after precond.</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___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">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="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="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="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">private</span> <span class="keyword">static</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="identifier">precondition</span><span class="special">(</span> <span class="identifier">month</span> <span class="special">&gt;=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">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="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="identifier">result</span> <span class="special">&lt;=</span> <span class="number">31</span> <span class="special">)</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 class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="contract__.examples.__contracts___increment__assertion_requirements_also_for_old_of"></a><a class="link" href="examples.html#contract__.examples.__contracts___increment__assertion_requirements_also_for_old_of" title="[Contracts] Increment: Assertion requirements also for old-of">[Contracts]
+ Increment: Assertion requirements also for old-of</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_equal</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">type_traits</span><span class="special">/</span><span class="identifier">can_call_greater</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">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">iostream</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">PreIncrementable</span> <span class="special">{</span>
+ <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">x</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">&amp;</span> <span class="special">);</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">BOOST_CONCEPT_USAGE</span><span class="special">(</span><span class="identifier">PreIncrementable</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="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">PreIncrementable</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="identifier">T</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">inc</span><span class="special">)</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">T</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">result</span> <span class="special">=</span> <span class="keyword">return</span><span class="special">,</span>
+ <span class="comment">// skip this old-of copy if `has_oldof&lt;T&gt;::value` is false</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="comment">// skip this assertion if `has_oldof&lt;T&gt;::value` is false</span>
+ <span class="identifier">value</span> <span class="special">&gt;</span> <span class="identifier">old_value</span><span class="special">,</span> <span class="comment">// also skip if T has no operator&gt;</span>
+ <span class="identifier">requires</span> <span class="identifier">contract</span><span class="special">::</span><span class="identifier">has_oldof</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span> <span class="special">&amp;&amp;</span> <span class="comment">// need old-of</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_greater</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">,</span> <span class="comment">// need &gt;</span>
+ <span class="identifier">result</span> <span class="special">==</span> <span class="identifier">value</span><span class="special">,</span> <span class="comment">// skip this assertion if T has no operator==</span>
+ <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">can_call_equal</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span> <span class="comment">// need ==</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">value</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">struct</span> <span class="identifier">counter</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="comment">// cannot copy (for some reason...)</span>
+ <span class="identifier">counter</span> <span class="special">(</span> <span class="special">)</span> <span class="special">:</span> <span class="identifier">number_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">{}</span>
+
+ <span class="identifier">counter</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">++</span> <span class="special">(</span> <span class="special">)</span> <span class="special">{</span> <span class="special">++</span><span class="identifier">number_</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">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">&gt;</span> <span class="special">(</span> <span class="identifier">counter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">left</span><span class="special">,</span> <span class="identifier">counter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">right</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">number_</span> <span class="special">&gt;</span> <span class="identifier">right</span><span class="special">.</span><span class="identifier">number_</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">void</span> <span class="identifier">print</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">number_</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">private</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">number_</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="comment">// specialization disables old-of for non-copyable `counter` (no type trait can</span>
+<span class="comment">// be implemented in C++ to automatically and portably detect copy constructor)</span>
+<span class="keyword">namespace</span> <span class="identifier">contract</span> <span class="special">{</span>
+ <span class="keyword">template</span><span class="special">&lt;&gt;</span> <span class="keyword">struct</span> <span class="identifier">has_oldof</span><span class="special">&lt;</span><span class="identifier">counter</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">false_</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="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</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">inc</span><span class="special">(</span><span class="identifier">i</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="comment">// check entire contract for `int` type</span>
+
+ <span class="identifier">counter</span> <span class="identifier">c</span><span class="special">;</span>
+ <span class="identifier">inc</span><span class="special">(</span><span class="identifier">c</span><span class="special">).</span><span class="identifier">print</span><span class="special">();</span> <span class="comment">// cannot copy `counter` so skip assertions with old-of</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.__named_parameters___depth_first_search__required_and_optional_named_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___depth_first_search__required_and_optional_named_parameters" title="[Named Parameters] Depth First Search: Required and optional named parameters">[Named
+ Parameters] Depth First Search: Required and optional named 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">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity</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">graph</span><span class="special">/</span><span class="identifier">adjacency_list</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">graph</span><span class="special">/</span><span class="identifier">depth_first_search</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">graph</span><span class="special">/</span><span class="identifier">graph_traits</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">range</span><span class="special">/</span><span class="identifier">irange</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">pending</span><span class="special">/</span><span class="identifier">indirect_cmp</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">type_traits</span><span class="special">/</span><span class="identifier">is_convertible</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">type_traits</span><span class="special">/</span><span class="identifier">is_integral</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">type_traits</span><span class="special">/</span><span class="identifier">is_same</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="identifier">placeholders</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">and</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">namespace</span> <span class="identifier">graphs</span>
+<span class="special">{</span>
+
+<span class="comment">// Some helper graph metafunctions.</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_incidence_and_vertex_list_graph</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">and_</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</span><span class="special">&lt;</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">traversal_category</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">incidence_graph_tag</span>
+ <span class="special">&gt;</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</span><span class="special">&lt;</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">traversal_category</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">vertex_list_graph_tag</span>
+ <span class="special">&gt;</span>
+ <span class="special">&gt;</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">,</span> <span class="keyword">typename</span> <span class="identifier">Key</span> <span class="special">&gt;</span>
+<span class="keyword">struct</span> <span class="identifier">is_property_map_of_key</span> <span class="special">:</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span><span class="identifier">Key</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">property_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">key_type</span><span class="special">&gt;</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">,</span> <span class="keyword">typename</span> <span class="identifier">Key</span> <span class="special">&gt;</span>
+<span class="keyword">struct</span> <span class="identifier">is_integral_property_map_of_key</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">and_</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_integral</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">property_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span>
+ <span class="special">,</span> <span class="identifier">is_property_map_of_key</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Key</span><span class="special">&gt;</span>
+ <span class="special">&gt;</span>
+<span class="special">{};</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">Size</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">IndexMap</span> <span class="special">&gt;</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">iterator_property_map</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_color_type</span><span class="special">*,</span> <span class="identifier">IndexMap</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_color_type</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_color_type</span><span class="special">&amp;&gt;</span>
+<span class="identifier">default_color_map</span> <span class="special">(</span> <span class="identifier">Size</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">num_vertices</span><span class="special">,</span> <span class="identifier">IndexMap</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">index_map</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">boost</span><span class="special">::</span><span class="identifier">default_color_type</span><span class="special">&gt;</span> <span class="identifier">colors</span><span class="special">(</span><span class="identifier">num_vertices</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="special">&amp;</span><span class="identifier">colors</span><span class="special">[</span><span class="number">0</span><span class="special">];</span>
+<span class="special">}</span>
+
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">graph</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">visitor</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">root_vertex</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">index_map</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">color_map</span><span class="special">)</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">void</span> <span class="special">(</span><span class="identifier">depth_first_search</span><span class="special">)</span> <span class="special">(</span>
+ <span class="comment">// Required named parameter (no default value) with type requirement.</span>
+ <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">is_incidence_and_vertex_list_graph</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="identifier">_</span><span class="special">&gt;)</span> <span class="identifier">graph</span><span class="special">,</span>
+ <span class="comment">// Optional named parameter (with default values) of any type (auto).</span>
+ <span class="identifier">in</span> <span class="keyword">auto</span> <span class="identifier">visitor</span><span class="special">,</span> <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">dfs_visitor</span><span class="special">&lt;&gt;(),</span>
+ <span class="comment">// Optional named parameter (default value) with specific type.</span>
+ <span class="identifier">in</span> <span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">graph</span><span class="special">::</span><span class="identifier">_</span><span class="special">&gt;::</span>
+ <span class="identifier">vertex_descriptor</span><span class="special">)</span> <span class="identifier">root_vertex</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="special">*</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">vertices</span><span class="special">(</span><span class="identifier">graph</span><span class="special">).</span><span class="identifier">first</span><span class="special">,</span>
+ <span class="comment">// Optional named parameter (default value) with type requirement.</span>
+ <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span>
+ <span class="identifier">is_integral_property_map_of_key</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="identifier">_</span>
+ <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">graph</span><span class="special">::</span><span class="identifier">_</span><span class="special">&gt;::</span>
+ <span class="identifier">vertex_descriptor</span>
+ <span class="special">&gt;)))</span> <span class="identifier">index_map</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">get</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">vertex_index</span><span class="special">,</span> <span class="identifier">graph</span><span class="special">),</span>
+ <span class="comment">// Optional output named parameter (default value) with type req.</span>
+ <span class="identifier">in</span> <span class="identifier">out</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span>
+ <span class="identifier">is_property_map_of_key</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="identifier">_</span>
+ <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">graph</span><span class="special">::</span><span class="identifier">_</span><span class="special">&gt;::</span>
+ <span class="identifier">vertex_descriptor</span>
+ <span class="special">&gt;)))</span> <span class="identifier">color_map</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">default_color_map</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">num_vertices</span><span class="special">(</span><span class="identifier">graph</span><span class="special">),</span> <span class="identifier">index_map</span><span class="special">)</span>
+ <span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">depth_first_search</span><span class="special">(</span><span class="identifier">graph</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">visitor</span><span class="special">(</span><span class="identifier">visitor</span><span class="special">).</span>
+ <span class="identifier">color_map</span><span class="special">(</span><span class="identifier">color_map</span><span class="special">).</span><span class="identifier">root_vertex</span><span class="special">(</span><span class="identifier">root_vertex</span><span class="special">).</span>
+ <span class="identifier">vertex_index_map</span><span class="special">(</span><span class="identifier">index_map</span><span class="special">));</span>
+<span class="special">}</span>
+
+<span class="special">}</span> <span class="comment">// namespace graphs</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">TimeMap</span> <span class="special">&gt;</span>
+<span class="keyword">class</span> <span class="identifier">dfs_time_visitor</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_dfs_visitor</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">property_traits</span><span class="special">&lt;</span> <span class="identifier">TimeMap</span> <span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="identifier">T</span><span class="special">;</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">dfs_time_visitor</span><span class="special">(</span><span class="identifier">TimeMap</span> <span class="identifier">dmap</span><span class="special">,</span> <span class="identifier">TimeMap</span> <span class="identifier">fmap</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">t</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">dmap_</span><span class="special">(</span><span class="identifier">dmap</span><span class="special">),</span> <span class="identifier">fmap_</span><span class="special">(</span><span class="identifier">fmap</span><span class="special">),</span> <span class="identifier">time_</span><span class="special">(</span><span class="identifier">t</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">V</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">G</span> <span class="special">&gt;</span>
+ <span class="keyword">void</span> <span class="identifier">discover_vertex</span> <span class="special">(</span> <span class="identifier">V</span> <span class="identifier">u</span><span class="special">,</span> <span class="identifier">G</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">g</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span> <span class="identifier">put</span><span class="special">(</span><span class="identifier">dmap_</span><span class="special">,</span> <span class="identifier">u</span><span class="special">,</span> <span class="identifier">time_</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">V</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">G</span> <span class="special">&gt;</span>
+ <span class="keyword">void</span> <span class="identifier">finish_vertex</span> <span class="special">(</span> <span class="identifier">V</span> <span class="identifier">u</span><span class="special">,</span> <span class="identifier">G</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">g</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span> <span class="identifier">put</span><span class="special">(</span><span class="identifier">fmap_</span><span class="special">,</span> <span class="identifier">u</span><span class="special">,</span> <span class="identifier">time_</span><span class="special">++);</span> <span class="special">}</span>
+
+ <span class="identifier">TimeMap</span> <span class="identifier">dmap_</span><span class="special">;</span>
+ <span class="identifier">TimeMap</span> <span class="identifier">fmap_</span><span class="special">;</span>
+ <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">time_</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="keyword">void</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adjacency_list</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">vecS</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">vecS</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">directedS</span><span class="special">&gt;</span> <span class="identifier">G</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">graph_traits</span><span class="special">&lt;</span><span class="identifier">G</span><span class="special">&gt;::</span><span class="identifier">vertices_size_type</span> <span class="identifier">size_type</span><span class="special">;</span>
+
+ <span class="keyword">enum</span> <span class="special">{</span><span class="identifier">u</span><span class="special">,</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">w</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">z</span><span class="special">,</span> <span class="identifier">N</span><span class="special">};</span>
+ <span class="keyword">char</span> <span class="identifier">names</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="char">'u'</span><span class="special">,</span> <span class="char">'v'</span><span class="special">,</span> <span class="char">'w'</span><span class="special">,</span> <span class="char">'x'</span><span class="special">,</span> <span class="char">'y'</span><span class="special">,</span> <span class="char">'z'</span><span class="special">};</span>
+ <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">E</span><span class="special">;</span>
+ <span class="identifier">E</span> <span class="identifier">edges</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="identifier">E</span><span class="special">(</span><span class="identifier">u</span><span class="special">,</span> <span class="identifier">v</span><span class="special">),</span> <span class="identifier">E</span><span class="special">(</span><span class="identifier">u</span><span class="special">,</span> <span class="identifier">x</span><span class="special">),</span> <span class="identifier">E</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">v</span><span class="special">),</span> <span class="identifier">E</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="identifier">E</span><span class="special">(</span><span class="identifier
">v</span><span class="special">,</span> <span class="identifier">y</span><span class="special">),</span> <span class="identifier">E</span><span class="special">(</span><span class="identifier">w</span><span class="special">,</span> <span class="identifier">y</span><span class="special">),</span> <span class="identifier">E</span><span class="special">(</span><span class="identifier">w</span><span class="special">,</span> <span class="identifier">z</span><span class="special">),</span>
+ <span class="identifier">E</span><span class="special">(</span><span class="identifier">z</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)};</span>
+ <span class="identifier">G</span> <span class="identifier">g</span><span class="special">(</span><span class="identifier">edges</span><span class="special">,</span> <span class="identifier">edges</span> <span class="special">+</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">edges</span><span class="special">)</span> <span class="special">/</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">E</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">vector</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="identifier">dtime</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">num_vertices</span><span class="special">(</span><span class="identifier">g</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">size_type</span><span class="special">&gt;</span> <span class="identifier">ftime</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">num_vertices</span><span class="special">(</span><span class="identifier">g</span><span class="special">));</span>
+ <span class="identifier">size_type</span> <span class="identifier">t</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">dfs_time_visitor</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">*&gt;</span> <span class="identifier">vis</span><span class="special">(&amp;</span><span class="identifier">dtime</span><span class="special">[</span><span class="number">0</span><span class="special">],</span> <span class="special">&amp;</span><span class="identifier">ftime</span><span class="special">[</span><span class="number">0</span><span class="special">],</span> <span class="identifier">t</span><span class="special">);</span>
+
+ <span class="identifier">graphs</span><span class="special">::</span><span class="identifier">depth_first_search</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span> <span class="identifier">vis</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">size_type</span><span class="special">&gt;</span> <span class="identifier">dorder</span><span class="special">(</span><span class="identifier">N</span><span class="special">);</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">integer_range</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="identifier">r</span><span class="special">(</span><span class="number">0</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">copy</span><span class="special">(</span><span class="identifier">r</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">end</span><span class="special">(),</span> <span class="identifier">dorder</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">sort</span><span class="special">(</span><span class="identifier">dorder</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">dorder</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">indirect_cmp</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">*,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="special">&gt;(&amp;</span><span class="identifier">dtime</span><span class="special">[</span><span class="number">0</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">"order of discovery: "</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">N</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</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">names</span><span class="special">[</span><span class="identifier">dorder</span><span class="special">[</span><span class="identifier">i</span><span class="special">]]</span> <span class="special">&lt;&lt;</span> <span class="string">" "</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">;</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="identifier">forder</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">copy</span><span class="special">(</span><span class="identifier">r</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">end</span><span class="special">(),</span> <span class="identifier">forder</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">sort</span><span class="special">(</span><span class="identifier">forder</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">forder</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">indirect_cmp</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">*,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span><span class="identifier">size_type</span><span class="special">&gt;</span> <span class="special">&gt;(&amp;</span><span class="identifier">ftime</span><span class="special">[</span><span class="number">0</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">"order of finish: "</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">N</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</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">names</span><span class="special">[</span><span class="identifier">forder</span><span class="special">[</span><span class="identifier">i</span><span class="special">]]</span> <span class="special">&lt;&lt;</span> <span class="string">" "</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">;</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.__named_parameters___python__def___deduced_named_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___python__def___deduced_named_parameters" title="[Named Parameters] Python def: Deduced named parameters">[Named
+ Parameters] Python <code class="computeroutput"><span class="identifier">def</span></code>: Deduced
+ named 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">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity</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">python</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">not</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">or</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="identifier">placeholders</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">type_traits</span><span class="special">/</span><span class="identifier">is_convertible</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="keyword">namespace</span> <span class="identifier">py</span>
+<span class="special">{</span>
+
+<span class="comment">// For simplicity, trivial helper implementations.</span>
+<span class="keyword">bool</span> <span class="identifier">is_valid_identifier</span> <span class="special">(</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</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="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_keyword_expression</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_PARAMETER</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">func</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">docstring</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">keywords</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">policies</span><span class="special">)</span>
+
+<span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span>
+<span class="keyword">void</span> <span class="special">(</span><span class="identifier">def</span><span class="special">)</span> <span class="special">(</span>
+ <span class="comment">// Non-deduced and required named parameters.</span>
+ <span class="identifier">in</span> <span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*)</span> <span class="identifier">name</span><span class="special">,</span> <span class="comment">// Specified type.</span>
+ <span class="identifier">in</span> <span class="keyword">auto</span> <span class="identifier">func</span><span class="special">,</span> <span class="comment">// Any type (auto).</span>
+ <span class="comment">// Deduced and optional (with default value) named parameters.</span>
+ <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*)</span> <span class="identifier">docstring</span><span class="special">,</span> <span class="keyword">default</span> <span class="string">""</span><span class="special">,</span> <span class="comment">// Specified type.</span>
+ <span class="comment">// Type requirements also used to uniquely deduce parameters.</span>
+ <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">is_keyword_expression</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="identifier">_</span><span class="special">&gt;)</span> <span class="identifier">keywords</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">keyword_range</span><span class="special">(),</span>
+ <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENITITY_TYPE</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">not_</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="identifier">or_</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</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="identifier">_</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;</span>
+ <span class="special">,</span> <span class="identifier">is_keyword_expression</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="identifier">_</span><span class="special">&gt;</span>
+ <span class="special">&gt;</span>
+ <span class="special">&gt;)))</span> <span class="identifier">policies</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">default_call_policies</span><span class="special">()</span>
+ <span class="special">)</span>
+ <span class="identifier">precondition</span><span class="special">(</span> <span class="identifier">is_valid_identifier</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span> <span class="special">)</span> <span class="comment">// Also with contract.</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">func</span><span class="special">,</span> <span class="identifier">docstring</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">,</span> <span class="identifier">policies</span><span class="special">);</span>
+<span class="special">}</span>
+
+<span class="special">}</span> <span class="comment">// namespace py</span>
+
+<span class="keyword">void</span> <span class="identifier">f</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">main</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">some_policies</span> <span class="special">=</span> <span class="number">123</span><span class="special">;</span>
+ <span class="identifier">py</span><span class="special">::</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">some_policies</span><span class="special">,</span> <span class="string">"Documentation for f"</span><span class="special">);</span>
+ <span class="identifier">py</span><span class="special">::</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">f</span><span class="special">,</span> <span class="string">"Documentation for f"</span><span class="special">,</span> <span class="identifier">some_policies</span><span class="special">);</span>
+
+ <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">other_policies</span> <span class="special">=</span> <span class="string">"abc"</span><span class="special">;</span>
+ <span class="identifier">py</span><span class="special">::</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">_policies</span> <span class="special">=</span> <span class="identifier">other_policies</span><span class="special">,</span> <span class="string">"Documentation for f"</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.__named_parameters___python__class___named_template_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___python__class___named_template_parameters" title="[Named Parameters] Python class: Named template parameters">[Named
+ Parameters] Python <code class="computeroutput"><span class="keyword">class</span></code>: Named
+ template 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">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity</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">python</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">type_traits</span><span class="special">/</span><span class="identifier">is_class</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">type_traits</span><span class="special">/</span><span class="identifier">is_base_and_derived</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="identifier">assert</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="identifier">placeholders</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">not</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">and</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">noncopyable</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">shared_ptr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="keyword">namespace</span> <span class="identifier">py</span>
+<span class="special">{</span>
+
+<span class="keyword">namespace</span> <span class="identifier">detail</span> <span class="special">{</span> <span class="keyword">struct</span> <span class="identifier">bases_tag</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">B0</span> <span class="special">=</span> <span class="keyword">void</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span> <span class="special">=</span> <span class="keyword">void</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B2</span> <span class="special">=</span> <span class="keyword">void</span> <span class="special">&gt;</span>
+<span class="keyword">struct</span> <span class="identifier">bases</span> <span class="special">:</span> <span class="identifier">detail</span><span class="special">::</span><span class="identifier">bases_tag</span> <span class="special">{};</span>
+
+<span class="identifier">CONTRACT_TEMPLATE_PARAMETER</span><span class="special">(</span><span class="identifier">ClassType</span><span class="special">)</span>
+<span class="identifier">CONTRACT_TEMPLATE_PARAMETER</span><span class="special">(</span><span class="identifier">BaseList</span><span class="special">)</span>
+<span class="identifier">CONTRACT_TEMPLATE_PARAMETER</span><span class="special">(</span><span class="identifier">HeldType</span><span class="special">)</span>
+<span class="identifier">CONTRACT_TEMPLATE_PARAMETER</span><span class="special">(</span><span class="identifier">Copyable</span><span class="special">)</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span>
+ <span class="comment">// Required named template parameter with type requirement.</span>
+ <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_class</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="identifier">_</span><span class="special">&gt;)</span> <span class="identifier">ClassType</span><span class="special">,</span>
+ <span class="comment">// Deduced and optional named template parameters with type requirements.</span>
+ <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_base_and_derived</span><span class="special">&lt;</span>
+ <span class="identifier">detail</span><span class="special">::</span><span class="identifier">bases_tag</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">_</span><span class="special">&gt;)))</span> <span class="identifier">BaseList</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">bases</span><span class="special">&lt;&gt;,</span>
+ <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</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">or_</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="identifier">or_</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_base_and_derived</span><span class="special">&lt;</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">bases_tag</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">_</span><span class="special">&gt;</span>
+ <span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</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">_</span><span class="special">&gt;</span>
+ <span class="special">&gt;</span>
+ <span class="special">&gt;)))</span> <span class="identifier">HeldType</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">ClassType</span><span class="special">,</span>
+ <span class="identifier">deduce</span> <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</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">_</span><span class="special">&gt;)))</span> <span class="identifier">Copyable</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="keyword">void</span>
+ <span class="comment">// NOTE: Named template params do not directly support non-type params.</span>
+<span class="special">)</span>
+<span class="keyword">class</span> <span class="special">(</span><span class="identifier">class_</span><span class="special">)</span>
+ <span class="identifier">extends</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">ClassType</span><span class="special">,</span> <span class="identifier">BaseList</span><span class="special">,</span>
+ <span class="identifier">HeldType</span><span class="special">,</span> <span class="identifier">Copyable</span><span class="special">&gt;))</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="keyword">typedef</span> <span class="identifier">ClassType</span> <span class="identifier">class_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">BaseList</span> <span class="identifier">base_list</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">HeldType</span> <span class="identifier">held_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">Copyable</span> <span class="identifier">copyable</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="special">}</span> <span class="comment">// namespace py</span>
+
+<span class="keyword">struct</span> <span class="identifier">b</span> <span class="special">{</span> <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">b</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">struct</span> <span class="identifier">d</span> <span class="special">:</span> <span class="identifier">b</span> <span class="special">{</span> <span class="special">~</span><span class="identifier">d</span><span class="special">()</span> <span class="special">{}</span> <span class="special">};</span>
+
+<span class="comment">// Named parameters.</span>
+<span class="keyword">typedef</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">_ClassType</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">_Copyable</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">x1</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">d</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">_HeldType</span><span class="special">&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">d</span><span class="special">&gt;</span> <span class="special">&gt;,</span>
+ <span class="identifier">py</span><span class="special">::</span><span class="identifier">BaseList</span><span class="special">&lt;</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">x2</span><span class="special">;</span>
+<span class="comment">// Deduced parameters.</span>
+<span class="keyword">typedef</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span> <span class="special">&gt;</span> <span class="identifier">y1</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">d</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">d</span><span class="special">&gt;,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">y2</span><span class="special">;</span>
+
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x1</span><span class="special">::</span><span class="identifier">class_type</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x1</span><span class="special">::</span><span class="identifier">base_list</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x1</span><span class="special">::</span><span class="identifier">held_type</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x1</span><span class="special">::</span><span class="identifier">copyable</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span> <span class="special">&gt;</span> <span class="special">));</span>
+
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x2</span><span class="special">::</span><span class="identifier">class_type</span><span class="special">,</span> <span class="identifier">d</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x2</span><span class="special">::</span><span class="identifier">base_list</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x2</span><span class="special">::</span><span class="identifier">held_type</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">d</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">x2</span><span class="special">::</span><span class="identifier">copyable</span><span class="special">,</span> <span class="keyword">void</span> <span class="special">&gt;</span> <span class="special">));</span>
+
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y1</span><span class="special">::</span><span class="identifier">class_type</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y1</span><span class="special">::</span><span class="identifier">base_list</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y1</span><span class="special">::</span><span class="identifier">held_type</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y1</span><span class="special">::</span><span class="identifier">copyable</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span> <span class="special">&gt;</span> <span class="special">));</span>
+
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y2</span><span class="special">::</span><span class="identifier">class_type</span><span class="special">,</span> <span class="identifier">d</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y2</span><span class="special">::</span><span class="identifier">base_list</span><span class="special">,</span> <span class="identifier">py</span><span class="special">::</span><span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y2</span><span class="special">::</span><span class="identifier">held_type</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">d</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">));</span>
+<span class="identifier">BOOST_MPL_ASSERT</span><span class="special">((</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">y2</span><span class="special">::</span><span class="identifier">copyable</span><span class="special">,</span> <span class="keyword">void</span> <span class="special">&gt;</span> <span class="special">));</span>
+
+<span class="keyword">int</span> <span class="identifier">main</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="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.__named_parameters___calls__member_functions_with_named_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___calls__member_functions_with_named_parameters" title="[Named Parameters] Calls: Member functions with named parameters">[Named
+ Parameters] Calls: Member functions with named 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">iostream</span><span class="special">&gt;</span>
+
+<span class="keyword">namespace</span> <span class="identifier">calls</span>
+<span class="special">{</span>
+
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">arg2</span><span class="special">)</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">struct</span> <span class="special">(</span><span class="identifier">callable2</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="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Member function with named parameters.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">call</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg2</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">call_impl</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="string">""</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Constant member with named parameters.</span>
+ <span class="keyword">public</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">call</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg2</span> <span class="special">)</span> <span class="keyword">const</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">call_impl</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="string">"const"</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">CONTRACT_FUNCTION</span><span class="special">(</span> <span class="comment">// Static member with named parameters.</span>
+ <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="special">(</span><span class="identifier">scall</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">in</span> <span class="keyword">int</span> <span class="identifier">arg2</span> <span class="special">)</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">call_impl</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="string">"static"</span><span class="special">);</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="comment">// NOTE: Function definition with named params cannot be directly separated.</span>
+ <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">call_impl</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">qualifier</span> <span class="special">)</span> <span class="special">;</span>
+<span class="special">};</span>
+
+<span class="keyword">void</span> <span class="identifier">callable2</span><span class="special">::</span><span class="identifier">call_impl</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">arg1</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">what</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">arg1</span> <span class="special">&lt;&lt;</span> <span class="string">", "</span> <span class="special">&lt;&lt;</span> <span class="identifier">arg2</span> <span class="special">&lt;&lt;</span> <span class="string">" ("</span> <span class="special">&lt;&lt;</span> <span class="identifier">what</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="comment">// namespace calls</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">calls</span><span class="special">::</span><span class="identifier">callable2</span><span class="special">::</span><span class="identifier">scall</span><span class="special">(</span><span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg2</span> <span class="special">=</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg1</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
+
+ <span class="identifier">calls</span><span class="special">::</span><span class="identifier">callable2</span> <span class="identifier">c</span><span class="special">;</span>
+ <span class="identifier">c</span><span class="special">.</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg2</span> <span class="special">=</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg1</span> <span class="special">=</span> <span class="number">4</span><span class="special">);</span>
+
+ <span class="identifier">calls</span><span class="special">::</span><span class="identifier">callable2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">cc</span> <span class="special">=</span> <span class="identifier">c</span><span class="special">;</span>
+ <span class="identifier">cc</span><span class="special">.</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg2</span> <span class="special">=</span> <span class="number">5</span><span class="special">,</span> <span class="identifier">calls</span><span class="special">::</span><span class="identifier">_arg1</span> <span class="special">=</span> <span class="number">6</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.__named_parameters___my_class__constructors_with_named_parameters"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___my_class__constructors_with_named_parameters" title="[Named Parameters] My Class: Constructors with named parameters">[Named
+ Parameters] My Class: Constructors with named 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">iostream</span><span class="special">&gt;</span>
+
+<span class="keyword">namespace</span> <span class="identifier">mine</span> <span class="special">{</span>
+
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">(</span><span class="identifier">index</span><span class="special">)</span>
+
+<span class="comment">// NOTE: Constructors with named parameters need to be implement in bases.</span>
+<span class="keyword">struct</span> <span class="identifier">myclass_params</span>
+<span class="special">{</span>
+ <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">Name</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Index</span> <span class="special">&gt;</span>
+ <span class="identifier">myclass_params</span> <span class="special">(</span> <span class="identifier">Name</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">Index</span> <span class="identifier">index</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">"name = "</span> <span class="special">&lt;&lt;</span> <span class="identifier">name</span> <span class="special">&lt;&lt;</span> <span class="string">"; index = "</span> <span class="special">&lt;&lt;</span> <span class="identifier">index</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="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">struct</span> <span class="special">(</span><span class="identifier">myclass</span><span class="special">)</span> <span class="identifier">extends</span><span class="special">(</span> <span class="identifier">myclass_params</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="identifier">CONTRACT_CONSTRUCTOR</span><span class="special">(</span>
+ <span class="keyword">public</span> <span class="keyword">explicit</span> <span class="special">(</span><span class="identifier">myclass</span><span class="special">)</span> <span class="special">(</span> <span class="identifier">in</span> <span class="keyword">auto</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">in</span> <span class="keyword">auto</span> <span class="identifier">index</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">42</span> <span class="special">)</span>
+ <span class="identifier">initialize</span><span class="special">(</span> <span class="identifier">myclass_params</span><span class="special">(</span><span class="identifier">CONTRACT_CONSTRUCTOR_PARAMETERS</span><span class="special">)</span> <span class="special">)</span>
+ <span class="comment">/** @todo are contracts still checked pre &gt; inv &gt; body &gt; post &gt; inv? */</span>
+ <span class="comment">/* or pre &gt; body &gt; inv &gt; post &gt; inv which is incorrect! */</span>
+ <span class="special">)</span> <span class="special">{}</span>
+<span class="special">};</span>
+
+<span class="special">}</span> <span class="comment">// namespace mine</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="keyword">void</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">mine</span><span class="special">::</span><span class="identifier">myclass</span> <span class="identifier">x</span><span class="special">(</span><span class="string">"bob"</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span>
+ <span class="identifier">mine</span><span class="special">::</span><span class="identifier">myclass</span> <span class="identifier">y</span><span class="special">(</span><span class="identifier">mine</span><span class="special">::</span><span class="identifier">_index</span> <span class="special">=</span> <span class="number">12</span><span class="special">,</span> <span class="identifier">mine</span><span class="special">::</span><span class="identifier">_name</span> <span class="special">=</span> <span class="string">"sally"</span><span class="special">);</span>
+ <span class="identifier">mine</span><span class="special">::</span><span class="identifier">myclass</span> <span class="identifier">z</span><span class="special">(</span><span class="string">"june"</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.__named_parameters___positive_number__fine_grained_parameter_name_control"></a><a class="link" href="examples.html#contract__.examples.__named_parameters___positive_number__fine_grained_parameter_name_control" title="[Named Parameters] Positive Number: Fine-grained parameter name control">[Named
+ Parameters] Positive Number: Fine-grained parameter name control</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">type_traits</span><span class="special">/</span><span class="identifier">has_equal_to</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="identifier">placeholders</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">int</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">long</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">char</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">namespace</span> <span class="identifier">num</span>
+<span class="special">{</span>
+
+<span class="keyword">namespace</span> <span class="identifier">tag</span> <span class="comment">// Namespace `tag` already used here, use `keywords` instead.</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">Value</span><span class="special">;</span> <span class="comment">// Dummy declarations...</span>
+ <span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">Default</span><span class="special">;</span>
+ <span class="identifier">Value</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">Default</span><span class="special">();</span>
+<span class="special">}</span>
+
+<span class="comment">// Also use `Param` and `_param` postfixes instead of `_` prefix.</span>
+<span class="identifier">CONTRACT_PARAMETER_TEMPLATE</span><span class="special">((</span><span class="identifier">ValueParam</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">)</span> <span class="identifier">Value</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER_TEMPLATE</span><span class="special">((</span><span class="identifier">DefaultParam</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">)</span> <span class="identifier">Default</span><span class="special">)</span>
+<span class="identifier">CONTRACT_PARAMETER</span><span class="special">((</span><span class="identifier">value_param</span><span class="special">,</span> <span class="identifier">keywords</span><span class="special">)</span> <span class="identifier">value</span><span class="special">)</span>
+
+<span class="identifier">CONTRACT_CLASS</span><span class="special">(</span>
+<span class="keyword">template</span><span class="special">(</span>
+ <span class="keyword">namespace</span> <span class="identifier">keywords</span><span class="special">,</span> <span class="comment">// Use namespace `keywords` instead of `tag`.</span>
+ <span class="identifier">in</span> <span class="keyword">typename</span> <span class="identifier">Value</span><span class="special">,</span> <span class="keyword">default</span> <span class="keyword">int</span><span class="special">,</span>
+ <span class="identifier">in</span> <span class="identifier">requires</span><span class="special">(</span><span class="identifier">is_same</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="identifier">_</span><span class="special">::</span><span class="identifier">type</span><span class="special">,</span> <span class="identifier">Value</span><span class="special">&gt;)</span> <span class="identifier">Default</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;</span>
+<span class="special">)</span>
+<span class="keyword">struct</span> <span class="special">(</span><span class="identifier">positive</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">static</span> <span class="keyword">class</span><span class="special">(</span> <span class="identifier">Default</span><span class="special">::</span><span class="identifier">value</span> <span class="special">&gt;</span> <span class="number">0</span> <span class="special">),</span>
+ <span class="identifier">get</span><span class="special">()</span> <span class="special">&gt;</span> <span class="number">0</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">positive</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">value_</span><span class="special">(</span><span class="identifier">Default</span><span class="special">::</span><span class="identifier">value</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">void</span> <span class="special">(</span><span class="identifier">set</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">namespace</span> <span class="identifier">keywords</span><span class="special">,</span> <span class="identifier">in</span> <span class="special">(</span><span class="identifier">Value</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">value</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">get</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">value</span><span class="special">,</span> <span class="identifier">requires</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">has_euql_to</span><span class="special">&lt;</span><span class="identifier">Value</span><span class="special">&gt;::</span><span class="identifier">value</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">value</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="identifier">Value</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">(</span><span class="identifier">get</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="keyword">private</span><span class="special">:</span>
+ <span class="identifier">Value</span> <span class="identifier">value_</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="special">}</span> <span class="comment">// namespace num</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span> <span class="special">(</span> <span class="identifier">value</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">num</span><span class="special">::</span><span class="identifier">positive</span><span class="special">&lt;</span> <span class="keyword">char</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">char_</span><span class="special">&lt;</span><span class="char">'z'</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">p</span><span class="special">;</span>
+ <span class="identifier">num</span><span class="special">::</span><span class="identifier">positive</span><span class="special">&lt;</span> <span class="special">&gt;</span> <span class="identifier">q</span><span class="special">;</span>
+
+ <span class="comment">// Use `...Param` instead of `_...`.</span>
+ <span class="identifier">num</span><span class="special">::</span><span class="identifier">positive</span><span class="special">&lt;</span> <span class="identifier">num</span><span class="special">::</span><span class="identifier">DefaultParam</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="identifier">int_</span><span class="special">&lt;</span><span class="number">10</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">r</span><span class="special">;</span>
+ <span class="identifier">num</span><span class="special">::</span><span class="identifier">positive</span><span class="special">&lt;</span>
+ <span class="identifier">num</span><span class="special">::</span><span class="identifier">DefaultParam</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="identifier">long_</span><span class="special">&lt;</span><span class="number">10</span><span class="special">&gt;</span> <span class="special">&gt;</span>
+ <span class="special">,</span> <span class="identifier">num</span><span class="special">::</span><span class="identifier">ValueParam</span><span class="special">&lt;</span><span class="keyword">long</span><span class="special">&gt;</span>
+ <span class="special">&gt;</span> <span class="identifier">s</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="identifier">get</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">s</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="identifier">num</span><span class="special">::</span><span class="identifier">value_param</span> <span class="special">=</span> <span class="number">123</span><span class="special">);</span> <span class="comment">// Use `..._param` instead of `_...`.</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="identifier">get</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="keyword">return</span> <span class="number">0</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>

Modified: sandbox/contract/libs/contract/doc/html/index.html
==============================================================================
--- sandbox/contract/libs/contract/doc/html/index.html (original)
+++ sandbox/contract/libs/contract/doc/html/index.html 2011-11-06 21:22:24 EST (Sun, 06 Nov 2011)
@@ -55,7 +55,7 @@
 </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: November 07, 2011 at 01:49:23 GMT</small></p></td>
+<td align="left"><p><small>Last revised: November 07, 2011 at 02:18:04 GMT</small></p></td>
 <td align="right"><div class="copyright-footer"></div></td>
 </tr></table>
 <hr>


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