Files
contract/doc/examples.qbk
2016-05-30 10:36:52 -07:00

141 lines
5.2 KiB
Plaintext

[section Examples]
This section lists examples taken from different Contract Programming sources and re-implemented using this library.
Some of these examples might be from old sources, containing old or obsolete code practices, not optimized for execution speed, and they be more relevant in the context programming languages other than C++.
Nevertheless, programmers are encouraged to review these examples to see a few diverse usages of this library that might be relevant for the contracts they need to write in their code.
Sources:
* __N1962__: Examples from the proposal to add Contract Programming to C++11 (unfortunately, this proposal was never accepted into the standard).
* __Meyer97__: Examples using the Eiffel programming language and reprogrammed using this library for C++.
* __Mitchell02__: Additional 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).
A few notable examples:
* [link N1962_vector_anchor \[N1962\] Vector]: Complete contracts for `std::vector` and a comparison with __N1962__ syntax.
* [link N1962_square_root_anchor \[N1962\] Square Root]: Comparison with D syntax.
* [link Mitchell02_counter_anchor \[Mitchell02\] Counter]: Subcontracting.
* [link Meyer97_stack4_anchor \[Meyer97\] Stack4]: Comparison with Eiffel syntax.
* [link Cline90_vector_anchor \[Cline90\] Vector]: Comparison with A++ syntax.
[#N1962_vector_anchor]
[heading \[N1962\] Vector: STL Vector contracts and comparison with C++ contract proposal syntax]
[import ../example/n1962/vector.cpp]
[import ../example/n1962/vector_n1962.hpp]
[table
[ [This Library] [Contract \[N1962\] and Static-If \[N3613\] Proposals (neither part of C++)] ]
[ [[n1962_vector]] [[n1962_vector_n1962]] ]
]
[heading \[N1962\] Circle: Subcontracting]
[import ../example/n1962/circle.cpp]
[n1962_circle]
[heading \[N1962\] Factorial: Recursion and assertion computational complexity]
[import ../example/n1962/factorial.cpp]
[n1962_factorial]
[heading \[N1962\] Equal: Operators]
[import ../example/n1962/equal.cpp]
[n1962_equal]
[heading \[N1962\] Sum: Array parameter]
[import ../example/n1962/sum.cpp]
[n1962_sum]
[#N1962_square_root_anchor]
[heading \[N1962\] Square Root: Default parameters and comparison with D syntax]
[import ../example/n1962/sqrt.cpp]
[import ../example/n1962/sqrt.d]
[table
[ [This Library] [The D Programming Language] ]
[ [[n1962_sqrt]] [[n1962_sqrt_d]] ]
]
[#Meyer97_stack4_anchor]
[heading \[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] [The Eiffel Programming Language] ]
[ [[meyer97_stack4]] [[meyer97_stack4_e]] ]
[ [[meyer97_stack4_main]] [] ]
]
[heading \[Meyer97\] Stack3: Error codes instead of preconditions]
[import ../example/meyer97/stack3.cpp]
[meyer97_stack3]
[heading \[Mitchell02\] Name List: Relaxing subcontracts]
[import ../example/mitchell02/name_list.cpp]
[mitchell02_name_list]
[heading \[Mitchell02\] Dictionary: Key-value map]
[import ../example/mitchell02/dictionary.cpp]
[mitchell02_dictionary]
[heading \[Mitchell02\] Courier: Subcontracting and static class invariants]
[import ../example/mitchell02/courier.cpp]
[mitchell02_courier]
[heading \[Mitchell02\] Stack: Stack-like container]
[import ../example/mitchell02/stack.cpp]
[mitchell02_stack]
[heading \[Mitchell02\] Simple Queue: Queue-like container]
[import ../example/mitchell02/simple_queue.cpp]
[mitchell02_simple_queue]
[heading \[Mitchell02\] Customer Manager: Contracts instead of Defensive Programming]
[import ../example/mitchell02/customer_manager.cpp]
[mitchell02_customer_manager]
[heading \[Mitchell02\] Observer: Pure virtual functions]
[import ../example/mitchell02/observer/observer.hpp]
[mitchell02_observer]
[import ../example/mitchell02/observer/subject.hpp]
[mitchell02_subject]
[import ../example/mitchell02/observer_main.cpp]
[mitchell02_observer_main]
[#Mitchell02_counter_anchor]
[heading \[Mitchell02\] Counter: Subcontracting]
[import ../example/mitchell02/counter/push_button.hpp]
[mitchell02_push_button]
[import ../example/mitchell02/counter/decrement_button.hpp]
[mitchell02_decrement_button]
[import ../example/mitchell02/counter/counter.hpp]
[mitchell02_counter]
[import ../example/mitchell02/counter_main.cpp]
[mitchell02_counter_main]
[#Cline90_vector_anchor]
[heading \[Cline90\] Vector: Comparison with A++ proposed syntax]
[import ../example/cline90/vector.hpp]
[import ../example/cline90/vector_main.cpp]
[import ../example/cline90/vector_axx.hpp]
[table
[ [This Library] [A++ Proposal (not part of C++)] ]
[ [[cline90_vector]] [[cline90_vector_axx]] ]
[ [[cline90_vector_main]] [] ]
]
[heading \[Cline90\] Stack: Stack-like container]
[import ../example/cline90/stack.cpp]
[cline90_stack]
[heading \[Cline90\] Vector-Stack: Subcontracting]
[import ../example/cline90/vstack.cpp]
[cline90_vstack]
[heading \[Cline90\] Calendar: A very simple calendar]
[import ../example/cline90/calendar.cpp]
[cline90_calendar]
[endsect]