Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / contract / doc / advanced.qbk
index 2c1d3a2..3ea2400 100644 (file)
@@ -6,7 +6,7 @@
 
 [section Advanced]
 
-This section is a guide to advanced usages of this library.
+This section is a guide to advanced usage of this library.
 
 [section Pure Virtual Public Functions]
 
@@ -28,9 +28,6 @@ Therefore, programmers can safely `assert(false)` at the beginning of the body i
 
 As seen in __Public_Function_Overrides__, preconditions of overriding public functions are checked in __OR__ with preconditions of overridden virtual public functions.
 Therefore, if a virtual public function in a base class specifies no precondition then preconditions specified by all its overriding functions in derived classes will have no effect (because when checked in __OR__ with the overridden function from the base class that has no preconditions, they will always pass):
-[footnote
-This consequence of the __substitution_principle__ ["that if any function in an inheritance hierarchy has no preconditions, then preconditions on functions overriding it have no useful effect] is also explicitly mentioned in the contract documentation of the D Programming Language (see __Bright04__).
-]
 
     class u { // Some base class.
     public:
@@ -47,7 +44,10 @@ This consequence of the __substitution_principle__ ["that if any function in an
     };
 
 This correctly reflects the fact that the overridden function in the base class can be called from any context (because it has no precondition) and so must all its overriding functions in all derived classes in accordance to the __substitution_principle__.
-In other words, the code above has the effect as declaring the virtual public function in the base class with a single precondition `BOOST_CONTRACT_ASSERT(true)` that will always trivially pass:
+[footnote
+This consequence of the __substitution_principle__ ["that if any function in an inheritance hierarchy has no preconditions, then preconditions on functions overriding it have no useful effect] is also explicitly mentioned in the contract documentation of the D Programming Language (see __Bright04__).
+]
+In other words, the code above has the same effect as declaring the virtual public function in the base class with a single precondition `BOOST_CONTRACT_ASSERT(true)` that will always trivially pass:
     
     class u { // Some base class.
     public:
@@ -73,7 +73,7 @@ For example (see [@../../example/features/named_override.cpp =named_override.cpp
 [import ../example/features/named_override.cpp]
 [named_override_pure_virtual_assert_false]
 
-That said, the need to declare such a precondition `BOOST_CONTRACT_ASSERT(false)` that will always fail might be an indication that the base class interface is not correctly designed.
+That said, the need to declare such a precondition `BOOST_CONTRACT_ASSERT(false)` that will always fail might also be an indication that the base class interface is not correctly designed.
 In general, the base class interface should still contain all functions (eventually as pure virtual) that are necessary to program its contracts.
 
 [endsect]
@@ -83,7 +83,7 @@ In general, the base class interface should still contain all functions (eventua
 It is possible to use `boost::optional` to handle return values when programmers cannot construct the result variable at its point of declaration before the contract (e.g., because an appropriate constructor for the return type is not available at that point, or just because it would be too expensive to execute an extra initialization of the return value at run-time).
 [footnote
 *Rationale:*
-This library uses `boost::optional` instead of `std::optional` because `std::optional` is not available before C++17.
+This library uses `boost::optional` instead of `std::optional` to support a larger number of compilers and their versions (because `std::optional` was not available before C++17).
 ]
 For example (see [@../../example/features/optional_result.cpp =optional_result.cpp=]):
 
@@ -92,15 +92,15 @@ For example (see [@../../example/features/optional_result.cpp =optional_result.c
 
 In this example the return type is a reference so it does not have default constructor that can be used to initialize `result` when it is declared before the contract declaration.
 In addition, `Index` needs to be validated to be smaller than `size()` by the precondition before it can be used to retrieve the reference to assign to `result` so `vect[Index]` cannot be used to initialize `result` when it is declared before the contract declaration.
-Therefore, `boost::optional` is used to defer `result` proper initialization until the execution of the function body, after the contract declaration, where `Index` has been validated by the precondition and `vect[Index]` can be safely evaluated to initialize `result`.
+Therefore, `boost::optional` is used to defer `result` real initialization until the execution of the function body, after the contract declaration, where `Index` has been validated by the precondition and `vect[Index]` can be safely evaluated to initialize `result`.
 
 As seen in __Return_Values__, it is the responsibility of the programmers to ensure that `result` is always set to the return value (when the function exits without trowing an exception).
 This also ensures that `result` is always set before the postconditions are checked so programmers can always dereference `result` in postconditions to access the return value (using `operator*` and `operator->` as usual with `boost::optional`, and without having to explicitly check if `result` is an empty `boost::optional` object or not).
-This can be done ensuring that /all/ return statements in the function are of the form:
+This can be done ensuring that /all/ `return` statements in the function are of the form:
     
-    boost::optional<return_type> result;
+    boost::optional<``[^['return-type]]``> result;
     ...
-    return *(result = return_expr); // Assign `result` at each return.
+    return *(result = ``[^['return-expression]]``); // Assign `result` at each return.
 
 [heading Optional Results in Virtual Public Functions]
 
@@ -124,8 +124,8 @@ In addition, programmers are encouraged to declare the postcondition functor to
 [section Private and Protected Functions]
 
 Private and protected functions do not check class invariants (because they are not part of the public class interface) and they do not subcontract (because they are not accessible at the calling site where the __substitution_principle__ applies, see __Function_Calls__).
-However, programmers may still want to specify preconditions and postconditions for private and protected functions when they want to check correctness of their implementation and usage from within the class, base classes, and friend classes or functions.
-When programmers decide to specify contracts for private and protected functions, they shall use [funcref boost::contract::function] (because, like for non-member functions, this does not check class invariants and does not subcontract).
+However, programmers may still want to specify preconditions and postconditions for private and protected functions when they want to check correctness of their implementation and use (from within the class, base classes, friend classes or functions, etc.).
+When programmers decide to specify contracts for private and protected functions, they can use [funcref boost::contract::function] (because, like for non-member functions, this does not check class invariants and does not subcontract).
 For example (see [@../../example/features/private_protected.cpp =private_protected.cpp=]):
 
 [import ../example/features/private_protected.cpp]
@@ -146,7 +146,7 @@ For example (see [@../../example/features/private_protected_virtual.cpp =private
 [import ../example/features/private_protected_virtual.cpp]
 [private_protected_virtual_counter]
 
-However, public functions in derived classes overriding private or protected virtual functions from base classes shall not specify the extra `override_...` template parameter to [funcref boost::contract::public_function] because the overridden functions are private or protected and, not being public, they do not participate to subcontracting (this library will generate a compile-time error if `override_...` is specified because there will be no virtual public function to override from the base class).
+However, public functions in derived classes overriding private or protected virtual functions from base classes shall not specify the extra `override_...` template parameter to [funcref boost::contract::public_function] because the overridden functions are private or protected and, not being public, they do not participate to subcontracting (this library will generate a compile-time error if `override_...` is specified because there will be no virtual /public/ function to override from the base class).
 For example (see [@../../example/features/private_protected_virtual.cpp =private_protected_virtual.cpp=]):
 
 [private_protected_virtual_counter10]
@@ -162,14 +162,14 @@ For example (see [@../../example/features/private_protected_virtual_multi.cpp =p
 [warning
 Unfortunately, the code above does not compile on MSVC (at least up to Visual Studio 2015) because MSVC incorrectly gives a compile-time error when SFINAE fails due to private or protected access levels.
 Instead, GCC and Clang correctly implement SFINAE failures due to private and protected functions so the code above correctly complies on GCC and Clang.
-Therefore, currently it is not possible to override a function that is public in one base but private or protected in other base using this library on MSVC, but that can correctly be done on GCC or Clang instead.
+Therefore, currently it is not possible to override a function that is public in one base but private or protected in other base using this library on MSVC (at least up to Visual Studio 2015), but that can correctly be done on GCC or Clang instead.
 ]
 
 [endsect]
 
 [section Friend Functions]
 
-Friend functions are not member functions so [funcref boost::contract::function] can used to program contracts for them and all considerations made in __Non_Member_Functions__ apply.
+In general, friend functions are not member functions so [funcref boost::contract::function] is used to program their contracts and all considerations made in __Non_Member_Functions__ apply.
 For example (see [@../../example/features/friend.cpp =friend.cpp=]):
 
 [import ../example/features/friend.cpp]
@@ -184,7 +184,7 @@ For example (see [@../../example/features/friend_invariant.cpp =friend_invariant
 Contract programming proposals for C++ like __N1962__ do not provide a mechanism for friend functions to check class invariants of objects passed as parameters.
 In other words, these proposals do not enable contracts to recognize that in C++ some friend functions logically act as if they were part of the public interface of the objects they take as parameters.
 This is reasonable for proposals that add contracts to the core language because friend functions are not always meant to extend an object public interface and C++ does not provide a mechanism to programmatically specify when they do and when they do not.
-However, this library adds the flexibility to let programmers manually specify when friend functions should also check class invariants of the objects they take as parameters (using [funcref boost::contract::public_function]) and when they should not (using [funcref boost::contract::function] instead).
+However, this library provides the flexibility to let programmers manually specify when friend functions should also check class invariants of the objects they take as parameters (using [funcref boost::contract::public_function]) and when they should not (using [funcref boost::contract::function] instead).
 ]
 
 [import ../example/features/friend_invariant.cpp]
@@ -206,7 +206,7 @@ For example:
         boost::contract::check inv1 = boost::contract::public_function(&object1);
         boost::contract::check inv2 = boost::contract::public_function(object2);
         // Check postconditions and exception guarantees.
-        boost::contract::check post_except = boost::contract::function()
+        boost::contract::check postex = boost::contract::function()
             .postcondition(...)
             .except(...)
         ;
@@ -215,7 +215,7 @@ For example:
     }
 
 Changing the order of the [classref boost::contract::check] declarations above, programmers can chose the order for checking class invariants among the different objects passed to the friend function and also whether to check these invariants before or after preconditions, postconditions, and exception guarantees of the friend function (see __Non_Member_Functions__ and __Public_Functions__ for information on how the RAII objects returned by [funcref boost::contract::function] and [funcref boost::contract::public_function] check contract conditions).
-The example above is programmed to check `class1` invariants before `class2` invariants (but the order could have been inverted if programmers so chose).
+The example above is programmed to check `class1` invariants before `class2` invariants (but that order could have been inverted if programmers so chose).
 
 [note
 In the example above, preconditions are intentionally programmed to be checked before class invariants so the objects passed to the friend function can be validated by the preconditions before they are passed as pointers to [funcref boost::contract::public_function] (e.g., check `object2` is not null).
@@ -269,11 +269,11 @@ For example (see [@../../example/features/code_block.cpp =code_block.cpp=]):
 [import ../example/features/code_block.cpp]
 [code_block]
 
-Finally, at the moment this library does not support contracts for functions and classes declared `constexpr`.
+The library does not support contracts for functions and classes declared `constexpr`.
 [footnote
 *Rationale:*
 In general, it might be useful to specify contracts for `constexpr` functions and literal classes.
-However, the implementation of this library cannot support contracts for `constexpr` functions and classes because C++ does not currently allow `constexpr` functions to do the following:
+However, the current implementation of this library cannot support contracts for `constexpr` functions and classes because C++ does not currently allow `constexpr` functions to do the following:
 Declare local variables of (literal) types with non-trivial `constexpr` destructors (this RAII technique is used by this library to check invariants, postconditions, and exceptions guarantees at exit);
 Call other `constexpr` functions using try-catch statements (used by this library to report contract assertion failures and catch any other exception that might be thrown when evaluating the asserted conditions);
 Use lambda functions (used by this library for convenience to program functors that that check preconditions, postconditions, and exception guarantees).
@@ -284,34 +284,34 @@ Also note that even if supported, contracts for `constexpr` functions probably w
 
 [section Implementation Checks]
 
-This library provides a mechanism to check assertions within implementation code a part from preconditions, postconditions, exceptions guarantees, and class invariants.
-Implementation checks are programmed using a nullary functor that is directly assigned to a [classref boost::contract::check] object declaration right at the place within the code where the checks need to be performed (without calling [funcref boost::contract::function], [funcref boost::contract::public_function], etc. in this case).
+This library provides also a mechanism to check assertions within implementation code (differently from preconditions, postconditions, exceptions guarantees, and class invariants that are instead checked before or after code that implements a function body).
+These /implementation checks/ are programmed using a nullary functor that is directly assigned to a [classref boost::contract::check] object declaration right at the place within the code where the checks need to be performed (without calling [funcref boost::contract::function], [funcref boost::contract::public_function], etc. in this case).
 For example (see [@ ../../example/features/check.cpp =check.cpp=]):
 
 [import ../example/features/check.cpp]
 [check]
 
-The implementation check functor should capture all the variables that it needs to assert the implementation checks.
+The implementation check functor should capture all the variables that it needs for its assertions.
 These variables can be captured by value when the overhead of copying such variables is acceptable.
-In any case, implementation checks should not modify the value of the captured variables, even when those are captured by reference (see __Constant_Correctness__).
+In any case, programmers should not write implementation checks that modify the value of the captured variables, even when those are captured by reference (see __Constant_Correctness__).
 
 Any code can be programmed in the implementation check functor, but it is recommended to keep this code simple using mainly assertions and if-statements (to avoid programming complex checks that might be buggy and also slow to check at run-time).
-It is also recommended to use [macroref BOOST_CONTRACT_ASSERT] to program the assertions because that enables this library to print informative error messages when the asserted conditions are evaluated to be false (this is not a variadic macro, see __No_Macros__):
+It is also recommended to use [macroref BOOST_CONTRACT_ASSERT] to program the assertions because that enables this library to print informative error messages when the asserted conditions are evaluated to be false (note that this is not a variadic macro, see __No_Macros__):
     
-    BOOST_CONTRACT_ASSERT(bool_cond)
-    // Or, if `bool_cond` contains commas `,` not already within parenthesis `()`...
-    BOOST_CONTRACT_ASSERT((bool_cond)) // ...use extra parenthesis (not a variadic macro).
+    BOOST_CONTRACT_ASSERT(``[^['boolean-condition]]``)
+    // Or, if `boolean-condition` contains commas `,` not already within parenthesis `()`...
+    BOOST_CONTRACT_ASSERT((``[^['boolean-condition]]``)) // ...use extra parenthesis (not a variadic macro).
 
-This library will automatically call the failure handler [funcref boost::contract::check_failure] if any of the [macroref BOOST_CONTRACT_ASSERT] conditions are false and, more in general, if calling the implementation check functor throws any exception.
+This library will automatically call the failure handler [funcref boost::contract::check_failure] if any of the [macroref BOOST_CONTRACT_ASSERT] conditions are false or, more in general, if calling the implementation check functor throws any exception.
 By default, this failure handler prints an error message to `std::cerr` and terminates the program calling `std::terminate` (see __Throw_on_Failures__ to change the failure handler to throw exceptions, exit the program with an error code, etc.).
 
-Similarly to the C-style `assert` macro that is disable when `NDEBUG` is defined, implementation checks are disabled when [macroref BOOST_CONTRACT_NO_CHECKS] is defined.
+Similarly to the C-style `assert` macro that is disabled when `NDEBUG` is defined, implementation checks are disabled when [macroref BOOST_CONTRACT_NO_CHECKS] is defined (see __Disable_Contract_Checking__).
 That will skip all implementation checks at run-time but it will not eliminate some of the overhead of executing and compiling the related [classref boost::contract::check] declarations.
-Alternatively, this library provides the [macroref BOOST_CONTRACT_CHECK] macro that allows to completely remove run- and compile-time overhead of implementation checks when [macroref BOOST_CONTRACT_NO_CHECKS] is defined (this is not a variadic macro):
+Alternatively, this library provides the [macroref BOOST_CONTRACT_CHECK] macro that allows to completely remove run- and compile-time overheads of implementation checks when [macroref BOOST_CONTRACT_NO_CHECKS] is defined (note that this is not a variadic macro):
 
-    BOOST_CONTRACT_CHECK(bool_cond)
-    // Or, if `bool_cond` contains commas `,` not already within parenthesis `()`...
-    BOOST_CONTRACT_CHECK((bool_cond)) // ...use extra parenthesis (not a variadic macro).
+    BOOST_CONTRACT_CHECK(``[^['boolean-condition]]``)
+    // Or, if `boolean-condition` contains commas `,` not already within parenthesis `()`...
+    BOOST_CONTRACT_CHECK((``[^['boolean-condition]]``)) // ...use extra parenthesis (not a variadic macro).
 
 For example (see [@ ../../example/features/check_macro.cpp =check_macro.cpp=]):
 
@@ -320,27 +320,31 @@ For example (see [@ ../../example/features/check_macro.cpp =check_macro.cpp=]):
 
 The [macroref BOOST_CONTRACT_CHECK] macro is similar to the C-style assert macro as it accepts a boolean condition (instead of a nullary functor like [classref boost::contract::check] does).
 [footnote
-Of course, nothing prevents programmers from calling functors to specify boolean conditions when if-guards and other statements are required to assert the implementation checks.
-For example, programmers can use C++11 lambda functions to define and call such functors in place where the implementation checks are specified `BOOST_CONTRACT_CHECK([...] -> bool { ... } ())`.
+Of course, nothing prevents programmers from calling functors within [macroref BOOST_CONTRACT_CHECK] to specify boolean conditions when if-guards and other statements are required to assert the implementation checks.
+For example, programmers can use C++11 lambda functions to define and call such functors in place where the implementation checks are specified:
+``
+    BOOST_CONTRACT_CHECK([&] -> bool {
+        if(even_numbers) return gcd(x, y) == 2;
+        else return gcd(x, y) == 3;
+    } ());
+``
 ]
 Using [macroref BOOST_CONTRACT_CHECK] is essentially equivalent to using the C-style `assert` macro a part from the following:
 
 * Implementation checks are disabled defining [macroref BOOST_CONTRACT_NO_CHECKS] (instead of `NDEBUG` for disabling `assert`).
-* If the asserted boolean condition is either false or it throws an exception then this library will call [funcref boost::contract::check_failure] (instead `assert` calls `std::abort` if the asserted condition is false and unwinds the stack if evaluating the condition throws an exception).
+* If the asserted boolean condition is either false or it throws an exception then this library will call [funcref boost::contract::check_failure] (instead `assert` calls `std::abort` if the asserted condition is false and it unwinds the stack if evaluating the condition throws an exception).
 * Implementation checks are automatically disabled when other contract conditions specified using this library are already being checked (to avoid infinite recursion, see [macroref BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION]).
 
-(See __Disable_Contract_Checking__ and __Disable_Contract_Compilation__ for macros to completely remove run- and compile-time overhead also for preconditions, postconditions, exception guarantees, and class invariants.)
-
 [endsect]
 
-[section Old Value Copies at Body]
+[section Old Values Copied at Body]
 
 In the examples seen so far, old value variables of type [classref boost::contract::old_ptr] are initialized to a copy of the expression passed to [macroref BOOST_CONTRACT_OLDOF] as soon as they are declared.
-This is correctly happens before the function body is executed but also before the contract is declared, therefore even before class invariants (for public functions) and preconditions are checked at function entry.
-This might work well in most practical cases, however technically old values should be copied before executing the function body but /after/ checking entry class invariants and preconditions (see __Assertions__).
+That correctly happens before the function body is executed but also before the contract is declared, therefore even before class invariants (for public functions) and preconditions are checked at function entry.
+This might work well in most practical cases however, technically speaking, old values should be copied before executing the function body but /after/ checking class invariants and preconditions at function entry (see __Assertions__).
 Specifically, there could be cases in which it makes sense to evaluate the expressions passed to [macroref BOOST_CONTRACT_OLDOF] only under the assumption that assertions programmed in class invariants and preconditions are true.
 
-This library allows to construct [classref boost::contract::old_ptr] variables using their default constructor (equivalent to a null pointer) and then to later assign them to a copy of the expression passed to [macroref BOOST_CONTRACT_OLDOF] in a nullary functor [^['d]]`()` passed to `.old(`[^['d]]`)`.
+This library allows to construct [classref boost::contract::old_ptr] variables using their default constructor (equivalent to a null pointer) and then to later assign them to a copy of the expression specified by [macroref BOOST_CONTRACT_OLDOF] in a nullary functor [^['d]]`()` passed to `.old(`[^['d]]`)`.
 The functor [^['d]]`()` is called by this library before the function body is executed but only after class invariants and preconditions are checked.
 Old value assignments via `.old(...)` must appear after preconditions but before postconditions and exception guarantees wen these are all present (see __Preconditions__, __Postconditions__, and __Exception_Guarantees__).
 [footnote
@@ -351,15 +355,15 @@ The enforced order for specifying preconditions, old value assignments, postcond
 Other contract programming frameworks allow to mix this order, that could have been implemented for this library as well but it would have complicated somewhat the library implementation while adding no real value (arguably creating confusion in user code by not enforcing a consistent order for specifying contract conditions).
 ]
 
-For example, the following old value expression `s[index]` passed to [macroref BOOST_CONTRACT_OLDOF] is valid only after the precondition has checked that `index` is within valid range `index < s.size()`.
-Therefore, `old_y` is first declared using its default constructor (i.e., initialized to a null pointer) and later assigned to a copy of `s[index]` in `.old(...)` after the precondition has checked `index` (see [@../../example/features/old.cpp =old.cpp=]):
+For example, the following old value expression `s[index]` passed to [macroref BOOST_CONTRACT_OLDOF] is valid only after the precondition has checked that `index` is within the valid range `index < s.size()`.
+Therefore, `old_char` is first declared using its default constructor (i.e., initialized to a null pointer) and later assigned to a copy of `s[index]` in `.old(...)` after the precondition has checked `index` (see [@../../example/features/old.cpp =old.cpp=]):
 
 [import ../example/features/old.cpp]
 [old]
 
-The functor passed to `.old(...)` should capture all variables it needs to evaluate to copy the old value expressions passed to [macroref BOOST_CONTRACT_OLDOF].
-In general, these variables should be captured by reference and not by value (because old values need to make copies of the values the captured variables will have just before executing the function body, and not copy the values these variables had when the functor passed to `.old(...)` was first declared).
-In any case, the functor passed to `.old(...)` should modify only old values and not the values of other captured variables (see __Constant_Correctness__).
+The functor passed to `.old(...)` should capture all the variables that it needs to evaluate the old value expressions passed to [macroref BOOST_CONTRACT_OLDOF].
+In general, these variables should be captured by reference and not by value (because old values need to copy the values the captured variables will have just before executing the function body, and not the values these variables had when the functor passed to `.old(...)` was first declared).
+In any case, programmers should write the functor passed to `.old(...)` so that it modifies only old values and not the values of other captured variables, even when those are captured by reference (see __Constant_Correctness__).
 
 This library will automatically call the failure handler [funcref boost::contract::old_failure] if calling the functor specified via `.old(...)` throws an exception (by default, this handler prints an error message to `std::cerr` and terminates the program calling `std::terminate`, but see __Throw_on_Failures__ to throw exceptions, exit the program with an error code, etc.).
 
@@ -377,18 +381,18 @@ However, that will prevent this library from knowing the [enumref boost::contrac
 
 [section Named Overrides]
 
-As seen in __Public_Function_Overrides__, the [macroref BOOST_CONTRACT_OVERRIDE] macro has to be used to declare a type `override_...` that is passed to [funcref boost::contract::public_function] for public function overrides.
-The function names passed to [macroref BOOST_CONTRACT_OVERRIDE] (and [macroref BOOST_CONTRACT_OVERRIDES]) should never start with an underscore to avoid generating names containing double underscores `override__...` (which are reserved by the C++ standard).
+As seen in __Public_Function_Overrides__, the [macroref BOOST_CONTRACT_OVERRIDE] macro has to be used to declare the type `override_...` that is passed as an explicit template parameter to [funcref boost::contract::public_function] for public function overrides.
+The function names passed to [macroref BOOST_CONTRACT_OVERRIDE] (and [macroref BOOST_CONTRACT_OVERRIDES]) should never start with an underscore to avoid generating names containing double underscores `override__...` (because all symbols containing double underscores `...__...` are reserved symbols in the C++ standard).
 There is a separate macro [macroref BOOST_CONTRACT_NAMED_OVERRIDE] that can be used to explicitly specify the name of the type being declared:
 [footnote
 *Rationale:*
 A different macro [macroref BOOST_CONTRACT_NAMED_OVERRIDE] is used instead of overloading [macroref BOOST_CONTRACT_OVERRIDE] using variadic macros because the override macro cannot be programmed manually by users so making it a variadic would prevent to use this library on compilers that do not support variadic macros (see __No_Macros__).
 ]
 
-    BOOST_CONTRACT_OVERRIDE(func_name)                  // Generate `override_...`.
-    BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name) // Generate `type_name`.
+    BOOST_CONTRACT_OVERRIDE(``[^['function-name]]``)                  // Generate `override_...`.
+    BOOST_CONTRACT_NAMED_OVERRIDE(``[^['type-name]]``, ``[^['function-name]]``) // Generate `type-name`.
 
-For example, the following public function override is named `_1` so `BOOST_CONTRACT_OVERRIDE(_1)` would declare a type named `override__1` (which is reserved in C++ because it contains double underscores `__`). thus `BOOST_CONTRACT_NAMED_OVERRIDE(override1, _1)` is used to name the type `override1` instead (see [@../../example/features/named_override.cpp =named_override.cpp=]):
+For example, the following public function override is named `_1` so `BOOST_CONTRACT_OVERRIDE(_1)` would declare a type named `override__1` (which is reserved symbol in C++ because it contains a double underscore `__`), thus `BOOST_CONTRACT_NAMED_OVERRIDE(override1, _1)` is used to name the type `override1` instead (see [@../../example/features/named_override.cpp =named_override.cpp=]):
 
 [named_override]
 
@@ -405,14 +409,14 @@ The authors found such a syntax less readable than repeating single [macroref BO
 
 [section Access Specifiers]
 
-As we have seen so far, programmers are required to decorate their classes declaring the following extra members that are internally used by this library to check contracts:
+As seen thus far, this library requires programmers to decorate their classes declaring the following extra members:
 
 * The `invariant` and `static_invariant` member functions (used to check class invariants, see __Class_Invariants__).
-* The `base_types` member type declared via [macroref BOOST_CONTRACT_BASE_TYPES] (used to implement subcontracting, see __Public_Function_Overrides__).
+* The `base_types` member `typedef` declared via [macroref BOOST_CONTRACT_BASE_TYPES] (used to implement subcontracting, see __Public_Function_Overrides__).
 * The `override_...` member types declared via [macroref BOOST_CONTRACT_OVERRIDE], [macroref BOOST_CONTRACT_NAMED_OVERRIDE], and [macroref BOOST_CONTRACT_OVERRIDES] (used to implement subcontracting for overriding functions, see __Public_Function_Overrides__).
 [footnote
 *Rationale:*
-The internals of the `override_...` type generated by [macroref BOOST_CONTRACT_OVERRIDE] use names reserved by this library so programmers should not actually use such a type even when it is declared `public`.
+Note that the internals of the `override_...` type generated by [macroref BOOST_CONTRACT_OVERRIDE] use names reserved by this library so programmers should not actually use such a type even when it is declared `public`.
 ]
 
 In general, these members must be declared `public` in the user class in order for this library to be able to access them.
@@ -421,7 +425,7 @@ There is some variability among compiler implementations:
 The `base_types` member type needs to be declared `public` on MSVC, GCC, and Clang;
 The `invariant` and `static_invariant` member functions need to be declared `public` on MSVC, but not on GCC and Clang;
 The `override_...` member types do not have to be declared `public` on any compiler.
-In any case, declaring the [classref boost::contract::access] class `friend` as shown in this section allows to always declare the extra members `private` on all compilers.
+In any case, declaring these extra members all `public` or all `private` when the [classref boost::contract::access] class is also declared `friend` always works on all compilers.
 ]
 However, programmers might need to more precisely control the public members of their classes to prevent incorrect access of encapsulated members.
 All these members can be declared `private` as long as the [classref boost::contract::access] class is declared as `friend` of the user class.
@@ -430,7 +434,8 @@ For example (see [@../../example/features/access.cpp =access.cpp=]):
 [import ../example/features/access.cpp]
 [access]
 
-This technique is not used in most examples of this documentation only for brevity, but programmers are encouraged to use it in real code.
+This technique is not used in most examples of this documentation only for brevity.
+Programmers are encouraged to use [classref boost::contract::access] in real production code freely as they see fit.
 
 [warning
 Not declaring [classref boost::contract::access] friend of user classes might cause compiler errors on some compilers (e.g., MSVC) because the private members needed to check the contracts will not be accessible.
@@ -448,15 +453,15 @@ If a condition checked using [macroref BOOST_CONTRACT_ASSERT] is evaluated to be
 * Postconditions: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from within `.postcondition(...)` call [funcref boost::contract::postcondition_failure].
 * Exceptions guarantees: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from within `.except(...)` call [funcref boost::contract::except_failure].
 * Class invariants: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from `invariant()` and `static_invariant()` call [funcref boost::contract::entry_invariant_failure] when checked at function entry and [funcref boost::contract::exit_invariant_failure] when checked at function exit.
-* Old value copies at body: Exceptions thrown from old value copies at body within `.old(...)` call [funcref boost::contract::old_failure].
+* Old values copied at body: Exceptions thrown from old values copied at body within `.old(...)` call [funcref boost::contract::old_failure].
 * Implementation checks: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from implementation checks `boost::contract::check c = `[^['nullary-functor]] and `BOOST_CONTRACT_CHECK(...)` call [funcref boost::contract::check_failure].
 
 By default, these contract failure handlers print a message to the standard error `std::cerr` and then terminate the program calling `std::terminate`.
 [footnote
 *Rationale:*
-In general, when a contract fails the only safe thing to do is to terminate program execution (because the contract failure indicates a bug in the program, and in general a buggy program will be in a state for which no operation can be successfully performed, so the program should be stopped as soon as possible).
+In general, when a contract fails the only safe thing to do is to terminate program execution (because the contract failure indicates a bug in the program, and in general a buggy program will be in a state for which no operation can be successfully and safely performed, so the program should be stopped as soon as possible).
 Therefore, this library terminates the program by default.
-However, for specific applications, programmers could implement some fail-safe mechanism for which some mission-critical operation could always be performed upon handling failures so this library allows programmers to override the default contract failure handlers to fully customize how to handle contract failures.
+However, for specific applications, programmers could implement some fail-safe mechanism for which some mission-critical operations could always be performed upon handling failures so this library allows programmers to override the default contract failure handlers to fully customize how to handle contract failures.
 ]
 However, programmers can override the default contract failure handlers to perform any custom action on contract failure using the following functions respectively:
 
@@ -464,10 +469,10 @@ However, programmers can override the default contract failure handlers to perfo
 * Postconditions: [funcref boost::contract::set_postcondition_failure].
 * Exception guarantees: [funcref boost::contract::set_except_failure].
 * Class invariants: [funcref boost::contract::set_entry_invariant_failure] and [funcref boost::contract::set_exit_invariant_failure], or [funcref boost::contract::set_invariant_failure] (to set both entry and exit invariant failure handlers at once for convenience).
-* Old value copies at body: [funcref boost::contract::set_old_failure].
+* Old values copied at body: [funcref boost::contract::set_old_failure].
 * Implementation checks: [funcref boost::contract::set_check_failure].
 
-These `set_..._failure(`[^['f]]`)` function calls return the contract failure handler functor [^['f]] that they take as input parameter.
+These `set_..._failure(`[^['f]]`)` function calls return a reference to the contract failure handler functor [^['f]] that they take as input parameter (so they can be concatenated).
 [footnote
 *Rationale:*
 The `set_..._failure` functions take a functor as parameter (to accept not just function pointers but also lambdas, binds, etc.) and they return this same functor as result so they can be concatenated (this interface is a bit different from `std::set_terminate`).
@@ -481,32 +486,37 @@ For example (see [@../../example/features/throw_on_failure.cpp =throw_on_failure
 When programming custom failure handlers that trow exceptions instead of terminating the program, programmers should be wary of the following:
 
 * In order to comply with C++ and STL exception safety, destructors should never throw (in fact destructors are implicitly declared `noexcept` since C++11).
-This library passes a [enumref boost::contract::from] parameter to the contract failure handlers for preconditions, postconditions, class invariants, and old value copies at body (see [funcref boost::contract::precondition_failure], [funcref boost::contract::postcondition_failure], [funcref boost::contract::entry_invariant_failure], [funcref boost::contract::exit_invariant_failure], and [funcref boost::contract::old_failure] respectively).
+This library passes a [enumref boost::contract::from] parameter to the contract failure handlers for preconditions, postconditions, class invariants, and old values copied at body (see [funcref boost::contract::precondition_failure], [funcref boost::contract::postcondition_failure], [funcref boost::contract::entry_invariant_failure], [funcref boost::contract::exit_invariant_failure], and [funcref boost::contract::old_failure] respectively).
 This [enumref boost::contract::from] parameter indicates if the contract failure occurred in a destructor, constructor, or function call so programmers can use it to code custom contract failure hander functions that never throw from destructors.
-(In the example above, contract failures from destructors are simply ignored even if that is probably never a safe thing to do in real code.)
+(In the example above, contract failures from destructors are simply ignored even if that is probably never a safe thing to do in real production code.)
 * C++ stack-unwinding will execute base class destructors even when the derived class destructor trows an exception.
 Therefore, the contracts of base class destructors will continue to be checked when contract failure handlers are programmed to throw exceptions on contract failures from destructors (yet another reason not to throw exceptions from destructors, not even because of contract failures).
-* Implementation checks can appear in any code, including destructor implementation code, so [funcref boost::contract::check_failure] should also never throw, or implementation checks should never be used in destructors otherwise these destructors will throw (note that [funcref boost::contract::check_failure] does not provide the [enumref boost::contract::from] parameter so it is not possible to differentiate from implementation checks failing from destructors instead than from other parts of the code).
 * The contract failure handler for exception guarantees [funcref boost::contract::except_failure] should never throw (regardless of the value of its [enumref boost::contract::from] parameter) because when [funcref boost::contract::except_failure] is called there is already an active exception on the stack, the exception that triggered the exception guarantees to be checked in the first place (throwing an exception while there is already an active exception will force program termination or lead to undefined behaviour in C++).
+* Implementation checks can appear in any code, including destructor implementation code, so [funcref boost::contract::check_failure] should also never throw, or implementation checks should never be used in destructors otherwise these destructors will throw (note that [funcref boost::contract::check_failure] does not provide the [enumref boost::contract::from] parameter so it is not possible to differentiate from implementation checks failing from destructors instead than from other parts of the code).
 
 [note
-It is the responsibility of the programmers to decide how to handle contract failures from destructors when they program custom contract failure handlers that throw exceptions instead of terminating the program (given that C++ and STL exception safety rules requires destructors to never throw).
+Programmers need to decide how to handle contract failures from destructors when they write custom contract failure handlers that throw exceptions instead of terminating the program (given that C++ and STL exception safety rules requires destructors to never throw).
 This is not a simple dilemma and it might be a good reason to terminate the program instead of throwing exceptions when assertions fail in C++ (as this library and also C-style `assert` do by default).
 ]
 
+[heading Throw User-Defined Exceptions]
+
 Contract assertions can be programmed to throw [classref boost::contract::assertion_failure] using `BOOST_CONTRACT_ASSERT(`[^['condition]]`)` as we have seen so far (see __No_Macros__).
 Alternatively, contract assertions can be programmed to throw any other exception (including user-defined exceptions) using code similar to the following:
 
     if(!``[^['condition]]``) throw ``[^['exception-object]]``;
 
-For example, the following precondition functor throws [classref boost::contract:assertion_failure] (via [macroref BOOST_CONTRACT_ASSERT]) on its first assertion and the user-defined exception `too_large_error` on its second assertion (both exceptions will cause this library to call the customized [funcref boost::contract::precondition_failure] listed above which will in turn re-throw the exceptions up he stack, see [@../../example/features/throw_on_failure.cpp =throw_on_failure.cpp=]):
+For example, the following precondition functor throws [classref boost::contract::assertion_failure] (via [macroref BOOST_CONTRACT_ASSERT]) on its first assertion and the user-defined exception `too_large_error` on its second assertion (both exceptions will cause this library to call the customized [funcref boost::contract::precondition_failure] listed above which will in turn re-throw the exceptions up the stack, see [@../../example/features/throw_on_failure.cpp =throw_on_failure.cpp=]):
 
 [throw_on_failure_class_begin]
 [throw_on_failure_ctor]
 [throw_on_failure_class_end]
 
-Finally, note that the exception specifiers `noexcept` (since C++11) and `throw` (deprecated in C++11) of the enclosing operation declaring the contract correctly apply to the contract code as well.
+[heading Exception Specifiers (`noexcept` and `throw``)]
+
+Exception specifiers `noexcept` (since C++11) and `throw` (deprecated in C++11) of the enclosing function, constructor, or destructor declaring the contract correctly apply to the contract code as well.
 Therefore, even if the contract failure handlers are reprogrammed to throw exceptions in case of contract failures, those exceptions will never be thrown outside the context of the enclosing operation if that is not in accordance with the exception specifiers of that operation (specifically, note that all destructors are implicitly declared `noexcept` in C++11).
+
 For example, the following code will correctly never throw from the `noexcept` destructor, not even if the class invariants checked at destructor entry throw `too_large_error` and the contract failure handlers for invariants are programmed to throw from destructors (the program will always terminate in this case instead, see [@../../example/features/throw_on_failure.cpp =throw_on_failure.cpp=]):
 
 [throw_on_failure_class_begin]