mirror of
https://github.com/boostorg/contract.git
synced 2026-02-27 17:02:15 +00:00
319 lines
10 KiB
Plaintext
Executable File
319 lines
10 KiB
Plaintext
Executable File
|
|
[/ Copyright (C) 2008-2012 Lorenzo Caminiti ]
|
|
[/ Distributed under 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) ]
|
|
[/ Home at http://sourceforge.net/projects/contractpp ]
|
|
|
|
[section Examples]
|
|
|
|
This section lists non-trivial examples programmed using this library.
|
|
The listed examples are taken from the foloowing sources (which are referenced in the title of each example).
|
|
|
|
[table
|
|
[ [Sources] [Notes] ]
|
|
[ [__N1962__] [
|
|
Examples from the proposal to add Contract Programming to __CXX11__ submitted to the standard committee (unfortunately, this proposal was never accepted into the standard).
|
|
] ]
|
|
[ [__N2081__] [
|
|
Examples from the proposal to add concepts to __CXX11__ submitted to the standard committee (unfortunately, this proposal was never accepted into the standard).
|
|
These examples have been extended to specify both concepts and contracts.
|
|
] ]
|
|
[ [__Meyer97__ __Mitchell02__] [
|
|
Examples using the __Eiffel__ programming language and reprogrammed using this library for C++.
|
|
] ]
|
|
[ [__Cline90__] [
|
|
Examples from a very early proposal called Annotated C++ (A++) to add Contract Programming to C++ (A++ was never implemented or proposed for addition to the standard).
|
|
] ]
|
|
[ [__Stroustrup97__] [
|
|
One example that shows the importance of class invariants and how to configure this library to throw exceptions instead of terminating the program when contracts are broken.
|
|
] ]
|
|
]
|
|
|
|
The followings are among the most interesting examples:
|
|
|
|
[table
|
|
[ [Key Example] [Topic] ]
|
|
[ [[link contract__.examples.__n1962___vector__comparison_with_c___proposed_syntax \[N1962\] Vector]] [
|
|
A comparison between this library syntax and the syntax for contract and concept checking proposed by __N1962__ and __N2081__ respectively.
|
|
] ]
|
|
[ [[link contract__.examples.__n2081___add__generic_addition_algorithm \[N2081\] Add]] [
|
|
Contracts and user-defined concepts.
|
|
] ]
|
|
[ [[link contract__.examples.__mitchell02___counter__subcontracting_and_virtual_specifiers__final__override__new__and_pure_virtual_ \[Mitchell02\] Counter]] [
|
|
Subcontracting and __CXX11__-like virtual specifiers `final`, `override`, `new`, and pure virtual.
|
|
] ]
|
|
[ [[link contract__.examples.__meyer97___stack4__comparison_with_eiffel_syntax \[Meyer97\] Stack4]] [
|
|
A comparison between this library and __Eiffel__ syntax for preconditions, postconditions, and class invariants.
|
|
] ]
|
|
[ [[link contract__.examples.__meyer97___gcd__loop_variants_and_invariants_plus_comparison_with_eiffel_syntax \[Meyer97\] GCD]] [
|
|
A comparison between this library and __Eiffel__ syntax for loop variants and block invariants.
|
|
] ]
|
|
[ [[link contract__.examples.__cline90___vector__comparison_with_a___proposed_syntax \[Cline90\] Vector]] [
|
|
A comparison between this library and A++ syntax.
|
|
] ]
|
|
]
|
|
|
|
[section \[N1962\] Vector: Comparison with C++ proposed syntax]
|
|
[import ../example/n1962/vector.hpp]
|
|
[import ../example/n1962/vector.cpp]
|
|
[import ../example/n1962/vector_npaper.hpp]
|
|
[table
|
|
[ [This Library (C++03)] [\[N1962\] and \[N2081\] Proposals (not part of C++)] ]
|
|
[ [[n1962_vector]] [[n1962_vector_npaper]] ]
|
|
[ [[n1962_vector_main]] [] ]
|
|
]
|
|
[endsect]
|
|
|
|
[section \[N1962\] Circle: Subcontracting]
|
|
[import ../example/n1962/circle.cpp]
|
|
[n1962_circle]
|
|
[endsect]
|
|
|
|
[section \[N1962\] Factorial: Recursion and assertion computational complexity]
|
|
[import ../example/n1962/factorial.cpp]
|
|
[n1962_factorial]
|
|
[endsect]
|
|
|
|
[section \[N1962\] Equal: Operators]
|
|
[import ../example/n1962/equal.hpp]
|
|
[n1962_equal_header]
|
|
[import ../example/n1962/equal_not.hpp]
|
|
[n1962_equal_not_header]
|
|
[import ../example/n1962/equal_main.cpp]
|
|
[n1962_equal_main]
|
|
[endsect]
|
|
|
|
[section \[N1962\] Sum: Separated body definitions]
|
|
[import ../example/n1962/sum.hpp]
|
|
[n1962_sum_header]
|
|
[import ../example/n1962/sum.cpp]
|
|
[n1962_sum]
|
|
[import ../example/n1962/sum_main.cpp]
|
|
[n1962_sum_main]
|
|
[endsect]
|
|
|
|
[section \[N1962\] Square Root: Default parameters and comparison with D syntax]
|
|
[import ../example/n1962/sqrt.cpp]
|
|
[import ../example/n1962/sqrt.d]
|
|
[table
|
|
[ [This Library (C++03)] [The D Programming Language] ]
|
|
[ [[n1962_sqrt]] [[n1962_sqrt_d]] ]
|
|
]
|
|
[endsect]
|
|
|
|
[section \[N1962\] Block: Block invariants]
|
|
[import ../example/n1962/block_invariant.cpp]
|
|
[n1962_block_invariant]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Add: Generic addition algorithm]
|
|
[import ../example/n2081/add.hpp]
|
|
[n2081_add_header]
|
|
[import ../example/n2081/add.cpp]
|
|
[n2081_add]
|
|
[import ../example/n2081/add_error.cpp]
|
|
[n2081_add_error]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Advance: Concept-based iterator overloading (emulated using tags)]
|
|
[import ../example/n2081/advance.cpp]
|
|
[n2081_advance]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Find: Generic find algorithm]
|
|
[import ../example/n2081/find.hpp]
|
|
[n2081_find_header]
|
|
[import ../example/n2081/find.cpp]
|
|
[n2081_find]
|
|
[import ../example/n2081/find_error.cpp]
|
|
[n2081_find_error]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Apply: Overloaded invocation of functors]
|
|
[import ../example/n2081/apply.cpp]
|
|
[n2081_apply]
|
|
[endsect]
|
|
|
|
[section \[N2081\] For Each: Generic for-each algorithm]
|
|
[import ../example/n2081/for_each.cpp]
|
|
[n2081_for_each]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Transform: Generic binary transformation algorithm]
|
|
[import ../example/n2081/transform.cpp]
|
|
[n2081_transform]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Count: Generic counting algorithm]
|
|
[import ../example/n2081/count.cpp]
|
|
[n2081_count]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Convert: Conversion between two types]
|
|
[import ../example/n2081/convert.hpp]
|
|
[n2081_convert_header]
|
|
[import ../example/n2081/convert.cpp]
|
|
[n2081_convert]
|
|
[import ../example/n2081/convert_error.cpp]
|
|
[n2081_convert_error]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Equal: Generic equality comparison]
|
|
[import ../example/n2081/equal.hpp]
|
|
[n2081_equal_header]
|
|
[import ../example/n2081/equal.cpp]
|
|
[n2081_equal]
|
|
[import ../example/n2081/equal_error.cpp]
|
|
[n2081_equal_error]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Less Equal: Generic less-than or equal-to comparison]
|
|
[import ../example/n2081/less_eq.cpp]
|
|
[n2081_less_eq]
|
|
[endsect]
|
|
|
|
[section \[N2081\] De-Ref: Generic iterator dereferencing]
|
|
[import ../example/n2081/deref.cpp]
|
|
[n2081_deref]
|
|
[endsect]
|
|
|
|
[section \[N2081\] Min: Generic minimum algorithm]
|
|
[import ../example/n2081/min.hpp]
|
|
[n2081_min_header]
|
|
[import ../example/n2081/min.cpp]
|
|
[n2081_min]
|
|
[import ../example/n2081/min_error.cpp]
|
|
[n2081_min_error]
|
|
[endsect]
|
|
|
|
[section \[Meyer97\] Stack4: Comparison with Eiffel syntax]
|
|
[import ../example/meyer97/stack4.hpp]
|
|
[import ../example/meyer97/stack4_main.cpp]
|
|
[import ../example/meyer97/stack4.e]
|
|
[table
|
|
[ [This Library (C++03)] [The Eiffel Programming Language] ]
|
|
[ [[meyer97_stack4_header]] [[meyer97_stack4_e]] ]
|
|
[ [[meyer97_stack4_main]] [] ]
|
|
]
|
|
[endsect]
|
|
|
|
[section \[Meyer97\] Stack3: Error codes instead of preconditions]
|
|
[import ../example/meyer97/stack3.cpp]
|
|
[meyer97_stack3]
|
|
[endsect]
|
|
|
|
[section \[Meyer97\] GCD: Loop variants and invariants plus comparison with Eiffel syntax]
|
|
[import ../example/meyer97/gcd.cpp]
|
|
[import ../example/meyer97/gcd.e]
|
|
[table
|
|
[ [This Library (C++03)] [The Eiffel Programming Language] ]
|
|
[ [[meyer97_gcd]] [[teletype] [meyer97_gcd_e] [c++]] ]
|
|
]
|
|
[endsect]
|
|
|
|
[section \[Meyer97\] Max-Array: Nested loop variants and invariants]
|
|
[import ../example/meyer97/maxarray.cpp]
|
|
[meyer97_maxarray]
|
|
[endsect]
|
|
|
|
[section \[Mitchell02\] Name List: Relaxed subcontracts]
|
|
[import ../example/mitchell02/name_list.hpp]
|
|
[mitchell02_name_list_header]
|
|
[import ../example/mitchell02/name_list.cpp]
|
|
[mitchell02_name_list]
|
|
[import ../example/mitchell02/name_list_main.cpp]
|
|
[mitchell02_name_list_main]
|
|
[endsect]
|
|
|
|
[section \[Mitchell02\] Dictionary: Simple key-value map]
|
|
[import ../example/mitchell02/dictionary.cpp]
|
|
[mitchell02_dictionary]
|
|
[endsect]
|
|
|
|
[section \[Mitchell02\] Courier: Subcontracting and static class invariants]
|
|
[import ../example/mitchell02/courier.hpp]
|
|
[mitchell02_courier_header]
|
|
[import ../example/mitchell02/courier.cpp]
|
|
[mitchell02_courier]
|
|
[import ../example/mitchell02/courier_main.cpp]
|
|
[mitchell02_courier_main]
|
|
[endsect]
|
|
|
|
[section \[Mitchell02\] Stack: Simple stack dispenser]
|
|
[import ../example/mitchell02/stack.cpp]
|
|
[mitchell02_stack]
|
|
[endsect]
|
|
|
|
[section \[Mitchell02\] Simple Queue: Simple queue dispenser]
|
|
[import ../example/mitchell02/simple_queue.cpp]
|
|
[mitchell02_simple_queue]
|
|
[endsect]
|
|
|
|
[section \[Mitchell02\] Customer Manager: Contracts instead of Defensive Programming]
|
|
[import ../example/mitchell02/customer_manager.hpp]
|
|
[mitchell02_customer_manager_header]
|
|
[import ../example/mitchell02/customer_manager.cpp]
|
|
[mitchell02_customer_manager]
|
|
[import ../example/mitchell02/customer_manager_main.cpp]
|
|
[mitchell02_customer_manager_main]
|
|
[endsect]
|
|
|
|
[section \[Mitchell02\] Observer: Contracts for pure virtual functions]
|
|
[import ../example/mitchell02/observer/observer.hpp]
|
|
[mitchell02_observer_header]
|
|
[import ../example/mitchell02/observer/subject.hpp]
|
|
[mitchell02_subject_header]
|
|
[import ../example/mitchell02/observer_main.cpp]
|
|
[mitchell02_observer_main]
|
|
[endsect]
|
|
|
|
[section \[Mitchell02\] Counter: Subcontracting and virtual specifiers (final, override, new, and pure virtual)]
|
|
[import ../example/mitchell02/counter/push_button.hpp]
|
|
[mitchell02_push_button_header]
|
|
[import ../example/mitchell02/counter/decrement_button.hpp]
|
|
[mitchell02_decrement_button_header]
|
|
[import ../example/mitchell02/counter/counter.hpp]
|
|
[mitchell02_counter_header]
|
|
[import ../example/mitchell02/counter_main.cpp]
|
|
[mitchell02_counter_main]
|
|
[endsect]
|
|
|
|
[section \[Stroustrup97\] String: Throw when contract is broken]
|
|
[import ../example/stroustrup97/string.hpp]
|
|
[stroustrup97_string_header]
|
|
[import ../example/stroustrup97/string.cpp]
|
|
[stroustrup97_string]
|
|
[import ../example/stroustrup97/string_main.cpp]
|
|
[stroustrup97_string_main]
|
|
[endsect]
|
|
|
|
[section \[Cline90\] Vector: Comparison with A++ proposed syntax]
|
|
[import ../example/cline90/vector.hpp]
|
|
[import ../example/cline90/vector_main.cpp]
|
|
[import ../example/cline90/vector_app.hpp]
|
|
[table
|
|
[ [This Library (C++03)] [A++ Proposal (not part of C++)] ]
|
|
[ [[cline90_vector_header]] [[cline90_vector_app_header]] ]
|
|
[ [[cline90_vector_main]] [] ]
|
|
]
|
|
[endsect]
|
|
|
|
[section \[Cline90\] Stack: Function-Try blocks and exception specifications]
|
|
[import ../example/cline90/stack.cpp]
|
|
[cline90_stack]
|
|
[endsect]
|
|
|
|
[section \[Cline90\] Vector-Stack: Subcontracting from Abstract Data Type (ADT)]
|
|
[import ../example/cline90/vstack.cpp]
|
|
[cline90_vstack]
|
|
[endsect]
|
|
|
|
[section \[Cline90\] Calendar: A very simple calendar]
|
|
[import ../example/cline90/calendar.cpp]
|
|
[cline90_calendar]
|
|
[endsect]
|
|
|
|
[endsect]
|
|
|