update boost

This commit is contained in:
2023-11-24 12:56:13 -06:00
parent cfc99971af
commit 19d727037a
9260 changed files with 849256 additions and 299957 deletions

View File

@@ -29,7 +29,10 @@ Assert contract conditions.
code that throws @RefClass{boost::contract::assertion_failure} with the
correct assertion file name (using <c>__FILE__</c>), line number (using
<c>__LINE__</c>), and asserted condition code so to produce informative
error messages.
error messages (C++11 <c>__func__</c> is not used here because in most cases
it will simply expand to the internal compiler name of the lambda function
used to program the contract conditions adding no specificity to the error
message).
@RefMacro{BOOST_CONTRACT_ASSERT}, @RefMacro{BOOST_CONTRACT_ASSERT_AUDIT},
and @RefMacro{BOOST_CONTRACT_ASSERT_AXIOM} are the three assertion levels
@@ -38,11 +41,12 @@ Assert contract conditions.
@see @RefSect{tutorial.preconditions, Preconditions},
@RefSect{tutorial.postconditions, Postconditions},
@RefSect{tutorial.exception_guarantees, Exceptions Guarantees},
@RefSect{tutorial.class_invariants, Class Invariants}
@RefSect{tutorial.class_invariants, Class Invariants},
@RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}
@param cond Boolean contract condition to check.
(This is not a variadic macro parameter so any comma it might
contain must be protected by round parenthesis,
contain must be protected by round parenthesis and
@c BOOST_CONTRACT_ASSERT((cond)) will always work.)
*/
// This must be an expression (a trivial one so the compiler can optimize it
@@ -64,7 +68,8 @@ Assert contract conditions.
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
/**
Preferred way to assert contract conditions that are computationally
expensive, at least compared to the cost of executing the function body.
expensive, at least compared to the computational cost of executing the
function body.
The asserted condition will always be compiled and validated syntactically,
but it will not be checked at run-time unless
@@ -87,11 +92,12 @@ Assert contract conditions.
If there is a need, programmers are free to implement their own assertion
levels defining macros similar to the one above.
@see @RefSect{extras.assertion_levels, Assertion Levels}
@see @RefSect{extras.assertion_levels, Assertion Levels},
@RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}
@param cond Boolean contract condition to check.
(This is not a variadic macro parameter so any comma it might
contain must be protected by round parenthesis,
contain must be protected by round parenthesis and
@c BOOST_CONTRACT_ASSERT_AUDIT((cond)) will always work.)
*/
#define BOOST_CONTRACT_ASSERT_AUDIT(cond)
@@ -104,8 +110,9 @@ Assert contract conditions.
#endif
/**
Preferred way to assert contract conditions that are computationally
prohibitive, at least compared to the cost of executing the function body.
Preferred way to document in the code contract conditions that are
computationally prohibitive, at least compared to the computational cost of
executing the function body.
The asserted condition will always be compiled and validated syntactically, but
it will never be checked at run-time.
@@ -122,11 +129,12 @@ by this library.
If there is a need, programmers are free to implement their own assertion levels
defining macros similar to the one above.
@see @RefSect{extras.assertion_levels, Assertion Levels}
@see @RefSect{extras.assertion_levels, Assertion Levels},
@RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}
@param cond Boolean contract condition to check.
(This is not a variadic macro parameter so any comma it might
contain must be protected by round parenthesis,
contain must be protected by round parenthesis and
@c BOOST_CONTRACT_ASSERT_AXIOM((cond)) will always work.)
*/
#define BOOST_CONTRACT_ASSERT_AXIOM(cond) \

View File

@@ -18,27 +18,27 @@ Specify inheritance form base classes (for subcontracting).
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
/**
Used to program a @c typedef listing the bases of a derived class.
Used to program the @c typedef that lists the bases of a derived class.
In order to support subcontracting, a derived class that specifies contracts for
one or more overriding public function must declare a @c typedef named
@c base_types (or @RefMacro{BOOST_CONTRACT_BASES_TYPEDEF}) using this macro.
one or more overriding public functions must declare a @c typedef named
@c base_types (or @RefMacro{BOOST_CONTRACT_BASES_TYPEDEF}) using this macro:
@code
class u :
class u
#define BASES public b, protected virtual w1, private w2
BASES
: BASES
{
friend class boost::contract:access;
typedef BOOST_CONTRACT_BASES(BASES) base_types;
typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
#undef BASES
...
};
@endcode
This @c typedef must be @c public if @RefClass{boost::contract::access} is not
This @c typedef must be @c public unless @RefClass{boost::contract::access} is
used.
@see @RefSect{tutorial.base_classes__subcontracting_, Base Classes}
@@ -52,7 +52,9 @@ used.
library).
This is a variadic macro parameter, on compilers that do not support
variadic macros, the @c typedef for base classes can be programmed
manually without using this macro.
manually without using this macro (see
@RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}).
*/
#define BOOST_CONTRACT_BASE_TYPES(...)

View File

@@ -10,8 +10,10 @@
/** @file
Statically disable compilation and execution of functor calls.
@note This facility allows to emulate C++17 <c>if constexpr</c> statements
when used together with functor templates (or C++14 generic lambdas).
@note These facilities allow to emulate C++17 <c>if constexpr</c> statements
when used together with functor templates (and C++14 generic lambdas).
Therefore, they are not useful on C++17 compilers where
<c> if constexpr</c> can be directly used instead.
*/
#include <boost/contract/detail/none.hpp>
@@ -43,7 +45,8 @@ namespace boost { namespace contract {
/**
Select compilation and execution of functor template calls using a static
boolean predicate.
boolean predicate (not needed on C++17 compilers, use <c>if constexpr</c>
instead).
This class template has no members because it is never used directly, it is only
used via its specializations.
@@ -73,14 +76,16 @@ struct call_if_statement {}; // Empty so cannot be used (but copyable).
/**
Template specialization to dispatch between then-branch functor template calls
that return void and the ones that return non-void.
that return void and the ones that return non-void (not needed on C++17
compilers, use <c>if constexpr</c> instead).
The base class is a call-if statement so the else and else-if statements can be
specified if needed.
Usually this class template is instantiated only via the return value of
@RefFunc{boost::contract::call_if} and @RefFunc{boost::contract::call_if_c}.
@note The <c>result_of<Then()>::type</c> expression should be evaluated only
@note The <c>result_of<Then()>::type</c> expression needs be evaluated only
when the static predicate is already checked to be @c true (because
@c Then() is required to compile only in that case).
Thus, this template specialization introduces an extra level of
@@ -126,7 +131,9 @@ struct call_if_statement<true, Then,
/**
Template specialization to handle static predicates that are @c true for
then-branch functor template calls that do not return void.
then-branch functor template calls that do not return void (not needed on C++17
compilers, use <c>if constexpr</c> instead).
Usually this class template is instantiated only via the return value of
@RefFunc{boost::contract::call_if} and @RefFunc{boost::contract::call_if_c}.
@@ -164,7 +171,7 @@ struct call_if_statement<true, Then, ThenResult> { // Copyable (as *).
Specify the else-branch functor template.
@param f Else-branch nullary functor template.
The functor template call @c f() is never compiled and executed
The functor template call @c f() is never compiled or executed
for this template specialization (because the if-statement
static predicate is @c true).
The return type of @c f() must be the same as (or implicitly
@@ -175,14 +182,18 @@ struct call_if_statement<true, Then, ThenResult> { // Copyable (as *).
executed).
*/
template<typename Else>
ThenResult else_(Else const& f) const { return *r_; }
ThenResult else_(Else const&
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
f
#endif
) const { return *r_; }
/**
Specify an else-if-branch functor template (using a static boolean
predicate).
@param f Else-if-branch nullary functor template.
The functor template call @c f() is never compiled and executed
The functor template call @c f() is never compiled or executed
for this template specialization (because the if-statement
static predicate is @c true).
The return type of @c f() must be the same as (or implicitly
@@ -198,15 +209,19 @@ struct call_if_statement<true, Then, ThenResult> { // Copyable (as *).
if-statement static predicate is @c true).
*/
template<bool ElseIfPred, typename ElseIfThen>
call_if_statement<true, Then, ThenResult> else_if_c(ElseIfThen const& f)
const { return *this; }
call_if_statement<true, Then, ThenResult> else_if_c(
ElseIfThen const&
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN // Avoid unused param warning.
f
#endif
) const { return *this; }
/**
Specify an else-if-branch functor template (using a nullary boolean
meta-function).
@param f Else-if-branch nullary functor template.
The functor template call @c f() is never compiled and executed
The functor template call @c f() is never compiled or executed
for this template specialization (because the if-statement
static predicate is @c true).
The return type of @c f() must be the same as (or implicitly
@@ -222,8 +237,12 @@ struct call_if_statement<true, Then, ThenResult> { // Copyable (as *).
if-statement static predicate is @c true).
*/
template<class ElseIfPred, typename ElseIfThen>
call_if_statement<true, Then, ThenResult> else_if(ElseIfThen const& f)
const { return *this; }
call_if_statement<true, Then, ThenResult> else_if(
ElseIfThen const&
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN // Avoid unused param warning.
f
#endif
) const { return *this; }
private:
boost::shared_ptr<ThenResult> r_;
@@ -231,7 +250,9 @@ private:
/**
Template specialization to handle static predicates that are @c true for
then-branch functor template calls that return void.
then-branch functor template calls that return void (not needed on C++17
compilers, use <c>if constexpr</c> instead).
Usually this class template is instantiated only via the return value of
@RefFunc{boost::contract::call_if} and @RefFunc{boost::contract::call_if_c}.
@@ -263,7 +284,7 @@ struct call_if_statement<true, Then, void> { // Copyable (no data).
Specify the else-branch functor template.
@param f Else-branch nullary functor template.
The functor template call @c f() is never compiled and executed
The functor template call @c f() is never compiled or executed
for this template specialization (because the if-statement
static predicate is @c true).
The return type of @c f() must be @c void for this template
@@ -271,14 +292,18 @@ struct call_if_statement<true, Then, void> { // Copyable (no data).
return void).
*/
template<typename Else>
void else_(Else const& f) const {}
void else_(Else const&
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
f
#endif
) const {}
/**
Specify an else-if-branch functor template (using a static boolean
predicate).
@param f Else-if-branch nullary functor template.
The functor template call @c f() is never compiled and executed
The functor template call @c f() is never compiled or executed
for this template specialization (because the if-statement
static predicate is @c true).
The return type of @c f() must be @c void for this template
@@ -294,16 +319,19 @@ struct call_if_statement<true, Then, void> { // Copyable (no data).
(because the then-branch functor template calls return void).
*/
template<bool ElseIfPred, typename ElseIfThen>
call_if_statement<true, Then, void> else_if_c(ElseIfThen const& f) const {
return *this;
}
call_if_statement<true, Then, void> else_if_c(
ElseIfThen const&
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN // Avoid unused param warning.
f
#endif
) const { return *this; }
/**
Specify an else-if-branch functor template (using a nullary boolean
meta-function).
@param f Else-if-branch nullary functor template.
The functor template call @c f() is never compiled and executed
The functor template call @c f() is never compiled or executed
for this template specialization (because the if-statement
static predicate is @c true).
The return type of @c f() must be @c void for this template
@@ -319,13 +347,17 @@ struct call_if_statement<true, Then, void> { // Copyable (no data).
(because the then-branch functor template calls return void).
*/
template<class ElseIfPred, typename ElseIfThen>
call_if_statement<true, Then, void> else_if(ElseIfThen const& f) const {
return *this;
}
call_if_statement<true, Then, void> else_if(
ElseIfThen const&
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN // Avoid unused param warning.
f
#endif
) const { return *this; }
};
/**
Template specialization to handle static predicates that are @c false.
Template specialization to handle static predicates that are @c false (not
needed on C++17 compilers, use <c>if constexpr</c> instead).
This template specialization handles all else-branch functor template calls
(whether they return void or not).
@@ -350,24 +382,28 @@ struct call_if_statement<false, Then,
Construct this object with the then-branch functor template.
@param f Then-branch nullary functor template.
The functor template call @c f() is never compiled and executed
The functor template call @c f() is never compiled or executed
for this template specialization (because the if-statement
static predicate is @c false).
The return type of @c f() must be the same as (or implicitly
convertible to) the return type of all other functor template
calls specified for this call-if object.
*/
explicit call_if_statement(Then const& f) {}
explicit call_if_statement(Then const&
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
f
#endif
) {}
// Do not provide `operator result_type()` here, require else_ instead.
/**
Specify the else-branch functor template.
@note The <c>result_of<Else()>::type</c> expression should be evaluated
@note The <c>result_of<Else()>::type</c> expression needs be evaluated
only when the static predicate is already checked to be @c false
(because @c Else() is required to compile only in that case).
Thus, this result-of expression is evaluated lazily only in
Thus, this result-of expression is evaluated lazily and only in
instantiations of this template specialization.
@param f Else-branch nullary functor template.
@@ -407,8 +443,8 @@ struct call_if_statement<false, Then,
@return A call-if statement so the else statement and additional else-if
statements can be specified if needed.
Eventually, this will be the return value of the functor template
call being compiled and executed.
Eventually, this will be the return value of the one functor
template call being compiled and executed.
*/
template<bool ElseIfPred, typename ElseIfThen>
call_if_statement<ElseIfPred, ElseIfThen> else_if_c(ElseIfThen f) const {
@@ -433,8 +469,8 @@ struct call_if_statement<false, Then,
@return A call-if statement so the else statement and additional else-if
statements can be specified if needed.
Eventually, this will be the return value of the functor template
call being compiled and executed.
Eventually, this will be the return value of the one functor
template call being compiled and executed.
*/
template<class ElseIfPred, typename ElseIfThen>
call_if_statement<ElseIfPred::value, ElseIfThen> else_if(ElseIfThen f)
@@ -445,7 +481,8 @@ struct call_if_statement<false, Then,
/**
Select compilation and execution of functor template calls using a static
boolean predicate.
boolean predicate (not needed on C++17 compilers, use <c>if constexpr</c>
instead).
Create a call-if object with the specified then-branch functor template:
@@ -481,8 +518,8 @@ returns non-void).
@return A call-if statement so else and else-if statements can be specified if
needed.
Eventually, this will be the return value of the functor template call
being compiled and executed (which can also be @c void).
Eventually, this will be the return value of the one functor template
call being compiled and executed (which could also be @c void).
*/
template<bool Pred, typename Then>
call_if_statement<Pred, Then> call_if_c(Then f) {
@@ -491,7 +528,8 @@ call_if_statement<Pred, Then> call_if_c(Then f) {
/**
Select compilation and execution of functor template calls using a nullary
boolean meta-function.
boolean meta-function (not needed on C++17 compilers, use <c>if constexpr</c>
instead).
This is equivalent to <c>boost::contract::call_if_c<Pred::value>(f)</c>.
Create a call-if object with the specified then-branch functor template:
@@ -528,8 +566,8 @@ returns non-void).
@return A call-if statement so else and else-if statements can be specified if
needed.
Eventually, this will be the return value of the functor template call
being compiled and executed (which can also be @c void).
Eventually, this will be the return value of the one functor template
call being compiled and executed (which could also be @c void).
*/
template<class Pred, typename Then>
call_if_statement<Pred::value, Then> call_if(Then f) {
@@ -538,16 +576,16 @@ call_if_statement<Pred::value, Then> call_if(Then f) {
/**
Select compilation and execution of a boolean functor template condition using a
static boolean predicate.
static boolean predicate (not needed on C++17 compilers, use
<c>if constexpr</c> instead).
Compile and execute the nullary boolean functor template call @c f() if and only
if the specified static boolean predicate @p Pred is @c true, otherwise
trivially return @p else_ (@c true by default) at run-time.
A call to <c>boost::contract::condition_if_c<Pred>(f, else_)</c> is logically
equivalent to
<c>boost::contract::call_if_c<Pred>(f, [else_] { return else_; })</c> (but
its internal implementation is optimized and it does not actually use
equivalent to <c>boost::contract::call_if_c<Pred>(f, [] { return else_; })</c>
(but its internal implementation is optimized and it does not actually use
@c call_if_c).
@see @RefSect{extras.assertion_requirements__templates_,
@@ -574,22 +612,23 @@ its internal implementation is optimized and it does not actually use
template<bool Pred, typename Then>
typename boost::enable_if_c<Pred, bool>::type
condition_if_c(Then f, bool else_ = true) { return f(); }
condition_if_c(Then f, bool /* else_ */ = true) { return f(); }
template<bool Pred, typename Then>
typename boost::disable_if_c<Pred, bool>::type
condition_if_c(Then f, bool else_ = true) { return else_; }
condition_if_c(Then /* f */, bool else_ = true) { return else_; }
#endif
/**
Select compilation and execution of a boolean functor template condition using a
nullary boolean meta-function.
nullary boolean meta-function (not needed on C++17 compilers, use
<c>if constexpr</c> instead).
This is equivalent to
<c>boost::contract::condition_if_c<Pred::value>(f, else_)</c>.
Compile and execute the nullary boolean functor template call @c f() if and only
if the specified nullary boolean meta-function @p Pred is @c true, otherwise
trivially return @p else_ (@c true by default) at run-time.
if the specified nullary boolean meta-function @p Pred::value is @c true,
otherwise trivially return @p else_ (@c true by default) at run-time.
@see @RefSect{extras.assertion_requirements__templates_,
Assertion Requirements}
@@ -603,8 +642,8 @@ trivially return @p else_ (@c true by default) at run-time.
@tparam Pred Nullary boolean meta-function selecting when the functor
template call @c f() should be compiled and executed.
@return Boolean value returned by @c f() if the static predicate @c Pred is
@c true. Otherwise, trivially return @p else_.
@return Boolean value returned by @c f() if the static predicate @c Pred::value
is @c true. Otherwise, trivially return @p else_.
*/
template<class Pred, typename Then>
bool condition_if(Then f, bool else_ = true) {

View File

@@ -61,17 +61,16 @@ This object enforces the following (see
@li Constructor entry never checks class invariants.
@li Destructor exit checks class invariants only if the body throws an
exception (even if destructors should usually not be programmed to throw
exceptions in C++).
exceptions in C++ and they are implicitly declared @c noexcept since C++11).
@li Static invariants are always checked at entry and exit (and regardless of
the body throwing exceptions or not).
When used this way, this object is usually constructed and initialized to the
return value of one of the contract functions
@RefFunc{boost::contract::function}, @RefFunc{boost::contract::constructor},
@RefFunc{boost::contract::destructor}, or
@RefFunc{boost::contract::public_function}.
In addition, this object can be constructed from a nullary functor that is used
to program implementation checks.
When used this way, this object is constructed and initialized to the return
value of one of the contract functions @RefFunc{boost::contract::function},
@RefFunc{boost::contract::constructor}, @RefFunc{boost::contract::destructor},
or @RefFunc{boost::contract::public_function}.
In addition to that, this object can be constructed from a nullary functor when
it is used to program implementation checks.
@see @RefSect{tutorial, Tutorial},
@RefSect{advanced.implementation_checks, Implementation Checks}
@@ -132,7 +131,7 @@ public:
/**
Construct this object to check the specified contract.
This checks class invariants at entry (if those apply to the specified
This checks class invariants at entry (if those were specified for the given
contract).
This constructor is not declared @c explicit so initializations can use
assignment syntax @c =.
@@ -149,8 +148,11 @@ public:
@tparam VirtualResult Return type of the enclosing function declaring the
contract if that is either a virtual or an
overriding public function.
Otherwise, this is always @c void.
overriding public function, otherwise this is always
@c void.
(Usually this template parameter is automatically
deduced by C++ and it does not need to be explicitly
specified by programmers.)
*/
template<typename VirtualResult>
/* implicit */ check
@@ -169,7 +171,7 @@ public:
Construct this object to check the specified contract.
This checks class invariants at entry and preconditions (if any of those
apply to the specified contract).
were specified for the given contract).
This constructor is not declared @c explicit so initializations can use
assignment syntax @c =.
@@ -187,8 +189,11 @@ public:
@tparam VirtualResult Return type of the enclosing function declaring the
contract if that is either a virtual or an
overriding public function.
Otherwise, this is always @c void.
overriding public function, otherwise this is always
@c void.
(Usually this template parameter is automatically
deduced by C++ and it does not need to be explicitly
specified by programmers.)
*/
template<typename VirtualResult>
/* implicit */ check
@@ -205,7 +210,8 @@ public:
Construct this object to check the specified contract.
This checks class invariants at entry and preconditions then it makes old
value copies at body (if any of those apply to the specified contract).
value copies at body (if any of those were specified for the given
contract).
This constructor is not declared @c explicit so initializations can use
assignment syntax @c =.
@@ -223,8 +229,11 @@ public:
@tparam VirtualResult Return type of the enclosing function declaring the
contract if that is either a virtual or an
overriding public function.
Otherwise, this is always @c void.
overriding public function, otherwise this is always
@c void.
(Usually this template parameter is automatically
deduced by C++ and it does not need to be explicitly
specified by programmers.)
*/
template<typename VirtualResult>
/* implicit */ check
@@ -241,8 +250,8 @@ public:
Construct this object to check the specified contract.
This checks class invariants at entry and preconditions then it makes old
value copies at body, plus the destructor of this object will check
postconditions in this case (if any of those apply to the specified
value copies at body, plus the destructor of this object will also check
postconditions in this case (if any of those were specified for the given
contract).
This constructor is not declared @c explicit so initializations can use
assignment syntax @c =.
@@ -261,8 +270,11 @@ public:
@tparam VirtualResult Return type of the enclosing function declaring the
contract if that is either a virtual or an
overriding public function.
Otherwise, this is always @c void.
overriding public function, otherwise this is always
@c void.
(Usually this template parameter is automatically
deduced by C++ and it does not need to be explicitly
specified by programmers.)
*/
/* implicit */ check
/** @cond */ BOOST_PREVENT_MACRO_SUBSTITUTION /** @endcond */ (
@@ -277,9 +289,9 @@ public:
Construct this object to check the specified contract.
This checks class invariants at entry and preconditions then it makes old
value copies at body, plus the destructor of this object will check
postconditions and exception guarantees in this case (if any of those apply
to the specified contract).
value copies at body, plus the destructor of this object will also check
postconditions and exception guarantees in this case (if any of those were
specified for the given contract).
This constructor is not declared @c explicit so initializations can use
assignment syntax @c =.
@@ -297,8 +309,11 @@ public:
@tparam VirtualResult Return type of the enclosing function declaring the
contract if that is either a virtual or an
overriding public function.
Otherwise, this is always @c void.
overriding public function, otherwise this is always
@c void.
(Usually this template parameter is automatically
deduced by C++ and it does not need to be explicitly
specified by programmers.)
*/
/* implicit */ check
/** @cond */ BOOST_PREVENT_MACRO_SUBSTITUTION /** @endcond */ (
@@ -314,9 +329,10 @@ public:
This checks class invariants at exit and either postconditions when the
enclosing function body did not throw an exception, or exception guarantees
when the function body threw an exception (that is if class invariants,
postconditions, and exception guarantees respectively apply to the contract
parameter specified when constructing this object).
when the function body threw an exception (if class invariants,
postconditions, and exception guarantees respectively were specified for the
enclosing class and the contract parameter given when constructing this
object).
@b Throws: This can throw in case programmers specify contract failure
handlers that throw exceptions instead of terminating the

View File

@@ -29,7 +29,7 @@ Program contracts for constructors.
This is used to specify postconditions, exception guarantees, old value copies
at body, and check class invariants for constructors (see
@RefClass{boost::contract::constructor_precondition} to specify preconditions
for constructors instead):
for constructors):
@code
class u {
@@ -44,7 +44,7 @@ public:
u(...) {
boost::contract::old_ptr<old_type> old_var;
boost::contract::check c = boost::contract::constructor(this)
// No `.precondition` (use `constructor_precondition` if needed).
// No `.precondition` (use `constructor_precondition` instead).
.old([&] { // Optional.
old_var = BOOST_CONTRACT_OLDOF(old_expr);
...
@@ -84,10 +84,11 @@ postconditions and exception guarantees, within classes that have no invariants.
(Usually this template parameter is automatically deduced by C++
and it does not need to be explicitly specified by programmers.)
@return The result of this function must be explicitly assigned to a variable of
type @RefClass{boost::contract::check} declared locally just before the
code of the constructor body (otherwise this library will generate a
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code of
the constructor body (otherwise this library will generate a run-time
error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
template<class Class>
specify_old_postcondition_except<> constructor(Class* obj) {

View File

@@ -43,23 +43,24 @@ namespace boost { namespace contract {
#endif
/**
Friend this class to declare invariants and base types as private members.
Declare this class as friend to program invariants and base types as private
members.
Declare this class a friend of the user-defined class specifying the contracts
in order to declare the invariant functions and the base types @c typedef as
and then invariant functions and the base types @c typedef can be declared as
non-public members:
@code
class u :
class u
#define BASES public b, private w
BASES
: BASES
{
friend class boost::contract::access;
typedef BOOST_CONTRACT_BASES(BASES) base_types; // Private.
typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Private.
#undef BASES
void invariant() const { ... } // Private.
void invariant() const { ... } // Private (same for static and volatile).
public:
...
@@ -67,9 +68,10 @@ public:
@endcode
In real code, programmers will likely chose to declare this class as friend so
to fully control public interfaces of their user-defined classes.
to fully control public interfaces of their user-defined classes (this is not
extensively done in the examples of this documentation only for brevity).
This class is not intended to be directly used by programmers a part from
declaring it @c friend (and that is why this class does not have any public
being declared as @c friend (and that is why this class does not have any public
member and it is not copyable).
@warning Not declaring this class friend of user-defined classes will cause
@@ -79,8 +81,8 @@ member and it is not copyable).
instead fail SFINAE and no compiler error will be reported while
invariants and subcontracting will be silently skipped at run-time.
Therefore, programmers must make sure to either declare this class
as friend (preferred) or to always declare invariant functions and
base types @c typedef as public members.
as friend or to always declare invariant functions and base types
@c typedef as public members.
@see @RefSect{advanced.access_specifiers, Access Specifiers}
*/

View File

@@ -27,7 +27,7 @@ Macros for implementation checks.
@code
void f() {
...
BOOST_CONTRACT_CHECK(...);
BOOST_CONTRACT_CHECK(cond);
...
}
@endcode
@@ -41,7 +41,7 @@ Macros for implementation checks.
@param cond Boolean condition to check within implementation code (function
body, etc.).
(This is not a variadic macro parameter so any comma it might
contain must be protected by round parenthesis,
contain must be protected by round parenthesis and
@c BOOST_CONTRACT_CHECK((cond)) will always work.)
*/
#define BOOST_CONTRACT_CHECK(cond)
@@ -58,11 +58,11 @@ Macros for implementation checks.
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
/**
Preferred way to assert implementation check conditions that are
computationally expensive, at least compared to the cost of executing the
function body.
computationally expensive, at least compared to the computational cost of
executing the function body.
The specified condition will always be compiled and validated
syntactically, but it will not be evaluated at run-time unless
The specified condition will always be compiled and validated syntactically,
but it will not be checked at run-time unless
@RefMacro{BOOST_CONTRACT_AUDITS} is defined (undefined by default).
This macro is defined by code equivalent to:
@@ -87,7 +87,7 @@ Macros for implementation checks.
@param cond Boolean condition to check within implementation code (function
body, etc.).
(This is not a variadic macro parameter so any comma it might
contain must be protected by round parenthesis,
contain must be protected by round parenthesis and
@c BOOST_CONTRACT_CHECK_AUDIT((cond)) will always work.)
*/
#define BOOST_CONTRACT_CHECK_AUDIT(cond)
@@ -100,11 +100,12 @@ Macros for implementation checks.
#endif
/**
Preferred way to assert implementation check conditions that are computationally
prohibitive, at least compared to the cost of executing the function body.
Preferred way to document in the code implementation check conditions that are
computationally prohibitive, at least compared to the computational cost of
executing the function body.
The specified condition will always be compiled and validated
syntactically, but it will never be evaluated at run-time.
The specified condition will always be compiled and validated syntactically, but
it will never be checked at run-time.
This macro is defined by code equivalent to:
@code
@@ -123,7 +124,7 @@ defining macros similar to the one above.
@param cond Boolean condition to check within implementation code (function
body, etc.).
(This is not a variadic macro parameter so any comma it might
contain must be protected by round parenthesis,
contain must be protected by round parenthesis and
@c BOOST_CONTRACT_CHECK_AXIOM((cond)) will always work.)
*/
#define BOOST_CONTRACT_CHECK_AXIOM(cond) \

View File

@@ -33,21 +33,19 @@ Configure this library compile-time and run-time behaviours.
If this macro is defined, this library is compiled so it can be linked
as a shared library (a.k.a., Dynamically Linked Library or DLL) to user
code.
Also, this library will automatically define this macro when Boost libraries
are built as dynamic libraries (e.g., defining @c BOOST_ALL_DYN_LINK).
This library will automatically define this macro when Boost libraries are
built as shared libraries (e.g., defining @c BOOST_ALL_DYN_LINK or using
<c>bjam link=shared ...</c>).
@warning In general this library will correctly check contracts at
run-time only when compiled as a shared library, unless user
code checks contracts in a single program unit (e.g., a single
program with only statically linked libraries that check
contracts).
program with only statically linked libraries).
Therefore, it is recommended to build and use this library as
a dynamic library by defining this macro (or equivalently by
building all Boost libraries as dynamic libraries and
@c BOOST_ALL_DYN_LINK is defined).
a shared library by defining this macro (or equivalently by
building all Boost libraries as shared libraries).
@see @RefSect{getting_started.compilers_and_platforms, Compilers and
Platforms}
@see @RefSect{getting_started, Getting Started}
*/
#define BOOST_CONTRACT_DYN_LINK
#elif defined(BOOST_CONTRACT_DYN_LINK) && defined(BOOST_CONTRACT_STATIC_LINK)
@@ -61,8 +59,8 @@ Configure this library compile-time and run-time behaviours.
If this macro is defined, this library is compiled so it can be linked
statically to user code.
This library build scripts will automatically define this macro when Boost
libraries are being built as static libraries.
This library will automatically define this macro when Boost libraries
are built as static libraries.
@warning This library is not guaranteed to always work correctly at
run-time when this macro is defined (define
@@ -71,10 +69,9 @@ Configure this library compile-time and run-time behaviours.
However, this macro can be defined and this library can be
safely used as a static library for user code that checks
contracts in a single program unit (e.g., a single program with
only statically linked libraries that check contracts).
only statically linked libraries).
@see @RefSect{getting_started.compilers_and_platforms, Compilers and
Platforms}
@see @RefSect{getting_started, Getting Started}
*/
#define BOOST_CONTRACT_STATIC_LINK
#elif defined(BOOST_CONTRACT_STATIC_LINK) && defined(BOOST_CONTRACT_DYN_LINK)
@@ -90,11 +87,11 @@ Configure this library compile-time and run-time behaviours.
Automatically defined by this library when it is being used as a header-only
library (not recommended).
This library will define this macro when users do not define
This macro is not a configuration macro and this library will generate a
compile-time error if users try to define it directly.
This library will automatically define this macro when users do not define
@RefMacro{BOOST_CONTRACT_DYN_LINK} (or @c BOOST_ALL_DYN_LINK) and
@RefMacro{BOOST_CONTRACT_STATIC_LINK} (this macro is not a configuration
macro and this library will generate a compile-time error if users try to
define it directly).
@RefMacro{BOOST_CONTRACT_STATIC_LINK}.
When used as a header-only library, this library code does not have to be
compiled separately from user code, this library headers are simply included
and compiled as part of the user program.
@@ -106,10 +103,9 @@ Configure this library compile-time and run-time behaviours.
However, this macro can be defined and this library can be
safely used as a header-only library for user code that checks
contracts in a single program unit (e.g., a single program with
only statically linked libraries that check contracts).
only statically linked libraries).
@see @RefSect{getting_started.compilers_and_platforms, Compilers and
Platforms}
@see @RefSect{getting_started, Getting Started}
*/
#define BOOST_CONTRACT_HEADER_ONLY
#endif
@@ -144,14 +140,14 @@ Configure this library compile-time and run-time behaviours.
Maximum number of arguments for public function overrides on compilers that
do not support variadic templates (default to @c 10).
On compilers that do not support variadic templates, this macro is defined
to the maximum number of arguments that public function overrides can have
and pass to @RefFunc{boost::contract::public_function} (users can redefine
this macro to a different value).
On compilers that do not support C++11 variadic templates, this macro is
defined to the maximum number of arguments that public function overrides
can have and pass to @RefFunc{boost::contract::public_function} (users can
redefine this macro to a different value).
On compilers that support variadic templates, this macro has no effect.
@note Regardless of the value of this macro and of compiler support for
variadic templates, there is an intrinsic limit of about 18
variadic templates, there might be an intrinsic limit of about 18
arguments for public function overrides (because of similar limits
in Boost.MPL and Boost.FunctionTypes internally used by this
library).
@@ -169,21 +165,22 @@ Configure this library compile-time and run-time behaviours.
classes for subcontracting via @RefMacro{BOOST_CONTRACT_BASE_TYPES}:
@code
class u :
class u
#define BASES public b, private w
BASES
: BASES
{
friend class boost::contract:access;
typedef BOOST_CONTRACT_BASES(BASES) BOOST_CONTRACT_TYPEDEF;
typedef BOOST_CONTRACT_BASE_TYPES(BASES) BOOST_CONTRACT_TYPEDEF;
#undef BASES
...
};
@endcode
Users can redefine this macro if the @c typedef must have a name different
from @c base_types (because of name clashes in user code, etc.).
When used this way, users can redefine this macro if the @c typedef must
have a name different from @c base_types (because of name clashes in user
code, etc.).
@see @RefSect{tutorial.base_classes__subcontracting_, Base Classes}
*/
@@ -217,8 +214,9 @@ Configure this library compile-time and run-time behaviours.
};
@endcode
Users can redefine this macro if the invariant functions must have a name
different from @c invariant (because of name clashes in user code, etc.).
When used this way, users can redefine this macro if the invariant functions
must have a name different from @c invariant (because of name clashes in
user code, etc.).
@note C++ does not allow to overload member functions based on the
@c static classifier, so this macro must always be defined to be
@@ -253,9 +251,9 @@ Configure this library compile-time and run-time behaviours.
};
@endcode
Users can redefine this macro if the static invariant function must have a
name different from @c static_invariant (because of name clashes in user
code, etc.).
When used this way, users can redefine this macro if the static invariant
function must have a name different from @c static_invariant (because of
name clashes in user code, etc.).
@note C++ does not allow to overload member functions based on the
@c static classifier, so this macro must always be defined to be
@@ -275,11 +273,11 @@ Configure this library compile-time and run-time behaviours.
Defining this macro disables a number of static checks and related
compile-time errors generated by this library, for example:
@li The static invariant member @c BOOST_CONTRACT_STATIC_INVARIANT_FUNC
function must be declared @c static.
@li Non-static invariant member functions @c BOOST_CONTRACT_INVARIANT_FUNC
must be declared either @c const, <c>const volatile</c>, or
<c>volatile const</c>.
@li The static invariant member function named as
@c BOOST_CONTRACT_STATIC_INVARIANT_FUNC must be declared @c static.
@li Non-static invariant member functions named as
@c BOOST_CONTRACT_INVARIANT_FUNC must be declared either @c const,
<c>const volatile</c>, or <c>volatile const</c>.
@li Derived classes that program contracts for one or more public function
overrides via @RefFunc{boost::contract::public_function} must also
define the @RefMacro{BOOST_CONTRACT_BASE_TYPES} @c typedef.
@@ -296,22 +294,23 @@ Configure this library compile-time and run-time behaviours.
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
/**
Code block to execute if contracts are not assigned to a
@RefClass{boost::contract::check} variable (undefined by default and
executes @c BOOST_ASSERT(false)).
@RefClass{boost::contract::check} variable (undefined and executes
@c BOOST_ASSERT(false) by default).
In general, there is a logic error in the program when contracts are not
assigned to a local variable of type @RefClass{boost::contract::check}
(because that is a misuse of this library).
explicitly assigned to a local variable of type
@RefClass{boost::contract::check} and without using C++11 @c auto
declarations (because that is a misuse of this library).
Therefore, by default (i.e., when this macro is not defined) this library
calls <c>BOOST_ASSERT(false)</c> in those cases.
If this macro is defined, this library will execute the code expanded by the
macro instead of calling @c BOOST_ASSERT(false) (if programmers prefer to
throw an exception, etc.).
If this macro is defined, this library will execute the code expanded by
this macro instead of calling @c BOOST_ASSERT(false) (if programmers prefer
to throw an exception, etc.).
This macro can be defined to be any block of code (use empty curly brackets
@c {} to generate no error), for example (on GCC):
This macro can also be defined to be any block of code (and use empty curly
brackets @c {} to generate no error, not recommended), for example (on GCC):
@code
-DBOOST_CONTRACT_ON_MISSING_CHECK_DECL='{ throw std::logic_error("missing contract check declaration"); }'
gcc -DBOOST_CONTRACT_ON_MISSING_CHECK_DECL='{ throw std::logic_error("missing contract check declaration"); }' ...
@endcode
@see @RefSect{tutorial, Tutorial}
@@ -327,13 +326,13 @@ Configure this library compile-time and run-time behaviours.
Not disabling other assertions while checking preconditions can lead to
infinite recursion in user code so by default this macro is not defined.
However, the @RefSect{bibliography, [1962]} proposal does not disable
However, the @RefSect{bibliography, [N1962]} proposal does not disable
assertions while checking preconditions because arguments can reach the
function body unchecked if assertions are disabled while checking
preconditions (e.g., when these same functions bodies are called to check
the preconditions in question).
This macro can be defined to obtain the behaviour specified in
@RefSect{bibliography, [1962]} (at the risk of infinite recursion).
@RefSect{bibliography, [N1962]} (at the risk of infinite recursion).
@see @RefSect{contract_programming_overview.feature_summary,
Feature Summary}
@@ -370,7 +369,8 @@ Configure this library compile-time and run-time behaviours.
syntactically.
However, they are not evaluated and checked at run-time unless
this macro is defined (because these conditions can be computationally
expensive, at least compared to the cost of executing the function body).
expensive, at least compared to the computational cost of executing the
function body).
@see @RefSect{extras.assertion_levels, Assertion Levels}
*/
@@ -379,15 +379,15 @@ Configure this library compile-time and run-time behaviours.
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
/**
If defined, this library does not perform implementation checks (undefined
by default).
If defined, this library disables implementation checks (undefined by
default).
If this macro is defined, this library internal code is also optimized to
reduce compile-time (not just run-time) overhead associated with
implementation checks.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of implementation checks or use
@RefMacro{BOOST_CONTRACT_CHECK} (recommended).
In addition, users can manually program @c \#ifndef statements in their code
using this macro to completely disable compilation of implementation checks
or use @RefMacro{BOOST_CONTRACT_CHECK} (recommended).
@see @RefSect{advanced.implementation_checks,
Implementation Checks},
@@ -407,11 +407,11 @@ Configure this library compile-time and run-time behaviours.
If this macro is defined, this library internal code is also optimized to
reduce compile-time (not just run-time) overhead associated with
checking preconditions.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of preconditions or use the macros
defined in @c boost/contract_macro.hpp (recommended only for applications
where it is truly necessary to completely remove contract code compilation
from production code).
In addition, users can manually program @c \#ifndef statements in their code
using this macro to completely disable compilation of preconditions or use
the macros defined in @c boost/contract_macro.hpp (recommended only for
applications where it is truly necessary to completely remove contract code
compilation from production code).
@see @RefSect{tutorial.preconditions, Preconditions},
@RefSect{extras.disable_contract_checking,
@@ -430,11 +430,11 @@ Configure this library compile-time and run-time behaviours.
If this macro is defined, this library internal code is also optimized to
reduce compile-time (not just run-time) overhead associated with
checking postconditions.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of postconditions or use the macros
defined in @c boost/contract_macro.hpp (recommended only for applications
where it is truly necessary to completely remove contract code compilation
from production code).
In addition, users can manually program @c \#ifndef statements in their code
using this macro to completely disable compilation of postconditions or use
the macros defined in @c boost/contract_macro.hpp (recommended only for
applications where it is truly necessary to completely remove contract code
compilation from production code).
It is necessary to disable both postconditions and exception guarantees
defining @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS} and
@@ -458,11 +458,11 @@ Configure this library compile-time and run-time behaviours.
If this macro is defined, this library internal code is also optimized to
reduce compile-time (not just run-time) overhead associated with
checking exception guarantees.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of exception guarantees or use the
macros defined in @c boost/contract_macro.hpp (recommended only for
applications where it is truly necessary to completely remove contract code
compilation from production code).
In addition, users can manually program @c \#ifndef statements in their code
using this macro to completely disable compilation of exception guarantees
or use the macros defined in @c boost/contract_macro.hpp (recommended only
for applications where it is truly necessary to completely remove contract
code compilation from production code).
It is necessary to disable both postconditions and exception guarantees
defining @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS} and
@@ -490,11 +490,11 @@ Configure this library compile-time and run-time behaviours.
If this macro is defined, this library internal code is also optimized to
reduce compile-time (not just run-time) overhead associated with
checking class invariants at entry.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of entry class invariants or use the
macros defined in @c boost/contract_macro.hpp (recommended only for
applications where it is truly necessary to completely remove contract code
compilation from production code).
In addition, users can manually program @c \#ifndef statements in their code
using this macro to completely disable compilation of entry class invariants
or use the macros defined in @c boost/contract_macro.hpp (recommended only
for applications where it is truly necessary to completely remove contract
code compilation from production code).
This macro is automatically defined when
@RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined.
@@ -520,11 +520,11 @@ Configure this library compile-time and run-time behaviours.
If this macro is defined, this library internal code is also optimized to
reduce compile-time (not just run-time) overhead associated with
checking class invariants at exit.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of exit class invariants or use the
macros defined in @c boost/contract_macro.hpp (recommended only for
applications where it is truly necessary to completely remove contract code
compilation from production code).
In addition, users can manually program @c \#ifndef statements in their code
using this macro to completely disable compilation of exit class invariants
or use the macros defined in @c boost/contract_macro.hpp (recommended only
for applications where it is truly necessary to completely remove contract
code compilation from production code).
This macro is automatically defined when
@RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined.
@@ -548,9 +548,9 @@ Configure this library compile-time and run-time behaviours.
If this macro is defined, this library internal code is also optimized to
reduce compile-time (not just run-time) overhead associated with
checking class invariants.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of class invariants or use the
macros defined in @c boost/contract_macro.hpp (recommended only for
In addition, users can manually program @c \#ifndef statements in their code
using this macro to completely disable compilation of class invariants or
use the macros defined in @c boost/contract_macro.hpp (recommended only for
applications where it is truly necessary to completely remove contract code
compilation from production code).
@@ -575,11 +575,11 @@ Configure this library compile-time and run-time behaviours.
Automatically defined by this library when old value copies are not to be
performed.
This library will define this macro when users define both
This macro is not a configuration macro and this library will generate a
compile-time error if users try to define it directly.
This library will automatically define this macro when users define both
@RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS} and
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration
macro and this library will generate a compile-time error if users try to
define it directly).
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS}.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of old value copies or use the
macros defined in @c boost/contract_macro.hpp (recommended only for
@@ -587,8 +587,8 @@ Configure this library compile-time and run-time behaviours.
compilation from production code).
@see @RefSect{tutorial.old_values, Old Values},
@RefSect{advanced.old_value_copies_at_body,
Old Value Copies at Body},
@RefSect{advanced.old_values_copied_at_body,
Old Values Copied at Body},
@RefSect{extras.disable_contract_compilation__macro_interface_,
Disable Contract Compilation}
*/
@@ -605,12 +605,12 @@ Configure this library compile-time and run-time behaviours.
Automatically defined by this library when contracts are not checked for
constructors.
This library will define this macro when users define all
This macro is not a configuration macro and this library will generate a
compile-time error if users try to define it directly.
This library will automatically define this macro when users define all
@RefMacro{BOOST_CONTRACT_NO_INVARIANTS},
@RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, and
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration
macro and this library will generate a compile-time error if users try to
define it directly).
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS}.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of contracts for constructors or use
the macros defined in @c boost/contract_macro.hpp (recommended only for
@@ -637,12 +637,12 @@ Configure this library compile-time and run-time behaviours.
Automatically defined by this library when contracts are not checked for
destructors.
This library will define this macro when users define all
This macro is not a configuration macro and this library will generate a
compile-time error if users try to define it directly.
This library will automatically define this macro when users define all
@RefMacro{BOOST_CONTRACT_NO_INVARIANTS},
@RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, and
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration
macro and this library will generate a compile-time error if users try to
define it directly).
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS}.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of contracts for destructors or use
the macros defined in @c boost/contract_macro.hpp (recommended only for
@@ -666,13 +666,13 @@ Configure this library compile-time and run-time behaviours.
Automatically defined by this library when contracts are not checked for
public functions.
This library will define this macro when users define all
This macro is not a configuration macro and this library will generate a
compile-time error if users try to define it directly.
This library will automatically define this macro when users define all
@RefMacro{BOOST_CONTRACT_NO_INVARIANTS},
@RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS},
@RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, and
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration
macro and this library will generate a compile-time error if users try to
define it directly).
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS}.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of contracts for public functions or
use the macros defined in @c boost/contract_macro.hpp (recommended only for
@@ -693,14 +693,14 @@ Configure this library compile-time and run-time behaviours.
defined(BOOST_CONTRACT_NO_EXCEPTS)
/**
Automatically defined by this library when contracts are not checked for
non-member, private and protected functions.
non-member, private, or protected functions.
This library will define this macro when users define all
This macro is not a configuration macro and this library will generate a
compile-time error if users try to define it directly.
This library will automatically define this macro when users define all
@RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS},
@RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, and
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration
macro and this library will generate a compile-time error if users try to
define it directly).
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS}.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of contracts for non-member,
private and protected functions, or use the macros defined in
@@ -708,7 +708,7 @@ Configure this library compile-time and run-time behaviours.
truly necessary to completely remove contract code compilation from
production code).
This macro is also used when contracts are not checked for private and
This macro is also used when contracts are not checked for private or
protected functions, lambda functions, code blocks, loops, etc.
@see @RefSect{tutorial.non_member_functions, Non-Member Functions},
@@ -733,18 +733,20 @@ Configure this library compile-time and run-time behaviours.
preconditions, postconditions, exceptions guarantees, and class invariants
(excluding implementation checks).
This library will define this macro when users define all
This macro is not a configuration macro and this library will generate a
compile-time error if users try to define it directly.
This library will automatically define this macro when users define all
@RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS},
@RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS},
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS}, and
@RefMacro{BOOST_CONTRACT_NO_INVARIANTS} (this macro is not a configuration
macro and this library will generate a compile-time error if users try to
define it directly).
@RefMacro{BOOST_CONTRACT_NO_INVARIANTS}.
Users can manually program @c \#ifndef statements in their code using this
macro to completely disable compilation of contracts within specifications
or use the macros defined in @c boost/contract_macro.hpp (recommended only
for applications where it is truly necessary to completely remove contract
code compilation from production code).
(so excluding implementation checks which are contracts within
implementations instead), or use the macros defined in
@c boost/contract_macro.hpp (recommended only for applications where it is
truly necessary to completely remove contract code compilation from
production code).
@see @RefSect{extras.disable_contract_compilation__macro_interface_,
Disable Contract Compilation}
@@ -760,16 +762,17 @@ Configure this library compile-time and run-time behaviours.
defined(BOOST_CONTRACT_NO_EXCEPTS) && \
defined(BOOST_CONTRACT_NO_CHECKS)
/**
Automatically defined by this library when contracts are not checked at all.
Automatically defined by this library when contracts are not checked at all
(neither for specifications nor for implementations).
This library will define this macro when users define all
This macro is not a configuration macro and this library will generate a
compile-time error if users try to define it directly.
This library will automatically define this macro when users define all
@RefMacro{BOOST_CONTRACT_NO_INVARIANTS},
@RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS},
@RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS},
@RefMacro{BOOST_CONTRACT_NO_EXCEPTS}, and
@RefMacro{BOOST_CONTRACT_NO_CHECKS} (this macro is not a configuration
macro and this library will generate a compile-time error if users try to
define it directly).
@RefMacro{BOOST_CONTRACT_NO_CHECKS}.
For example, users can manually program @c \#ifndef statements in their code
using this macro to avoid including the @c boost/contract.hpp header all
together:

View File

@@ -36,7 +36,9 @@ initialize other base classes):
public b
: BASES
{
...
friend class boost::contract::access;
typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
#undef BASES
public:
@@ -60,10 +62,11 @@ In addition, this class should never be declared as a virtual base (because
virtual bases are initialized only once across the entire inheritance hierarchy
preventing preconditions of other base classes from being checked).
Unions cannot have base classes in C++ so this class can be used to declare a
local object within the constructor definition just before
@RefFunc{boost::contract::constructor} is used (see
@RefSect{extras.unions, Unions}).
This class cannot be used this way in a @c union because unions cannot have base
classes in C++.
Instead, this class is used in a @c union to declare a local object within the
constructor definition just before @RefFunc{boost::contract::constructor} is
used (see @RefSect{extras.unions, Unions}).
@see @RefSect{tutorial.constructors, Constructors}
@@ -79,9 +82,10 @@ public:
This is implicitly called for those constructors of the contracted class
that do not specify preconditions.
@note Calling this default constructor should amount to negligible
compile-time and run-time overheads (likely to be optimized away
completely by most compilers).
@note The implementation of this library is optimized so that calling this
default constructor should amount to negligible compile-time and
run-time overheads (likely to be optimized away completely by most
compilers).
*/
constructor_precondition() {}

View File

@@ -66,11 +66,15 @@ public:
Exception thrown when inconsistent return values are passed to overridden
virtual public functions.
This exception is internally thrown by this library when programmers specify
return values for public function overrides in derived classes that are not
consistent with the return types of the virtual public functions being
overridden in the base classes.
This allows this library to give more descriptive error messages in such cases.
This exception is thrown when programmers pass to this library return value
parameters for public function overrides in derived classes that are not
consistent with the return type parameter passed for the virtual public function
being overridden from the base classes.
This allows this library to give more descriptive error messages in such cases
of misuse.
This exception is internally thrown by this library and programmers should not
need to throw it from user code.
@see @RefSect{tutorial.public_function_overrides__subcontracting_,
Public Function Overrides}
@@ -117,10 +121,10 @@ This exception is thrown by code expanded by @RefMacro{BOOST_CONTRACT_ASSERT}
This exception is typically used to report contract assertion failures because
it contains detailed information about the file name, line number, and source
code of the asserted condition (so it can be used by this library to provide
detailed error messages).
detailed error messages when handling contract assertion failures).
However, any other exception can be used to report a contract assertion failure
(including user-defined exceptions).
This library will call the appropriate contract failure handler function
(@RefFunc{boost::contract::precondition_failure}, etc.) when this or any other
exception is thrown while checking contracts (by default, these failure handler
@@ -171,7 +175,8 @@ public:
@b Throws: This is declared @c noexcept (or @c throw() before C++11).
@return A string formatted similarly to the following:
<c>assertion "`code()`" failed: file "`file()`", line \`line()\`</c>.
<c>assertion "`code()`" failed: file "`file()`", line \`line()\`</c>
(where `` indicate execution quotes).
File, line, and code will be omitted from this string if they were
not specified when constructing this object.
*/
@@ -236,7 +241,8 @@ enum from {
from_destructor,
/**
Assertion failed when checking contracts for functions (members or not).
Assertion failed when checking contracts for functions (members or not,
public or not).
*/
from_function
};
@@ -568,7 +574,7 @@ Set a new failure handler and returns it.
@param f New failure handler functor to set.
@return Same failure handler functor @p f passed as parameter (e.g., fr
@return Same failure handler functor @p f passed as parameter (e.g., for
concatenating function calls).
@see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
@@ -703,7 +709,7 @@ inline void except_failure(from where) /* can throw */ {
}
/**
Set failure handler for old value copies at body.
Set failure handler for old values copied at body.
Set a new failure handler and returns it.
@@ -715,7 +721,7 @@ Set a new failure handler and returns it.
concatenating function calls).
@see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
@RefSect{advanced.old_value_copies_at_body, Old Value Copies at Body}
@RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body}
*/
inline from_failure_handler const& set_old_failure(from_failure_handler const&
f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
@@ -727,7 +733,7 @@ inline from_failure_handler const& set_old_failure(from_failure_handler const&
}
/**
Return failure handler currently set for old value copies at body.
Return failure handler currently set for old values copied at body.
This is often called only internally by this library.
@@ -736,7 +742,7 @@ This is often called only internally by this library.
@return A copy of the failure handler currently set.
@see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
@RefSect{advanced.old_value_copies_at_body, Old Value Copies at Body}
@RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body}
*/
inline from_failure_handler get_old_failure()
/** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
@@ -748,7 +754,7 @@ inline from_failure_handler get_old_failure()
}
/**
Call failure handler for old value copies at body.
Call failure handler for old values copied at body.
This is often called only internally by this library.
@@ -761,7 +767,7 @@ This is often called only internally by this library.
throw exceptions instead of terminating the program).
@see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
@RefSect{advanced.old_value_copies_at_body, Old Value Copies at Body}
@RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body}
*/
inline void old_failure(from where) /* can throw */ {
#ifndef BOOST_CONTRACT_DISABLE_THREADS

View File

@@ -8,10 +8,10 @@
// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
/** @file
Specify preconditions, old value copies at body, postconditions, and exception
Specify preconditions, old values copied at body, postconditions, and exception
guarantees
Preconditions, old value copies at body, postconditions, and exception
Preconditions, old values copied at body, postconditions, and exception
guarantees are all optionals but, when they are specified, they need to be
specified in that order.
*/
@@ -42,7 +42,9 @@ specified in that order.
// is used instead of `check c = ...` but only up to C++17. C++17 strong copy
// elision on function return values prevents this lib from generating a
// compile-time error in those cases, but the lib will still generate a run-time
// error according with ON_MISSING_CHECK_DECL.
// error according with ON_MISSING_CHECK_DECL. Furthermore, on some C++98
// compilers, this private copy ctor gives a warning (because of lack of copy
// optimization on those compilers), this warning can be ignored.
#if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \
defined(BOOST_CONTRACT_STATIC_LINK)
#define BOOST_CONTRACT_SPECIFY_CLASS_IMPL_(class_type, cond_type) \
@@ -138,7 +140,7 @@ Used to prevent setting other contract conditions after exception guarantees.
This class has no member function so it is used to prevent specifying additional
functors to check any other contract.
This object is internally constructed by this library when users specify
This object is internally constructed by the library when users specify
contracts calling @RefFunc{boost::contract::function} and similar functions
(that is why this class does not have a public constructor).
@@ -149,11 +151,11 @@ public:
/**
Destruct this object.
@b Throws: This can throw in case programmers specify failure handlers that
throw exceptions instead of terminating the program (see
@b Throws: This is declared @c noexcept(false) since C++11 to allow users
to program failure handlers that throw exceptions on contract
assertion failures (not the default, see
@RefSect{advanced.throw_on_failures__and__noexcept__,
Throw on Failure}).
(This is declared @c noexcept(false) since C++11.)
*/
~specify_nothing() BOOST_NOEXCEPT_IF(false) {}
@@ -186,7 +188,7 @@ Allow to specify exception guarantees.
Allow to specify the functor this library will call to check exception
guarantees.
This object is internally constructed by this library when users specify
This object is internally constructed by the library when users specify
contracts calling @RefFunc{boost::contract::function} and similar functions
(that is why this class does not have a public constructor).
@@ -197,11 +199,11 @@ public:
/**
Destruct this object.
@b Throws: This can throw in case programmers specify failure handlers that
throw exceptions instead of terminating the program (see
@b Throws: This is declared @c noexcept(false) since C++11 to allow users
to program failure handlers that throw exceptions on contract
assertion failures (not the default, see
@RefSect{advanced.throw_on_failures__and__noexcept__,
Throw on Failure}).
(This is declared @c noexcept(false) since C++11.)
*/
~specify_except() BOOST_NOEXCEPT_IF(false) {}
@@ -222,9 +224,13 @@ public:
by this function does not allow to specify any additional contract.
*/
template<typename F>
specify_nothing except(F const& f) {
BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_
}
specify_nothing except(
F const&
#if !defined(BOOST_CONTRACT_NO_EXCEPTS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) { BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ }
/** @cond */
private:
@@ -251,7 +257,7 @@ Allow to specify postconditions or exception guarantees.
Allow to specify functors this library will call to check postconditions or
exception guarantees.
This object is internally constructed by this library when users specify
This object is internally constructed by the library when users specify
contracts calling @RefFunc{boost::contract::function} and similar functions
(that is why this class does not have a public constructor).
@@ -259,9 +265,12 @@ contracts calling @RefFunc{boost::contract::function} and similar functions
@RefSect{tutorial.exception_guarantees, Exception Guarantees}
@tparam VirtualResult Return type of the enclosing function declaring the
contract if that function is either a virtual public
function or a public function override.
Otherwise, this type is always @c void.
contract if that is either a virtual or an
overriding public function, otherwise this is always
@c void.
(Usually this template parameter is automatically
deduced by C++ and it does not need to be explicitly
specified by programmers.)
*/
template<typename VirtualResult = void>
class specify_postcondition_except { // Privately copyable (as *).
@@ -269,11 +278,11 @@ public:
/**
Destruct this object.
@b Throws: This can throw in case programmers specify failure handlers that
throw exceptions instead of terminating the program (see
@b Throws: This is declared @c noexcept(false) since C++11 to allow users
to program failure handlers that throw exceptions on contract
assertion failures (not the default, see
@RefSect{advanced.throw_on_failures__and__noexcept__,
Throw on Failure}).
(This is declared @c noexcept(false) since C++11.)
*/
~specify_postcondition_except() BOOST_NOEXCEPT_IF(false) {}
@@ -281,7 +290,7 @@ public:
Allow to specify postconditions.
@param f Functor called by this library to check postconditions
@c f(...).
@c f() or @c f(result).
Assertions within this functor are usually programmed using
@RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a
call to this functor indicates a contract assertion failure (and
@@ -289,18 +298,25 @@ public:
@RefFunc{boost::contract::postcondition_failure}).
This functor should capture variables by (constant) references
(to access the values they will have at function exit).
This functor must be a nullary functor if @c VirtualResult is
@c void, otherwise it must be a unary functor accepting the
return value as a parameter of type <c>VirtualResult const&</c>
(to avoid extra copies of the return value, or of type
@c VirtualResult or <c>VirtualResult const</c> if extra copies
of the return value are irrelevant).
This functor must be a nullary functor @c f() if
@c VirtualResult is @c void, otherwise it must be a unary
functor @c f(result) accepting the return value @c result as a
parameter of type <c>VirtualResult const&</c> (to avoid extra
copies of the return value, or of type @c VirtualResult or
<c>VirtualResult const</c> if extra copies of the return value
are irrelevant).
@return After postconditions have been specified, the object returned by
this function allows to optionally specify exception guarantees.
*/
template<typename F>
specify_except postcondition(F const& f) {
specify_except postcondition(
F const&
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) {
BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_
}
@@ -321,9 +337,13 @@ public:
by this function does not allow to specify any additional contract.
*/
template<typename F>
specify_nothing except(F const& f) {
BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_
}
specify_nothing except(
F const&
#if !defined(BOOST_CONTRACT_NO_EXCEPTS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) { BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ }
/** @cond */
private:
@@ -342,23 +362,26 @@ private:
};
/**
Allow to specify old value copies at body, postconditions, and exception
Allow to specify old values copied at body, postconditions, and exception
guarantees.
Allow to specify functors this library will call to copy old value at body,
Allow to specify functors this library will call to copy old values at body,
check postconditions, and check exception guarantees.
This object is internally constructed by this library when users specify
This object is internally constructed by the library when users specify
contracts calling @RefFunc{boost::contract::function} and similar functions
(that is why this class does not have a public constructor).
@see @RefSect{advanced.old_value_copies_at_body, Old Value Copies at Body},
@see @RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body},
@RefSect{tutorial.postconditions, Postconditions},
@RefSect{tutorial.exception_guarantees, Exception Guarantees}
@tparam VirtualResult Return type of the enclosing function declaring the
contract if that function is either a virtual public
function or a public function override.
Otherwise, this type is always @c void.
contract if that is either a virtual or an
overriding public function, otherwise this is always
@c void.
(Usually this template parameter is automatically
deduced by C++ and it does not need to be explicitly
specified by programmers.)
*/
template<typename VirtualResult = void>
class specify_old_postcondition_except { // Privately copyable (as *).
@@ -366,20 +389,20 @@ public:
/**
Destruct this object.
@b Throws: This can throw in case programmers specify failure handlers that
throw exceptions instead of terminating the program (see
@b Throws: This is declared @c noexcept(false) since C++11 to allow users
to program failure handlers that throw exceptions on contract
assertion failures (not the default, see
@RefSect{advanced.throw_on_failures__and__noexcept__,
Throw on Failure}).
(This is declared @c noexcept(false) since C++11.)
*/
~specify_old_postcondition_except() BOOST_NOEXCEPT_IF(false) {}
/**
Allow to specify old value copies at body.
Allow to specify old values copied at body.
It should often be sufficient to initialize old value pointers as soon as
they are declared, without using this function (see
@RefSect{advanced.old_value_copies_at_body, Old Value Copies at Body}).
@RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body}).
@param f Nullary functor called by this library @c f() to assign old
value copies just before the body is executed but after entry
@@ -395,12 +418,18 @@ public:
value expressions can be captured by (constant) value, or better
by (constant) reference to avoid extra copies).
@return After old value copies at body have been specified, the object
@return After old values copied at body have been specified, the object
returned by this function allows to optionally specify
postconditions and exception guarantees.
*/
template<typename F>
specify_postcondition_except<VirtualResult> old(F const& f) {
specify_postcondition_except<VirtualResult> old(
F const&
#if !defined(BOOST_CONTRACT_NO_OLDS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) {
BOOST_CONTRACT_SPECIFY_OLD_IMPL_
}
@@ -408,7 +437,7 @@ public:
Allow to specify postconditions.
@param f Functor called by this library to check postconditions
@c f(...).
@c f() or @c f(result).
Assertions within this functor are usually programmed using
@RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a
call to this functor indicates a contract assertion failure (and
@@ -416,18 +445,25 @@ public:
@RefFunc{boost::contract::postcondition_failure}).
This functor should capture variables by (constant) references
(to access the values they will have at function exit).
This functor must be a nullary functor if @c VirtualResult is
@c void, otherwise it must be a unary functor accepting the
return value as a parameter of type <c>VirtualResult const&</c>
(to avoid extra copies of the return value, or of type
@c VirtualResult or <c>VirtualResult const</c> if extra copies
of the return value are irrelevant).
This functor must be a nullary functor @c f() if
@c VirtualResult is @c void, otherwise it must be a unary
functor @c f(result) accepting the return value @c result as a
parameter of type <c>VirtualResult const&</c> (to avoid extra
copies of the return value, or of type @c VirtualResult or
<c>VirtualResult const</c> if extra copies of the return value
are irrelevant).
@return After postconditions have been specified, the object returned by
this function allows to optionally specify exception guarantees.
*/
template<typename F>
specify_except postcondition(F const& f) {
specify_except postcondition(
F const&
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) {
BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_
}
@@ -448,9 +484,13 @@ public:
by this function does not allow to specify any additional contract.
*/
template<typename F>
specify_nothing except(F const& f) {
BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_
}
specify_nothing except(
F const&
#if !defined(BOOST_CONTRACT_NO_EXCEPTS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) { BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ }
/** @cond */
private:
@@ -474,24 +514,27 @@ private:
};
/**
Allow to specify preconditions, old value copies at body, postconditions, and
Allow to specify preconditions, old values copied at body, postconditions, and
exception guarantees.
Allow to specify functors this library will call to check preconditions, copy
old values at body, check postconditions, and check exception guarantees.
This object is internally constructed by this library when users specify
This object is internally constructed by the library when users specify
contracts calling @RefFunc{boost::contract::function} and similar functions
(that is why this class does not have a public constructor).
@see @RefSect{tutorial.preconditions, Preconditions},
@RefSect{advanced.old_value_copies_at_body, Old Value Copies at Body},
@RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body},
@RefSect{tutorial.postconditions, Postconditions},
@RefSect{tutorial.exception_guarantees, Exception Guarantees}
@tparam VirtualResult Return type of the enclosing function declaring the
contract if that function is either a virtual public
function or a public function override.
Otherwise, this type is always @c void.
contract if that is either a virtual or an
overriding public function, otherwise this is always
@c void.
(Usually this template parameter is automatically
deduced by C++ and it does not need to be explicitly
specified by programmers.)
*/
template<
typename VirtualResult /* = void (already in fwd decl from decl.hpp) */
@@ -504,11 +547,11 @@ public:
/**
Destruct this object.
@b Throws: This can throw in case programmers specify failure handlers that
throw exceptions instead of terminating the program (see
@b Throws: This is declared @c noexcept(false) since C++11 to allow users
to program failure handlers that throw exceptions on contract
assertion failures (not the default, see
@RefSect{advanced.throw_on_failures__and__noexcept__,
Throw on Failure}).
(This is declared @c noexcept(false) since C++11.)
*/
~specify_precondition_old_postcondition_except() BOOST_NOEXCEPT_IF(false) {}
@@ -526,20 +569,26 @@ public:
better by (constant) reference (to avoid extra copies).
@return After preconditions have been specified, the object returned by this
function allows to optionally specify old value copies at body,
function allows to optionally specify old values copied at body,
postconditions, and exception guarantees.
*/
template<typename F>
specify_old_postcondition_except<VirtualResult> precondition(F const& f) {
specify_old_postcondition_except<VirtualResult> precondition(
F const&
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) {
BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_
}
/**
Allow to specify old value copies at body.
Allow to specify old values copied at body.
It should often be sufficient to initialize old value pointers as soon as
they are declared, without using this function (see
@RefSect{advanced.old_value_copies_at_body, Old Value Copies at Body}).
@RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body}).
@param f Nullary functor called by this library @c f() to assign old
value copies just before the body is executed but after entry
@@ -555,12 +604,18 @@ public:
value expressions can be captured by (constant) value, or better
by (constant) reference to avoid extra copies).
@return After old value copies at body have been specified, the object
@return After old values copied at body have been specified, the object
returned by this functions allows to optionally specify
postconditions and exception guarantees.
*/
template<typename F>
specify_postcondition_except<VirtualResult> old(F const& f) {
specify_postcondition_except<VirtualResult> old(
F const&
#if !defined(BOOST_CONTRACT_NO_OLDS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) {
BOOST_CONTRACT_SPECIFY_OLD_IMPL_
}
@@ -568,7 +623,7 @@ public:
Allow to specify postconditions.
@param f Functor called by this library to check postconditions
@c f(...).
@c f() or @c f(result).
Assertions within this functor are usually programmed using
@RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a
call to this functor indicates a contract assertion failure (and
@@ -576,18 +631,25 @@ public:
@RefFunc{boost::contract::postcondition_failure}).
This functor should capture variables by (constant) references
(to access the values they will have at function exit).
This functor must be a nullary functor if @c VirtualResult is
@c void, otherwise it must be a unary functor accepting the
return value as a parameter of type <c>VirtualResult const&</c>
(to avoid extra copies of the return value, or of type
@c VirtualResult or <c>VirtualResult const</c> if extra copies
of the return value are irrelevant).
This functor must be a nullary functor @c f() if
@c VirtualResult is @c void, otherwise it must be a unary
functor @c f(result) accepting the return value @c result as a
parameter of type <c>VirtualResult const&</c> (to avoid extra
copies of the return value, or of type @c VirtualResult or
<c>VirtualResult const</c> if extra copies of the return value
are irrelevant).
@return After postconditions have been specified, the object returned by
this function allows to optionally specify exception guarantees.
*/
template<typename F>
specify_except postcondition(F const& f) {
specify_except postcondition(
F const&
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) {
BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_
}
@@ -608,9 +670,13 @@ public:
by this function does not allow to specify any additional contract.
*/
template<typename F>
specify_nothing except(F const& f) {
BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_
}
specify_nothing except(
F const&
#if !defined(BOOST_CONTRACT_NO_EXCEPTS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
f
#endif // Else, no name (avoid unused param warning).
) { BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ }
/** @cond */
private:

View File

@@ -39,11 +39,21 @@ functions (for subcontracting).
Virtual public functions (and therefore also public function overrides)
declaring contracts using this library must specify an extra function parameter
at the very end of the parameter list.
at the very end of their parameter list.
This parameter must be a pointer to this class and it must have default value
@c 0 (i.e., @c nullptr).
(This extra parameter is often named @c v in this documentation, but any name
can be used.)
@c 0 or @c nullptr (this extra parameter is often named @c v in this
documentation, but any name can be used):
@code
class u {
public:
virtual void f(int x, boost::contract::virtual_* v = 0) { // Declare `v`.
... // Contract declaration (which will use `v`) and function body.
}
...
};
@endcode
In practice this extra parameter does not alter the calling interface of the
enclosing function declaring the contract because it is always the very last

View File

@@ -26,7 +26,7 @@ namespace boost { namespace contract {
Program contracts for destructors.
This is used to specify postconditions, exception guarantees, old value copies
at body, and check class invariants for destructors (destructors cannot not have
at body, and check class invariants for destructors (destructors cannot have
preconditions, see
@RefSect{contract_programming_overview.destructor_calls, Destructor Calls}):
@@ -83,10 +83,11 @@ postconditions and exception guarantees, within classes that have no invariants.
(Usually this template parameter is automatically deduced by C++
and it does not need to be explicitly specified by programmers.)
@return The result of this function must be explicitly assigned to a variable of
type @RefClass{boost::contract::check} declared locally just before the
code of the destructor body (otherwise this library will generate a
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code of
the destructor body (otherwise this library will generate a run-time
error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
template<class Class>
specify_old_postcondition_except<> destructor(Class* obj) {

View File

@@ -12,11 +12,13 @@
#include <boost/contract/detail/declspec.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/noncopyable.hpp>
#include <boost/config.hpp>
namespace boost { namespace contract { namespace detail {
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4275) // Base w/o DLL spec (noncopyable).
#pragma warning(disable: 4251) // Member w/o DLL spec (mutex_ type).
#endif

View File

@@ -17,6 +17,7 @@
#include <boost/function.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/mpl/if.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#endif
/* PRIVATE */
@@ -73,7 +74,7 @@ public:
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
BOOST_CONTRACT_DETAIL_COND_POST_DEF_(
none,
unused,
/* r */ BOOST_PP_EMPTY(),
void (),
// Won't raise this error if NO_POST (for optimization).
BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed,

View File

@@ -143,7 +143,10 @@ public:
boost::contract::from from,
boost::contract::virtual_* v,
C* obj,
VR& r
VR&
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS // Avoid unused param warning.
r
#endif
BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(1,
BOOST_CONTRACT_MAX_ARGS, Args, &, args)

View File

@@ -0,0 +1,31 @@
#ifndef BOOST_CONTRACT_DETAIL_EXCEPTION_HPP_
#define BOOST_CONTRACT_DETAIL_EXCEPTION_HPP_
// Copyright (C) 2008-2019 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).
// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
#include <boost/config.hpp>
#include <exception>
namespace boost { namespace contract { namespace detail {
// Using this instead of std::uncaught_exception() because
// std::uncaught_exception will be removed in C++20.
inline bool uncaught_exception() BOOST_NOEXCEPT {
// Alternatively, this could just return `boost::core::uncaught_exceptions()
// > 0` but that emulates the exception count which is not needed by this
// lib (the implementation below is simpler and could be faster).
#ifdef __cpp_lib_uncaught_exceptions
return std::uncaught_exceptions() > 0;
#else
return std::uncaught_exception();
#endif
}
} } } // namespace
#endif // #include guard

View File

@@ -11,6 +11,7 @@
#include <boost/contract/core/config.hpp>
#include <boost/contract/detail/condition/cond_inv.hpp>
#include <boost/contract/detail/none.hpp>
#include <boost/contract/detail/exception.hpp>
#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
!defined(BOOST_CONTRACT_NO_INVARIANTS) || \
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
@@ -70,7 +71,7 @@ public:
// If ctor body threw, no obj so check only static inv. Otherwise,
// obj constructed so check static inv, non-static inv, and post.
if(std::uncaught_exception()) {
if(uncaught_exception()) {
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
this->check_exit_static_inv();
#endif

View File

@@ -11,6 +11,7 @@
#include <boost/contract/core/config.hpp>
#include <boost/contract/detail/condition/cond_inv.hpp>
#include <boost/contract/detail/none.hpp>
#include <boost/contract/detail/exception.hpp>
#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
!defined(BOOST_CONTRACT_NO_INVARIANTS) || \
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
@@ -77,7 +78,7 @@ public:
// language allows for that (even if in C++11 dtors declarations are
// implicitly noexcept(true) unless specified otherwise) so this
// library must handle such a case.
if(std::uncaught_exception()) {
if(uncaught_exception()) {
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
this->check_exit_all_inv();
#endif

View File

@@ -10,6 +10,7 @@
#include <boost/contract/core/exception.hpp>
#include <boost/contract/core/config.hpp>
#include <boost/contract/detail/condition/cond_post.hpp>
#include <boost/contract/detail/exception.hpp>
#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
@@ -63,7 +64,7 @@ public:
checking k;
#endif
if(std::uncaught_exception()) {
if(uncaught_exception()) {
#ifndef BOOST_CONTRACT_NO_EXCEPTS
this->check_except();
#endif

View File

@@ -10,9 +10,10 @@
#include <boost/contract/core/virtual.hpp>
#include <boost/contract/core/exception.hpp>
#include <boost/contract/core/config.hpp>
#include <boost/contract/core/virtual.hpp>
#include <boost/contract/detail/condition/cond_subcontracting.hpp>
#include <boost/contract/detail/tvariadic.hpp>
#include <boost/contract/core/virtual.hpp>
#include <boost/contract/detail/exception.hpp>
#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
!defined(BOOST_CONTRACT_NO_INVARIANTS) || \
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
@@ -113,7 +114,7 @@ private:
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
this->check_subcontracted_exit_inv();
#endif
if(std::uncaught_exception()) {
if(uncaught_exception()) {
#ifndef BOOST_CONTRACT_NO_EXCEPTS
this->check_subcontracted_except();
#endif
@@ -141,7 +142,7 @@ public:
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
this->check_subcontracted_exit_inv();
#endif
if(std::uncaught_exception()) {
if(uncaught_exception()) {
#ifndef BOOST_CONTRACT_NO_EXCEPTS
this->check_subcontracted_except();
#endif

View File

@@ -11,6 +11,7 @@
#include <boost/contract/core/config.hpp>
#include <boost/contract/detail/condition/cond_inv.hpp>
#include <boost/contract/detail/none.hpp>
#include <boost/contract/detail/exception.hpp>
#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
!defined(BOOST_CONTRACT_NO_INVARIANTS) || \
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
@@ -84,7 +85,7 @@ public:
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
this->check_exit_static_inv();
#endif
if(std::uncaught_exception()) {
if(uncaught_exception()) {
#ifndef BOOST_CONTRACT_NO_EXCEPTS
this->check_except();
#endif

View File

@@ -66,9 +66,10 @@ postconditions, and exception guarantees.
@RefSect{advanced.lambdas__loops__code_blocks__and__constexpr__,
Lambdas\, Loops\, Code Blocks}
@return The result of this function must be explicitly assigned to a variable of
type @RefClass{boost::contract::check} declared locally just before the
function body code (otherwise this library will generate a run-time
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code of
the function body (otherwise this library will generate a run-time
error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
inline specify_precondition_old_postcondition_except<> function() {

View File

@@ -98,10 +98,10 @@ Where:
@RefClass{boost::contract::virtual_}<c>*</c> and default value @c 0
from the enclosing virtual public function or public function
overrides declaring the contract.
@arg <c><b>old_expr</b></c> is the expression to be evaluated and copied to
@arg <c><b>old_expr</b></c> is the expression to be evaluated and copied into
the old value pointer.
(This is not a variadic macro parameter so any comma it might contain
must be protected by round parenthesis,
must be protected by round parenthesis and
<c>BOOST_CONTRACT_OLDOF(v, (old_expr))</c> will always work.)
On compilers that do not support variadic macros, programmers can manually copy
@@ -130,27 +130,27 @@ Trait to check if an old value type can be copied or not.
By default, this unary boolean meta-function is equivalent to
@c boost::is_copy_constructible<T> but programmers can chose to specialize it
for user-defined types (in general some kind of specialization is needed on
for user-defined types (in general some kind of specialization is also needed on
compilers that do not support C++11, see
<a href="http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/boost_typetraits/reference/is_copy_constructible.html">
<c>boost::is_copy_constructible</c></a>):
@code
class u; // Some user-defined type.
class u; // Some user-defined type for which old values shall not be copied.
namespace boost { namespace contract {
template<> // Specialization.
template<> // Specialization to not copy old values of type `u`.
struct is_old_value_copyable<u> : boost::false_type {};
} } // namespace
@endcode
In summary, a given old value type @c T is copied only if
A given old value type @c T is copied only if
@c boost::contract::is_old_value_copyable<T>::value is @c true.
Copyable old value types are always copied using
@c boost::contract::old_value_copy<T>.
Non-copyable old value types generate a compile-time error when
@c boost::contract::old_ptr<T> is dereferenced, but instead leave
@c boost::contract::old_ptr_if_copyable<T> always null (without generating
A copyable old value type @c V is always copied using
@c boost::contract::old_value_copy<V>.
A non-copyable old value type @c W generates a compile-time error when
@c boost::contract::old_ptr<W> is dereferenced, but instead leaves
@c boost::contract::old_ptr_if_copyable<W> always null (without generating
compile-time errors).
@see @RefSect{extras.old_value_requirements__templates_,
@@ -170,7 +170,7 @@ struct is_old_value_copyable<old_value> : boost::true_type {};
Trait to copy an old value.
By default, the implementation of this trait uses @c T's copy constructor to
make one single copy of the specified @p value.
make one single copy of the specified value.
However, programmers can specialize this trait to copy old values using
user-specific operations different from @c T's copy constructor.
The default implementation of this trait is equivalent to:
@@ -180,7 +180,7 @@ template<typename T>
class old_value_copy {
public:
explicit old_value_copy(T const& old) :
old_(value) // One single copy of value using T's copy constructor.
old_(old) // One single copy of value using T's copy constructor.
{}
T const& old() const { return old_; }
@@ -204,8 +204,8 @@ struct old_value_copy {
This is the only operation within this library that actually copies old
values.
This ensures this library makes one and only one copy of old values (if they
actually need to be copied).
This ensures this library makes one and only one copy of an old value (if
they actually need to be copied, see @RefMacro{BOOST_CONTRACT_NO_OLDS}).
@param old The old value to copy.
*/
@@ -232,7 +232,7 @@ class old_ptr_if_copyable;
/**
Old value pointer that requires the pointed old value type to be copyable.
This is set to point to an actual old value copy using either
This pointer can be set to point an actual old value copy using either
@RefMacro{BOOST_CONTRACT_OLDOF} or @RefFunc{boost::contract::make_old} (that is
why this class does not have public non-default constructors):
@@ -240,7 +240,7 @@ why this class does not have public non-default constructors):
class u {
public:
virtual void f(..., boost::contract::virtual_* v = 0) {
boost::contract::old_ptr<old_type> old_var =
boost::contract::old_ptr<old_type> old_var = // For copyable `old_type`.
BOOST_CONTRACT_OLDOF(v, old_expr);
...
}
@@ -253,9 +253,9 @@ public:
@tparam T Type of the pointed old value.
This type must be copyable (i.e.,
<c>boost::contract::is_old_value_copyable<T>::value</c> is @c true),
otherwise this pointer will always be null and this library will
generate a compile-time error when the pointer is dereferenced.
<c>boost::contract::is_old_value_copyable<T>::value</c> must be
@c true), otherwise this pointer will always be null and this library
will generate a compile-time error when the pointer is dereferenced.
*/
template<typename T>
class old_ptr { /* copyable (as *) */
@@ -300,11 +300,11 @@ public:
@return A pointer to the old value (null if this old value pointer is null).
Contract assertions should not change the state of the program so
this member function is @c const and it returns the old value as a
constant pointer to a constant object (see
pointer to a constant object (see
@RefSect{contract_programming_overview.constant_correctness,
Constant Correctness}).
*/
T const* const operator->() const {
T const* operator->() const {
BOOST_STATIC_ASSERT_MSG(
boost::contract::is_old_value_copyable<T>::value,
"old_ptr<T> requires T copyble (see is_old_value_copyable<T>), "
@@ -319,7 +319,7 @@ public:
!!typed_copy_)
#else
/**
Check if this old value pointer is null or not.
Query if this old value pointer is null or not (safe-bool operator).
(This is implemented using safe-bool emulation on compilers that do not
support C++11 explicit type conversion operators.)
@@ -347,7 +347,7 @@ private:
Old value pointer that does not require the pointed old value type to be
copyable.
This is set to point to an actual old value copy using either
This pointer can be set to point to an actual old value copy using either
@RefMacro{BOOST_CONTRACT_OLDOF} or @RefFunc{boost::contract::make_old}:
@code
@@ -387,7 +387,8 @@ public:
/**
Construct this old value pointer from an old value pointer that requires
the old value type to be copyable.
Ownership of the pointed value object is transferred to this pointer.
This constructor is implicitly called by this library when assigning an
object of this type using @RefMacro{BOOST_CONTRACT_OLDOF} (this constructor
is usually not explicitly called by user code).
@@ -427,11 +428,11 @@ public:
@return A pointer to the old value (null if this old value pointer is null).
Contract assertions should not change the state of the program so
this member function is @c const and it returns the old value as a
constant pointer to a constant object (see
pointer to a constant object (see
@RefSect{contract_programming_overview.constant_correctness,
Constant Correctness}).
*/
T const* const operator->() const {
T const* operator->() const {
if(typed_copy_) return &typed_copy_->old();
return 0;
}
@@ -441,7 +442,7 @@ public:
!!typed_copy_)
#else
/**
Check if this old value pointer is null or not (safe-bool operator).
Query if this old value pointer is null or not (safe-bool operator).
(This is implemented using safe-bool emulation on compilers that do not
support C++11 explicit type conversion operators.)
@@ -467,13 +468,13 @@ private:
/**
Convert user-specified expressions to old values.
This class is often only implicitly used by this library and it does not
This class is usually only implicitly used by this library and it does not
explicitly appear in user code.
On older compilers that cannot correctly deduce the
@c boost::contract::is_old_value_copyable trait, programmers can manually
specialize that trait to make sure that only old value types that are copyable
are actually copied.
@c boost::contract::is_old_value_copyable trait used in the declaration of this
class, programmers can manually specialize that trait to make sure that only old
value types that are copyable are actually copied.
@see @RefSect{extras.old_value_requirements__templates_,
Old Value Requirements}
@@ -486,10 +487,11 @@ public:
Construct this object from the specified old value when the old value type
is copy constructible.
The specified old value is copied (one time only) using
@c boost::contract::old_value_copy, in which case related old value pointer
will not be null (no copy is made if postconditions and exception guarantees
are not being checked, see @RefMacro{BOOST_CONTRACT_NO_OLDS}).
The specified old value @c old is copied (one time only) using
@c boost::contract::old_value_copy, in which case the related old value
pointer will not be null (but no copy is made if postconditions and
exception guarantees are not being checked, see
@RefMacro{BOOST_CONTRACT_NO_OLDS}).
@param old Old value to be copied.
@@ -497,7 +499,12 @@ public:
*/
template<typename T>
/* implicit */ old_value(
T const& old,
T const&
#if !defined(BOOST_CONTRACT_NO_OLDS) || \
defined(BOOST_CONTRACT_DETAIL_DOXYGEN)
old
#endif // Else, no name (avoid unused param warning).
,
typename boost::enable_if<boost::contract::is_old_value_copyable<T>
>::type* = 0
)
@@ -510,10 +517,10 @@ public:
Construct this object from the specified old value when the old value type
is not copyable.
The specified old value cannot be copied in this case so it is not copied
and the related old value pointer will always be null (thus a call to this
constructor has no effect and it will likely be optimized away by most
compilers).
The specified old value @c old cannot be copied in this case so it is not
copied and the related old value pointer will always be null (thus calls to
this constructor have no effect and they will likely be optimized away by
most compilers).
@param old Old value (that will not be copied in this case).
@@ -521,7 +528,11 @@ public:
*/
template<typename T>
/* implicit */ old_value(
T const& old,
T const&
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
old
#endif // Else, no name (avoid unused param warning).
,
typename boost::disable_if<boost::contract::is_old_value_copyable<T>
>::type* = 0
) {} // Leave ptr_ null (thus no copy of T).
@@ -540,9 +551,9 @@ private:
};
/**
Convert old value copies to old value pointers.
Convert old value copies into old value pointers.
This class is often only implicitly used by this library and it does not
This class is usually only implicitly used by this library and it does not
explicitly appear in user code (that is why this class does not have public
constructors, etc.).
*/
@@ -553,7 +564,7 @@ public:
type @c T might or not be copyable.
For example, this is implicitly called when assigning or initializing old
value pointers.
value pointers of type @c boost::contract::old_ptr_if_copyable.
@tparam T Type of the pointed old value.
The old value pointer will always be null if this type is not
@@ -571,7 +582,7 @@ public:
type @c T must be copyable.
For example, this is implicitly called when assigning or initializing old
value pointers.
value pointers of type @c boost::contract::old_ptr.
@tparam T Type of the pointed old value. This type must be copyable
(see @c boost::contract::is_old_value_copyable),
@@ -585,11 +596,12 @@ public:
/** @cond */
private:
explicit old_pointer(virtual_* v, old_value const& old)
#ifndef BOOST_CONTRACT_NO_OLDS
: v_(v), untyped_copy_(old.untyped_copy_)
#endif
{}
#ifndef BOOST_CONTRACT_NO_OLDS
explicit old_pointer(virtual_* v, old_value const& old)
: v_(v), untyped_copy_(old.untyped_copy_) {}
#else
explicit old_pointer(virtual_* /* v */, old_value const& /* old */) {}
#endif
template<typename Ptr>
Ptr get() {
@@ -664,10 +676,10 @@ private:
};
/**
Return a null old value.
Return a "null" old value.
The related old value pointer will also be null.
This function is often only used by the code expanded by
This function is usually only called by the code expanded by
@RefMacro{BOOST_CONTRACT_OLDOF}.
@see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}
@@ -683,8 +695,8 @@ functions overrides).
The related old value pointer will not be null if the specified old value was
actually copied.
This function is often only used by code expanded by
@c BOOST_CONTRACT_OLDOF(old_expr):
This function is usually only called by code expanded by
@c BOOST_CONTRACT_OLDOF(old_expr) as in:
@code
boost::contract::make_old(boost::contract::copy_old() ? old_expr :
@@ -695,7 +707,7 @@ boost::contract::make_old(boost::contract::copy_old() ? old_expr :
@param old Old value which is usually implicitly constructed from the user old
value expression to be copied (use the ternary operator <c>?:</c>
to avoid evaluating the old value expression all together when
to completely avoid to evaluate the old value expression when
@c boost::contract::copy_old() is @c false).
@return Old value pointer (usually implicitly converted to either
@@ -711,8 +723,8 @@ overrides).
The related old value pointer will not be null if the specified old value was
actually copied.
This function is often only used by code expanded by
@c BOOST_CONTRACT_OLDOF(v, old_expr):
This function is usually only called by code expanded by
@c BOOST_CONTRACT_OLDOF(v, old_expr) as in:
@code
boost::contract::make_old(v, boost::contract::copy_old(v) ? old_expr :
@@ -727,7 +739,7 @@ boost::contract::make_old(v, boost::contract::copy_old(v) ? old_expr :
the contract.
@param old Old value which is usually implicitly constructed from the user old
value expression to be copied (use the ternary operator <c>?:</c>
to avoid evaluating the old value expression all together when
to completely avoid to evaluate the old value expression when
@c boost::contract::copy_old(v) is @c false).
@return Old value pointer (usually implicitly converted to either
@@ -738,13 +750,13 @@ boost::contract::make_old(v, boost::contract::copy_old(v) ? old_expr :
old_pointer make_old(virtual_* v, old_value const& old);
/**
Check if old values need to be copied (but not for virtual public functions and
Query if old values need to be copied (but not for virtual public functions and
public function overrides).
For example, this function always returns false when both postconditions and
exception guarantees are not being checked (see
@RefMacro{BOOST_CONTRACT_NO_OLDS}).
This function is often only used by the code expanded by
This function is usually only called by the code expanded by
@RefMacro{BOOST_CONTRACT_OLDOF}.
@see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}
@@ -764,7 +776,7 @@ inline bool copy_old() {
}
/**
Check if old values need to be copied (for virtual public functions and public
Query if old values need to be copied (for virtual public functions and public
function overrides).
For example, this function always returns false when both postconditions and
@@ -772,7 +784,7 @@ exception guarantees are not being checked (see
@RefMacro{BOOST_CONTRACT_NO_OLDS}).
In addition, this function returns false when overridden functions are being
called subsequent times by this library to support subcontracting.
This function is often only used by the code expanded by
This function is usually only called by the code expanded by
@RefMacro{BOOST_CONTRACT_OLDOF}.
@see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}
@@ -784,8 +796,8 @@ This function is often only used by the code expanded by
@return True if old values need to be copied, false otherwise.
*/
inline bool copy_old(virtual_* v) {
#ifndef BOOST_CONTRACT_NO_OLDS
#ifndef BOOST_CONTRACT_NO_OLDS
inline bool copy_old(virtual_* v) {
if(!v) {
#ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
return !boost::contract::detail::checking::already();
@@ -795,10 +807,16 @@ inline bool copy_old(virtual_* v) {
}
return v->action_ == boost::contract::virtual_::push_old_init_copy ||
v->action_ == boost::contract::virtual_::push_old_ftor_copy;
#else
}
#else
inline bool copy_old(virtual_*
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
v
#endif
) {
return false; // No post checking, so never copy old values.
#endif
}
}
#endif
} } // namespace

View File

@@ -18,20 +18,21 @@ Handle public function overrides (for subcontracting).
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
/**
Declare an override type with an arbitrary name.
Declare an override type trait with an arbitrary name.
Declare the override type to pass as an explicit template parameter to
@RefFunc{boost::contract::public_function} for public function overrides.
Declare the override type trait named @c type_name to pass as an explicit
template parameter to @RefFunc{boost::contract::public_function} for public
function overrides.
@see @RefSect{advanced.named_overrides, Named Overrides}
@param type_name Name of the override type this macro will declare.
@param type_name Name of the override type trait this macro will declare.
(This is not a variadic macro parameter but it should
never contain commas because it is an identifier.)
@param func_name Function name of the public function override.
This macro is called just once even if the function name
is overloaded (the same override type is used for all
overloaded functions with the same name, see
is overloaded (the same override type trait is used for
all overloaded functions with the same name, see
@RefSect{advanced.function_overloads,
Function Overloads}).
(This is not a variadic macro parameter but it should
@@ -113,17 +114,21 @@ Handle public function overrides (for subcontracting).
/* PUBLIC */
/**
Declare an override type named <c>override_<i>func_name</i></c>.
Declare an override type trait named <c>override_<i>func_name</i></c>.
Declare the override type to pass as an explicit template parameter to
@RefFunc{boost::contract::public_function} for public function overrides.
Declare the override type trait named <c>override_<i>func_name</i></c> to pass
as an explicit template parameter to @RefFunc{boost::contract::public_function}
for public function overrides.
Use @RefMacro{BOOST_CONTRACT_NAMED_OVERRIDE} to generate an override type trait
with a name different than <c>override_<i>func_name</i></c> (usually not
needed).
@see @RefSect{tutorial.public_function_overrides__subcontracting_,
Public Function Overrides}
@param func_name Function name of the public function override.
This macro is called just once even if the function name is
overloaded (the same override type is used for all
overloaded (the same override type trait is used for all
overloaded functions with the same name, see
@RefSect{advanced.function_overloads, Function Overloads}).
(This is not a variadic macro parameter but it should never
@@ -134,10 +139,10 @@ Declare the override type to pass as an explicit template parameter to
#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
/**
Declare multiple override types at once naming them <c>override_...</c> (for
convenience).
Declare multiple override type traits at once naming them
<c>override_...</c> (for convenience).
This variadic macro is provided for convenience only,
This variadic macro is provided for convenience as
<c>BOOST_CONTRACT_OVERRIDES(f_1, f_2, ..., f_n)</c> expands to code
equivalent to:
@@ -149,7 +154,7 @@ Declare the override type to pass as an explicit template parameter to
@endcode
On compilers that do not support variadic macros,
the override types can be equivalently programmed one-by-one calling
the override type traits can be equivalently programmed one-by-one calling
@RefMacro{BOOST_CONTRACT_OVERRIDE} for each function name as shown above.
@see @RefSect{tutorial.public_function_overrides__subcontracting_,

View File

@@ -9,7 +9,8 @@
/** @file
Program contracts for public functions (including subcontracting).
Overloads handle public functions that are static, virtual void, virtual non-void, overriding void, and overriding non-void.
The different overloads handle public functions that are static, virtual void,
virtual non-void, overriding void, and overriding non-void.
*/
#include <boost/contract/core/config.hpp>
@@ -47,6 +48,7 @@ Overloads handle public functions that are static, virtual void, virtual non-voi
#endif
#include <boost/preprocessor/control/expr_iif.hpp>
#include <boost/preprocessor/control/iif.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
namespace boost { namespace contract {
@@ -121,11 +123,12 @@ have no static invariants.
This template parameter must be explicitly specified for static
public functions (because they have no object @c this so there
is no function argument from which this type template parameter
can be deduced by this library).
can be automatically deduced by C++).
@return The result of this function must be explicitly assigned to a variable of
type @RefClass{boost::contract::check} declared locally just before the
code of the static function body (otherwise this library will generate a
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code of
the static public function body (otherwise this library will generate a
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
template<class Class>
@@ -204,9 +207,10 @@ no invariants.
(Usually this template parameter is automatically deduced by C++
and it does not need to be explicitly specified by programmers.)
@return The result of this function must be explicitly assigned to a variable of
type @RefClass{boost::contract::check} declared locally just before the
code of the public function body (otherwise this library will generate a
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code of
the public function body (otherwise this library will generate a
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
template<class Class>
@@ -372,10 +376,11 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
C++ and it does not need to be explicitly specified by
programmers.)
@return The result of this function must be explicitly assigned to a
variable of type @RefClass{boost::contract::check} declared locally
just before the code of the public function body (otherwise this
library will generate a run-time error, see
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code
of the public function body (otherwise this library will generate a
run-time error, see
@RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
template<class Class>
@@ -474,10 +479,11 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
C++ and it does not need to be explicitly specified by
programmers.)
@return The result of this function must be explicitly assigned to a
variable of type @RefClass{boost::contract::check} declared locally
just before the code of the public function body (otherwise this
library will generate a run-time error, see
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code
of the public function body (otherwise this library will generate a
run-time error, see
@RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
template<typename VirtualResult, class Class>
@@ -498,7 +504,7 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
BOOST_CONTRACT_DETAIL_DECL_OVERRIDING_PUBLIC_FUNCTION_Z(z, \
arity, /* is_friend = */ 0, has_virtual_result, \
Override, VirtualResult, F, Class, Args, \
v, r, f, obj, args \
v, r, /* f */ BOOST_PP_EMPTY(), obj, args \
) { \
BOOST_PP_IIF(BOOST_CONTRACT_PUBLIC_FUNCTIONS_IMPL_, \
{ /* extra scope paren to expand STATIC_STATIC emu on same line */ \
@@ -646,7 +652,8 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
@RefClass{boost::contract::virtual_}<c>*</c> and default value
@c 0 from the enclosing public function override.
@param f A pointer to the enclosing public function override declaring
the contract.
the contract (but see @RefSect{advanced.function_overloads,
Function Overloads}).
@param obj The object @c this from the scope of the enclosing public
function override declaring the contract.
This object might be mutable, @c const, @c volatile, or
@@ -660,9 +667,9 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
appear in the enclosing function declaration), but excluding the
trailing argument @c v.
@tparam Override The type <c>override_<i>function-name</i></c> declared
using the @RefMacro{BOOST_CONTRACT_OVERRIDE} or related
macros.
@tparam Override The type trait <c>override_<i>function-name</i></c>
declared using the @RefMacro{BOOST_CONTRACT_OVERRIDE} or
related macros.
This template parameter must be explicitly specified
(because there is no function argument from which it can
be automatically deduced by C++).
@@ -670,8 +677,7 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
override declaring the contract.
(Usually this template parameter is automatically deduced by
C++ and it does not need to be explicitly specified by
programmers, but see
@RefSect{advanced.function_overloads, Function Overloads}.)
programmers.)
@tparam Class The type of the class containing the virtual public function
declaring the contract.
(Usually this template parameter is automatically deduced by
@@ -689,10 +695,11 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
by C++ and they do not need to be explicitly specified by
programmers.)
@return The result of this function must be explicitly assigned to a
variable of type @RefClass{boost::contract::check} declared locally
just before the code of the public function body (otherwise this
library will generate a run-time error, see
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code
of the public function body (otherwise this library will generate a
run-time error, see
@RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
template<class Override, typename F, class Class, typename... Args>
@@ -773,7 +780,8 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
programmers must set it to the actual value being returned by
the function at each @c return statement.
@param f A pointer to the enclosing public function override declaring
the contract.
the contract (but see @RefSect{advanced.function_overloads,
Function Overloads}).
@param obj The object @c this from the scope of the enclosing public
function override declaring the contract.
This object might be mutable, @c const, @c volatile, or
@@ -787,9 +795,9 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
appear in the enclosing function declaration), but excluding the
trailing argument @c v.
@tparam Override The type <c>override_<i>function-name</i></c> declared
using the @RefMacro{BOOST_CONTRACT_OVERRIDE} or related
macros.
@tparam Override The type trait <c>override_<i>function-name</i></c>
declared using the @RefMacro{BOOST_CONTRACT_OVERRIDE} or
related macros.
This template parameter must be explicitly specified
(because there is no function argument from which it can
be automatically deduced by C++).
@@ -811,9 +819,7 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
override declaring the contract.
(Usually this template parameter is automatically deduced by
C++ and it does not need to be explicitly specified by
programmers, but see
@RefSect{advanced.function_overloads,
Function Overloads}.)
programmers.)
@tparam Class The type of the class containing the virtual public function
declaring the contract.
(Usually this template parameter is automatically deduced by
@@ -831,10 +837,11 @@ specify_precondition_old_postcondition_except<> public_function(Class* obj) {
by C++ and they do not need to be explicitly specified by
programmers.)
@return The result of this function must be explicitly assigned to a
variable of type @RefClass{boost::contract::check} declared locally
just before the code of the public function body (otherwise this
library will generate a run-time error, see
@return The result of this function must be assigned to a variable of type
@RefClass{boost::contract::check} declared explicitly (i.e., without
using C++11 @c auto declarations) and locally just before the code
of the public function body (otherwise this library will generate a
run-time error, see
@RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}).
*/
template<class Override, typename VirtualResult, typename F, class Class,