2 #ifndef BOOST_CONTRACT_MACRO_HPP_
3 #define BOOST_CONTRACT_MACRO_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
11 Allow to disable contracts to completely remove their compile-time and run-time
13 This header automatically includes all header files <c>boost/contract/\*.hpp</c>
14 necessary to use its macros.
16 Almost all the macros defined in this header file are variadic macros. On
17 compilers that do not support variadic macros, programmers can manually code
18 <c>\#ifndef BOOST_CONTRACT_NO_...</c> statements instead (see
19 @RefSect{extras.disable_contract_compilation__macro_interface_,
20 Disable Contract Compilation}).
23 // IMPORTANT: Following headers can always be #included (without any #if-guard)
24 // because they expand to trivial code that does not affect compile-time. These
25 // headers must always be #included here (without any #if-guard) because they
26 // define types and macros that are typically left in user code even when
27 // contracts are disables (these types and macros never affect run-time and
28 // their definitions are trivial when contracts are disabled so their impact on
29 // compile-time is negligible).
30 #include <boost/contract/override.hpp>
31 #include <boost/contract/base_types.hpp>
32 #include <boost/contract/core/constructor_precondition.hpp>
33 #include <boost/contract/core/check_macro.hpp>
34 #include <boost/contract/core/access.hpp>
35 #include <boost/contract/core/virtual.hpp>
36 #include <boost/contract/core/exception.hpp>
37 #include <boost/contract/core/config.hpp>
39 #ifndef BOOST_CONTRACT_NO_CONDITIONS
40 #include <boost/contract/assert.hpp>
43 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
45 Program preconditions that can be completely disabled at compile-time.
47 @c BOOST_CONTRACT_PRECONDITION(f) expands to code equivalent to the
48 following (note that no code is generated when
49 @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS} is defined):
52 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
59 @arg <c><b>f</b></c> is the nullay functor called by this library to
60 check preconditions @c f().
61 Assertions within this functor are usually programmed using
62 @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call
63 to this functor indicates a contract assertion failure (and will
64 result in this library calling
65 @RefFunc{boost::contract::precondition_failure}).
66 This functor should capture variables by (constant) value, or better
67 by (constant) reference (to avoid extra copies).
68 (This is a variadic macro parameter so it can contain commas not
69 protected by round parenthesis.)
71 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
72 Disable Contract Compilation},
73 @RefSect{tutorial.preconditions, Preconditions}
75 #define BOOST_CONTRACT_PRECONDITION(...)
76 #elif !defined(BOOST_CONTRACT_NO_PRECONDITIONS)
77 #define BOOST_CONTRACT_PRECONDITION(...) .precondition(__VA_ARGS__)
79 #define BOOST_CONTRACT_PRECONDITION(...) /* nothing */
82 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
84 Program postconditions that can be completely disabled at compile-time.
86 @c BOOST_CONTRACT_POSTCONDITION(f) expands to code equivalent to the
87 following (note that no code is generated when
88 @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS} is defined):
91 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
98 @arg <c><b>f</b></c> is the functor called by this library to check
99 postconditions @c f() or @c f(result).
100 Assertions within this functor are usually programmed using
101 @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call
102 to this functor indicates a contract assertion failure (and will
103 result in this library calling
104 @RefFunc{boost::contract::postcondition_failure}).
105 This functor should capture variables by (constant) references (to
106 access the values they will have at function exit).
107 This functor takes the return value (preferably by <c>const&</c>)
108 @c result as its one single parameter @c f(result) but only for
109 virtual public functions and public functions overrides, otherwise
110 it takes no parameter @c f().
111 (This is a variadic macro parameter so it can contain commas not
112 protected by round parenthesis.)
114 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
115 Disable Contract Compilation},
116 @RefSect{tutorial.postconditions, Postconditions}
118 #define BOOST_CONTRACT_POSTCONDITION(...)
119 #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
120 #define BOOST_CONTRACT_POSTCONDITION(...) .postcondition(__VA_ARGS__)
122 #define BOOST_CONTRACT_POSTCONDITION(...) /* nothing */
125 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
127 Program exception guarantees that can be completely disabled at
130 @c BOOST_CONTRACT_EXCEPT(f) expands to code equivalent to the following
131 (note that no code is generated when @RefMacro{BOOST_CONTRACT_NO_EXCEPTS}
135 #ifndef BOOST_CONTRACT_NO_EXCEPTS
142 @arg <c><b>f</b></c> is the nullary functor called by this library to
143 check exception guarantees @c f().
144 Assertions within this functor are usually programmed using
145 @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call
146 to this functor indicates a contract assertion failure (and will
147 result in this library calling
148 @RefFunc{boost::contract::except_failure}).
149 This functor should capture variables by (constant) references (to
150 access the values they will have at function exit).
151 (This is a variadic macro parameter so it can contain commas not
152 protected by round parenthesis.)
154 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
155 Disable Contract Compilation},
156 @RefSect{tutorial.exception_guarantees, Exception Guarantees}
158 #define BOOST_CONTRACT_EXCEPT(...)
159 #elif !defined(BOOST_CONTRACT_NO_EXCEPTS)
160 #define BOOST_CONTRACT_EXCEPT(...) .except(__VA_ARGS__)
162 #define BOOST_CONTRACT_EXCEPT(...) /* nothing */
165 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
167 Program old value copies at body that can be completely disabled at
170 @c BOOST_CONTRACT_OLD(f) expands to code equivalent to the following (note
171 that no code is generated when @RefMacro{BOOST_CONTRACT_NO_OLDS} is
175 #ifndef BOOST_CONTRACT_NO_OLDS
182 @arg <c><b>f</b></c> is the nullary functor called by this library
183 @c f() to assign old value copies just before the body is execute
184 but after entry invariants (when they apply) and preconditions are
186 Old value pointers within this functor call are usually assigned
187 using @RefMacro{BOOST_CONTRACT_OLDOF}.
188 Any exception thrown by a call to this functor will result in
189 this library calling @RefFunc{boost::contract::old_failure} (because
190 old values could not be copied to check postconditions and exception
192 This functor should capture old value pointers by references so they
193 can be assigned (all other variables needed to evaluate old value
194 expressions can be captured by (constant) value, or better by
195 (constant) reference to avoid extra copies).
196 (This is a variadic macro parameter so it can contain commas not
197 protected by round parenthesis.)
199 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
200 Disable Contract Compilation},
201 @RefSect{advanced.old_values_copied_at_body,
202 Old Values Copied at Body}
204 #define BOOST_CONTRACT_OLD(...)
207 Program old values that can be completely disabled at compile-time for old
208 value types that are required to be copyable.
210 This is used to program old value copies for copyable types:
216 BOOST_CONTRACT_OLD_PTR(old_type_a)(old_var_a); // Null...
217 BOOST_CONTRACT_OLD_PTR(old_type_b)(old_var_b, old_expr_b); // Set.
218 BOOST_CONTRACT_PUBLIC_FUNCTION(this)
220 BOOST_CONTRACT_OLD([&] {
221 old_var_a = BOOST_CONTRACT_OLDOF(old_expr_a); // ...set.
227 ... // Function body.
230 virtual void g(..., boost::contract::virtual_* v = 0) {
231 BOOST_CONTRACT_OLD_PTR(old_type_a)(old_var_a); // No `v`
232 BOOST_CONTRACT_OLD_PTR(old_type_b)(v, old_var_b, old_expr_b); // `v`
233 BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
235 BOOST_CONTRACT_OLD([&] {
236 old_var_a = BOOST_CONTRACT_OLDOF(v, old_expr_a); // `v`
242 ... // Function body.
249 This is an overloaded variadic macro and it can be used in the following
250 different ways (note that no code is generated when
251 @RefMacro{BOOST_CONTRACT_NO_OLDS} is defined).
253 1\. <c>BOOST_CONTRACT_OLD_PTR(old_type)(old_var)</c> expands to code
254 equivalent to the following (this leaves the old value pointer null):
257 #ifndef BOOST_CONTRACT_NO_OLDS
258 // This declaration does not need to use `v`.
259 boost::contract::old_ptr<old_type> old_var
263 2\. <c>BOOST_CONTRACT_OLD_PTR(old_type)(old_var, old_expr)</c> expands to
264 code equivalent to the following (this initializes the pointer to the
265 old value copy, but not to be used for virtual public functions and
266 public function overrides):
269 #ifndef BOOST_CONTRACT_NO_OLDS
270 boost::contract::old_ptr<old_type> old_var =
271 BOOST_CONTRACT_OLDOF(old_expr)
275 3\. <c>BOOST_CONTRACT_OLD_PTR(old_type)(v, old_var, old_expr)</c> expands to
276 code equivalent to the following (this initializes the pointer to the
277 old value copy for virtual public functions and public function
281 #ifndef BOOST_CONTRACT_NO_OLDS
282 boost::contract::old_ptr<old_type> old_var =
283 BOOST_CONTRACT_OLDOF(v, old_expr)
289 @arg <c><b>old_type</b></c> is the type of the pointed old value.
290 This type must be copyable (i.e.,
291 <c>boost::contract::is_old_value_copyable<old_type>::value</c> is
292 @c true), otherwise this pointer will always be null and this
293 library will generate a compile-time error when the pointer is
294 dereferenced (see @RefMacro{BOOST_CONTRACT_OLD_PTR_IF_COPYABLE}).
295 (This is a variadic macro parameter so it can contain commas not
296 protected by round parenthesis.)
297 (Rationale: Template parameters like this one are specified to
298 this library macro interface using their own set of parenthesis
299 <c>SOME_MACRO(template_params)(other_params)</c>.)
300 @arg <c><b>v</b></c> is the extra training parameter of type
301 @RefClass{boost::contract::virtual_}<c>*</c> and default value @c 0
302 from the enclosing virtual public function or public function
303 override declaring the contract.
304 (This is not a variadic macro parameter but it should never contain
305 commas because it is an identifier.)
306 @arg <c><b>old_var</b></c> is the name of the old value pointer variable.
307 (This is not a variadic macro parameter but it should never contain
308 commas because it is an identifier.)
309 @arg <c><b>old_expr</b></c> is the expression to be evaluated and copied
310 in the old value pointer.
311 (This is not a variadic macro parameter so any comma it might
312 contain must be protected by round parenthesis and
313 <c>BOOST_CONTRACT_OLD_PTR(old_type)(v, old_var, (old_expr))</c>
316 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
317 Disable Contract Compilation},
318 @RefSect{tutorial.old_values, Old Values}
320 #define BOOST_CONTRACT_OLD_PTR(...)
323 Program old values that can be completely disabled at compile-time for old
324 value types that are not required to be copyable.
326 This is used to program old value copies for types that might or might not
330 template<typename T> // Type `T` might or not be copyable.
334 BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_a)(old_var_a);
335 BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_b)(old_var_b,
337 BOOST_CONTRACT_PUBLIC_FUNCTION(this)
339 BOOST_CONTRACT_OLD([&] {
340 old_var_a = BOOST_CONTRACT_OLDOF(old_expr_a);
343 ... // In postconditions or exception guarantees:
344 if(old_var_a) ... // Always null for non-copyable types.
345 if(old_var_b) ... // Always null for non-copyable types.
349 ... // Function body.
352 virtual void g(..., boost::contract::virtual_* v = 0) {
353 BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_a)(old_var_a);
354 BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_b)(v, old_var_b,
356 BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
358 BOOST_CONTRACT_OLD([&] {
359 old_var_a = BOOST_CONTRACT_OLDOF(v, old_expr_a);
362 ... // In postconditions or exception guarantees:
363 if(old_var_a) ... // Always null for non-copyable types.
364 if(old_var_b) ... // Always null for non-copyable types.
368 ... // Function body.
375 This is an overloaded variadic macro and it can be used in the following
376 different ways (note that no code is generated when
377 @RefMacro{BOOST_CONTRACT_NO_OLDS} is defined).
379 1\. <c>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var)</c> expands to
380 code equivalent to the following (this leaves the old value pointer
384 #ifndef BOOST_CONTRACT_NO_OLDS
385 // This declaration does not need to use `v`.
386 boost::contract::old_ptr_if_copyable<old_type> old_var
390 2\. <c>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var, old_expr)</c>
391 expands to code equivalent to the following (this initializes the
392 pointer to the old value copy, but not to be used for virtual public
393 functions and public function overrides):
396 #ifndef BOOST_CONTRACT_NO_OLDS
397 boost::contract::old_ptr_if_copyable<old_type> old_var =
398 BOOST_CONTRACT_OLDOF(old_expr)
402 3\. <c>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var,
403 old_expr)</c> expands to code equivalent to the following (this
404 initializes the pointer to the old value copy for virtual public
405 functions and public function overrides):
408 #ifndef BOOST_CONTRACT_NO_OLDS
409 boost::contract::old_ptr_if_copyable<old_type> old_var =
410 BOOST_CONTRACT_OLDOF(v, old_expr)
416 @arg <c><b>old_type</b></c> is the type of the pointed old value.
417 If this type is not copyable (i.e.,
418 <c>boost::contract::is_old_value_copyable<old_type>::value</c> is
419 @c false), this pointer will always be null, but this library will
420 not generate a compile-time error when this pointer is dereferenced
421 (see @RefMacro{BOOST_CONTRACT_OLD_PTR}).
422 (This is a variadic macro parameter so it can contain commas not
423 protected by round parenthesis.)
424 @arg <c><b>v</b></c> is the extra trailing parameter of type
425 @RefClass{boost::contract::virtual_}<c>*</c> and default value @c 0
426 from the enclosing virtual public function or public function
427 override declaring the contract.
428 (This is not a variadic macro parameter but it should never contain
429 commas because it is an identifier.)
430 @arg <c><b>old_var</b></c> is the name of the old value pointer variable.
431 (This is not a variadic macro parameter but it should never contain
432 commas because it is an identifier.)
433 @arg <c><b>old_expr</b></c> is the expression to be evaluated and copied
434 in the old value pointer.
435 (This is not a variadic macro parameter so any comma it might
436 contain must be protected by round parenthesis and
437 <c>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var,
438 (old_expr))</c> will always work.)
440 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
441 Disable Contract Compilation},
442 @RefSect{extras.old_value_requirements__templates_,
443 Old Value Requirements}
445 #define BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...)
446 #elif !defined(BOOST_CONTRACT_NO_OLDS)
447 #include <boost/contract/old.hpp>
448 #include <boost/preprocessor/facilities/overload.hpp>
449 #include <boost/preprocessor/facilities/empty.hpp>
450 #include <boost/preprocessor/cat.hpp>
454 #define BOOST_CONTRACT_OLD_VAR_1(ptr) \
456 #define BOOST_CONTRACT_OLD_VAR_2(ptr, expr) \
457 ptr = BOOST_CONTRACT_OLDOF(expr)
458 #define BOOST_CONTRACT_OLD_VAR_3(v, ptr, expr) \
459 ptr = BOOST_CONTRACT_OLDOF(v, expr)
461 #define BOOST_CONTRACT_OLD_VAR_(...) \
462 BOOST_PP_CAT(BOOST_PP_OVERLOAD(BOOST_CONTRACT_OLD_VAR_, __VA_ARGS__) \
463 (__VA_ARGS__), BOOST_PP_EMPTY())
467 #define BOOST_CONTRACT_OLD(...) .old(__VA_ARGS__)
469 #define BOOST_CONTRACT_OLD_PTR(...) \
470 boost::contract::old_ptr< __VA_ARGS__ > \
471 BOOST_CONTRACT_OLD_VAR_
473 #define BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...) \
474 boost::contract::old_ptr_if_copyable< __VA_ARGS__ > \
475 BOOST_CONTRACT_OLD_VAR_
477 #include <boost/preprocessor/tuple/eat.hpp>
479 #define BOOST_CONTRACT_OLD(...) /* nothing */
481 #define BOOST_CONTRACT_OLD_PTR(...) BOOST_PP_TUPLE_EAT(0)
483 #define BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...) BOOST_PP_TUPLE_EAT(0)
486 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
488 Program (constant) class invariants that can be completely disabled at
491 @c BOOST_CONTRACT_INVARIANT({ ... }) expands to code equivalent to the
492 following (note that no code is generated when
493 @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined):
496 #ifndef BOOST_CONTRACT_NO_INVARIANTS
497 void BOOST_CONTRACT_INVARIANT_FUNC() const {
505 @arg <b>{ ... }</b> is the definition of the function that checks class
506 invariants for public functions that are not static and not volatile
507 (see @RefMacro{BOOST_CONTRACT_STATIC_INVARIANT} and
508 @RefMacro{BOOST_CONTRACT_INVARIANT_VOLATILE}).
509 The curly parenthesis are mandatory (rationale: this is so the
510 syntax of this macro resembles mote the syntax of the lambda
511 functions usually used to specify preconditions, etc.).
512 Assertions within this function are usually programmed using
513 @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call
514 to this function indicates a contract assertion failure (and will
515 result in this library calling either
516 @RefFunc{boost::contract::entry_invariant_failure} or
517 @RefFunc{boost::contract::exit_invariant_failure}).
518 (This is a variadic macro parameter so it can contain commas not
519 protected by round parenthesis.)
521 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
522 Disable Contract Compilation},
523 @RefSect{tutorial.class_invariants, Class Invariants}
525 #define BOOST_CONTRACT_INVARIANT(...)
528 Program volatile class invariants that can be completely disabled at
531 @c BOOST_CONTRACT_INVARIANT_VOLATILE({ ... }) expands to code equivalent to
532 the following (note that no code is generated when
533 @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined):
536 #ifndef BOOST_CONTRACT_NO_INVARIANTS
537 void BOOST_CONTRACT_INVARIANT_FUNC() const volatile {
545 @arg <b>{ ... }</b> is the definition of the function that checks class
546 invariants for volatile public functions
547 (see @RefMacro{BOOST_CONTRACT_INVARIANT} and
548 @RefMacro{BOOST_CONTRACT_STATIC_INVARIANT}).
549 The curly parenthesis are mandatory.
550 Assertions within this function are usually programmed using
551 @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call
552 to this function indicates a contract assertion failure (and will
553 result in this library calling either
554 @RefFunc{boost::contract::entry_invariant_failure} or
555 @RefFunc{boost::contract::exit_invariant_failure}).
556 (This is a variadic macro parameter so it can contain commas not
557 protected by round parenthesis.)
559 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
560 Disable Contract Compilation},
561 @RefSect{extras.volatile_public_functions,
562 Volatile Public Functions}
564 #define BOOST_CONTRACT_INVARIANT_VOLATILE(...)
567 Program static class invariants that can be completely disabled at
570 @c BOOST_CONTRACT_STATIC_INVARIANT({ ... }) expands to code equivalent to
571 the following (note that no code is generated when
572 @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined):
575 #ifndef BOOST_CONTRACT_NO_INVARIANTS
576 static void BOOST_CONTRACT_STATIC_INVARIANT_FUNC() {
584 @arg <b>{ ... }</b> is the definition of the function that checks class
585 invariants for static public functions
586 (see @RefMacro{BOOST_CONTRACT_INVARIANT} and
587 @RefMacro{BOOST_CONTRACT_INVARIANT_VOLATILE}).
588 The curly parenthesis are mandatory.
589 Assertions within this function are usually programmed using
590 @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call
591 to this function indicates a contract assertion failure (and will
592 result in this library calling either
593 @RefFunc{boost::contract::entry_invariant_failure} or
594 @RefFunc{boost::contract::exit_invariant_failure}).
595 (This is a variadic macro parameter so it can contain commas not
596 protected by round parenthesis.)
598 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
599 Disable Contract Compilation},
600 @RefSect{tutorial.class_invariants, Class Invariants}
602 #define BOOST_CONTRACT_STATIC_INVARIANT(...)
603 #elif !defined(BOOST_CONTRACT_NO_INVARIANTS)
604 #include <boost/contract/core/config.hpp>
606 #define BOOST_CONTRACT_INVARIANT(...) \
607 void BOOST_CONTRACT_INVARIANT_FUNC() const __VA_ARGS__
609 #define BOOST_CONTRACT_INVARIANT_VOLATILE(...) \
610 void BOOST_CONTRACT_INVARIANT_FUNC() const volatile __VA_ARGS__
612 #define BOOST_CONTRACT_STATIC_INVARIANT(...) \
613 static void BOOST_CONTRACT_STATIC_INVARIANT_FUNC() __VA_ARGS__
615 #define BOOST_CONTRACT_INVARIANT(...) /* nothing */
617 #define BOOST_CONTRACT_INVARIANT_VOLATILE(...) /* nothing */
619 #define BOOST_CONTRACT_STATIC_INVARIANT(...) /* nothing */
622 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
624 Program contracts that can be completely disabled at compile-time for
627 This is used together with @RefMacro{BOOST_CONTRACT_POSTCONDITION},
628 @RefMacro{BOOST_CONTRACT_EXCEPT}, and @RefMacro{BOOST_CONTRACT_OLD} to
629 specify postconditions, exception guarantees, and old value copies at body
630 that can be completely disabled at compile-time for constructors (see
631 @RefMacro{BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION} to specify preconditions
636 friend class boost::contract::access;
638 BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
639 BOOST_CONTRACT_ASSERT(...);
645 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
646 BOOST_CONTRACT_CONSTRUCTOR(this)
647 // No `PRECONDITION` (use `CONSTRUCTOR_PRECONDITION` if needed).
648 BOOST_CONTRACT_OLD([&] { // Optional.
649 old_var = BOOST_CONTRACT_OLDOF(old_epxr);
652 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
653 BOOST_CONTRACT_ASSERT(...);
656 BOOST_CONTRACT_EXCEPT([&] { // Optional.
657 BOOST_CONTRACT_ASSERT(...);
660 ; // Trailing `;` is required.
662 ... // Constructor body.
669 For optimization, this can be omitted for constructors that do not have
670 postconditions and exception guarantees, within classes that have no
673 @c BOOST_CONTRACT_CONSTRUCTOR(obj) expands to code equivalent to the
674 following (note that no code is generated when
675 @RefMacro{BOOST_CONTRACT_NO_CONSTRUCTORS} is defined):
678 #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS
679 boost::contract::check internal_var =
680 boost::contract::constructor(obj)
686 @arg <c><b>obj</b></c> is the object @c this from the scope of the
687 enclosing constructor declaring the contract.
688 Constructors check all class invariants, including static and
689 volatile invariants (see @RefMacro{BOOST_CONTRACT_INVARIANT},
690 @RefMacro{BOOST_CONTRACT_STATIC_INVARIANT}, and
691 @RefMacro{BOOST_CONTRACT_INVARIANT_VOLATILE}).
692 (This is a variadic macro parameter so it can contain commas not
693 protected by round parenthesis.)
694 @arg <c><b>internal_var</b></c> is a variable name internally generated
695 by this library (this name is unique but only on different line
696 numbers so this macro cannot be expanded multiple times on the same
699 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
700 Disable Contract Compilation},
701 @RefSect{tutorial.constructors, Constructors}
703 #define BOOST_CONTRACT_CONSTRUCTOR(...)
704 #elif !defined(BOOST_CONTRACT_NO_CONSTRUCTORS)
705 #include <boost/contract/constructor.hpp>
706 #include <boost/contract/check.hpp>
707 #include <boost/contract/detail/name.hpp>
709 #define BOOST_CONTRACT_CONSTRUCTOR(...) \
710 boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \
711 boost::contract::constructor(__VA_ARGS__)
713 #define BOOST_CONTRACT_CONSTRUCTOR(...) /* nothing */
716 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
718 Program preconditions that can be disabled at compile-time for constructors.
720 This is used together with @RefMacro{BOOST_CONTRACT_CONSTRUCTOR} to specify
721 contracts for constructors.
722 Constructors that do not have preconditions do not use this macro.
723 When at least one of the class constructors uses this macro,
724 @RefClass{boost::contract::constructor_precondition} must be the first and
725 private base of the class declaring the constructor for which preconditions
730 #define BASES private boost::contract::constructor_precondition<u>, \
734 friend class boost::contract::access;
736 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
742 explicit u(unsigned x) :
743 BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(u)([&] {
744 BOOST_CONTRACT_ASSERT(x != 0);
755 <c>BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(class_type)(f)</c> expands
756 to code equivalent to the following (note that when
757 @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS} is defined, this macro trivially
758 expands to a default constructor call that is internally implemented to do
759 nothing so this should have minimal to no overhead):
762 // Guarded only by NO_PRECONDITIONS (and not also by NO_CONSTRUCTORS)
763 // because for constructor's preconditions (not for postconditions, etc.).
764 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
765 boost::contract::constructor_precondition<class_type>(f)
766 #else // No-op call (likely optimized away, minimal to no overhead).
767 boost::contract::constructor_precondition<class_type>()
774 @arg <c><b>class_type</b></c> is the type of the class containing the
775 constructor for which preconditions are being programmed.
776 (This is a variadic macro parameter so it can contain commas not
777 protected by round parenthesis.)
778 @arg <c><b>f</b></c> is the nullary functor called by this library to
779 check constructor preconditions @c f().
780 Assertions within this functor call are usually programmed using
781 @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call
782 to this functor indicates a contract failure (and will result in
784 @RefFunc{boost::contract::precondition_failure}).
785 This functor should capture variables by (constant) value, or better
786 by (constant) reference to avoid extra copies.
787 (This is a variadic macro parameter so it can contain commas not
788 protected by round parenthesis.)
790 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
791 Disable Contract Compilation},
792 @RefSect{tutorial.constructors, Constructors}
794 #define BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(...)
795 #elif !defined(BOOST_CONTRACT_NO_PRECONDITIONS) // Not NO_CONSTRUCTORS here.
796 // constructor_precondition.hpp already #included at top.
798 #define BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(...) \
799 boost::contract::constructor_precondition< __VA_ARGS__ >
801 #include <boost/preprocessor/tuple/eat.hpp>
802 // constructor_precondition.hpp always #included at top of this file.
804 #define BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(...) \
805 /* always use default ctor (i.e., do nothing) */ \
806 boost::contract::constructor_precondition< __VA_ARGS__ >() \
807 BOOST_PP_TUPLE_EAT(0)
810 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
812 Program contracts that can be completely disabled at compile-time for
815 This is used together with @RefMacro{BOOST_CONTRACT_POSTCONDITION},
816 @RefMacro{BOOST_CONTRACT_EXCEPT}, and @RefMacro{BOOST_CONTRACT_OLD} to
817 specify postconditions, exception guarantees, and old value copies at body
818 that can be completely disabled at compile-time for destructors (destructors
819 cannot have preconditions, see
820 @RefSect{contract_programming_overview.destructor_calls, Destructor Calls}):
824 friend class boost::contract::access;
826 BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
827 BOOST_CONTRACT_ASSERT(...);
833 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
834 BOOST_CONTRACT_DESTRUCTOR(this)
835 // No `PRECONDITION` (destructors have no preconditions).
836 BOOST_CONTRACT_OLD([&] { // Optional.
837 old_var = BOOST_CONTRACT_OLDOF(old_expr);
840 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
841 BOOST_CONTRACT_ASSERT(...);
844 BOOST_CONTRACT_EXCEPT([&] { // Optional.
845 BOOST_CONTRACT_ASSERT(...);
848 ; // Trailing `;` is required.
850 ... // Destructor body.
857 For optimization, this can be omitted for destructors that do not have
858 postconditions and exception guarantees, within classes that have no
861 @c BOOST_CONTRACT_DESTRUCTOR(obj) expands to code equivalent to the
862 following (note that no code is generated when
863 @RefMacro{BOOST_CONTRACT_NO_DESTRUCTORS} is defined):
866 #ifndef BOOST_CONTRACT_NO_DESTRUCTORS
867 boost::contract::check internal_var =
868 boost::contract::destructor(obj)
874 @arg <c><b>obj</b></c> is the object @c this from the scope of the
875 enclosing destructor declaring the contract.
876 Destructors check all class invariants, including static and
877 volatile invariants (see @RefSect{tutorial.class_invariants,
878 Class Invariants} and
879 @RefSect{extras.volatile_public_functions,
880 Volatile Public Functions}).
881 (This is a variadic macro parameter so it can contain commas not
882 protected by round parenthesis.)
883 @arg <c><b>internal_var</b></c> is a variable name internally generated
884 by this library (this name is unique but only on different line
885 numbers so this macro cannot be expanded multiple times on the same
888 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
889 Disable Contract Compilation},
890 @RefSect{tutorial.destructors, Destructors}
892 #define BOOST_CONTRACT_DESTRUCTOR(...)
893 #elif !defined(BOOST_CONTRACT_NO_DESTRUCTORS)
894 #include <boost/contract/destructor.hpp>
895 #include <boost/contract/check.hpp>
896 #include <boost/contract/detail/name.hpp>
898 #define BOOST_CONTRACT_DESTRUCTOR(...) \
899 boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \
900 boost::contract::destructor(__VA_ARGS__)
902 #define BOOST_CONTRACT_DESTRUCTOR(...) /* nothing */
905 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
907 Program contracts that can be completely disabled at compile-time for
908 (non-public) functions.
910 This is used together with @RefMacro{BOOST_CONTRACT_PRECONDITION},
911 @RefMacro{BOOST_CONTRACT_POSTCONDITION}, @RefMacro{BOOST_CONTRACT_EXCEPT},
912 and @RefMacro{BOOST_CONTRACT_OLD} to specify preconditions, postconditions,
913 exception guarantees, and old value copies at body that can be completely
914 disabled at compile-time for (non-public) functions:
918 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
919 BOOST_CONTRACT_FUNCTION()
920 BOOST_CONTRACT_PRECONDITION([&] { // Optional.
921 BOOST_CONTRACT_ASSERT(...);
924 BOOST_CONTRACT_OLD([&] { // Optional.
925 old_var = BOOST_CONTRACT_OLDOF(old_expr);
928 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
929 BOOST_CONTRACT_ASSERT(...);
932 BOOST_CONTRACT_EXCEPT([&] { // Optional.
933 BOOST_CONTRACT_ASSERT(...);
936 ; // Trailing `;` is required.
938 ... // Function body.
942 This can be used to program contracts for non-member functions but also for
943 private and protected functions, lambda functions, loops, arbitrary blocks
945 For optimization, this can be omitted for code that does not have
946 preconditions, postconditions, and exception guarantees.
948 @c BOOST_CONTRACT_FUNCTION() expands to code equivalent to the following
949 (note that no code is generated when @RefMacro{BOOST_CONTRACT_NO_FUNCTIONS}
953 #ifndef BOOST_CONTRACT_NO_FUNCTIONS
954 boost::contract::check internal_var =
955 boost::contract::function()
961 @arg <c><b>internal_var</b></c> is a variable name internally generated
962 by this library (this name is unique but only on different line
963 numbers so this macro cannot be expanded multiple times on the same
966 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
967 Disable Contract Compilation},
968 @RefSect{tutorial.non_member_functions, Non-Member Functions},
969 @RefSect{advanced.private_and_protected_functions,
970 Private and Protected Functions},
971 @RefSect{advanced.lambdas__loops__code_blocks__and__constexpr__,
972 Lambdas\, Loops\, Code Blocks}
974 #define BOOST_CONTRACT_FUNCTION()
975 #elif !defined(BOOST_CONTRACT_NO_FUNCTIONS)
976 #include <boost/contract/function.hpp>
977 #include <boost/contract/check.hpp>
978 #include <boost/contract/detail/name.hpp>
980 #define BOOST_CONTRACT_FUNCTION() \
981 boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \
982 boost::contract::function()
984 #include <boost/preprocessor/facilities/empty.hpp>
986 #define BOOST_CONTRACT_FUNCTION() /* nothing */
989 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
991 Program contracts that can be completely disabled at compile-time for static
994 This is used together with @RefMacro{BOOST_CONTRACT_PRECONDITION},
995 @RefMacro{BOOST_CONTRACT_POSTCONDITION}, @RefMacro{BOOST_CONTRACT_EXCEPT},
996 and @RefMacro{BOOST_CONTRACT_OLD} to specify preconditions, postconditions,
997 exception guarantees, and old value copies at body that can be completely
998 disabled at compile-time for static public functions:
1002 friend class boost::contract::access;
1004 BOOST_CONTRACT_STATIC_INVARIANT({ // Optional (as for non-static).
1005 BOOST_CONTRACT_ASSERT(...);
1010 static void f(...) {
1011 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
1012 BOOST_CONTRACT_PUBLIC_FUNCTION(u)
1013 BOOST_CONTRACT_PRECONDITION([&] { // Optional.
1014 BOOST_CONTRACT_ASSERT(...);
1017 BOOST_CONTRACT_OLD([&] { // Optional.
1018 old_var = BOOST_CONTRACT_OLDOF(old_expr);
1021 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
1022 BOOST_CONTRACT_ASSERT(...);
1025 BOOST_CONTRACT_EXCEPT([&] { // Optional.
1026 BOOST_CONTRACT_ASSERT(...);
1029 ; // Trailing `;` is required.
1031 ... // Function body.
1038 For optimization, this can be omitted for static public functions that do
1039 not have preconditions, postconditions and exception guarantees, within
1040 classes that have no static invariants.
1042 @c BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(class_type) expands to code
1043 equivalent to the following (note that no code is generated when
1044 @RefMacro{BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS} is defined):
1047 #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
1048 boost::contract::check internal_var =
1049 boost::contract::public_function<class_type>()
1055 @arg <c><b>class_type</b></c> is the type of the class containing the
1056 static public function declaring the contract.
1057 (This is a variadic macro parameter so it can contain commas not
1058 protected by round parenthesis.)
1059 @arg <c><b>internal_var</b></c> is a variable name internally generated
1060 by this library (this name is unique but only on different line
1061 numbers so this macro cannot be expanded multiple times on the same
1064 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
1065 Disable Contract Compilation},
1066 @RefSect{tutorial.static_public_functions, Static Public Functions}
1068 #define BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(...)
1071 Program contracts that can be completely disabled at compile-time for
1072 non-static public functions that do not override.
1074 This is used together with @RefMacro{BOOST_CONTRACT_PRECONDITION},
1075 @RefMacro{BOOST_CONTRACT_POSTCONDITION}, @RefMacro{BOOST_CONTRACT_EXCEPT},
1076 and @RefMacro{BOOST_CONTRACT_OLD} to specify preconditions, postconditions,
1077 exception guarantees, and old value copies at body that can be completely
1078 disabled at compile-time for non-static public functions (virtual or not,
1079 void or not) that do not override:
1083 friend class boost::contract::access;
1085 BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
1086 BOOST_CONTRACT_ASSERT(...);
1091 // Non-virtual (same if void).
1094 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
1095 BOOST_CONTRACT_PUBLIC_FUNCTION(this)
1096 BOOST_CONTRACT_PRECONDITION([&] { // Optional.
1097 BOOST_CONTRACT_ASSERT(...);
1100 BOOST_CONTRACT_OLD([&] { // Optional.
1101 old_var = BOOST_CONTRACT_OLDOF(old_expr);
1104 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
1105 BOOST_CONTRACT_ASSERT(...);
1108 BOOST_CONTRACT_EXCEPT([&] { // Optional.
1109 BOOST_CONTRACT_ASSERT(...);
1112 ; // Trailing `;` is required.
1114 ... // Function body (use `return result = return_expr`).
1117 // Virtual and void.
1118 virtual void g(..., boost::contract::virtual_* v = 0) {
1119 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
1120 BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
1122 BOOST_CONTRACT_OLD([&] { // Optional.
1123 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
1127 ; // Trailing `;` is required.
1129 ... // Function body.
1132 // Virtual and non-void.
1133 virtual t h(..., boost::contract::virtual_* v = 0) {
1135 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
1136 BOOST_CONTRACT_PUBLIC_FUNCTION(v, result, this)
1138 BOOST_CONTRACT_OLD([&] { // Optional.
1139 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
1142 BOOST_CONTRACT_POSTCONDITION([&] (t const& result) { // Optional
1143 BOOST_CONTRACT_ASSERT(...);
1147 ; // Trailing `;` is required.
1149 ... // Function body (use `return result = return_expr`).
1156 For optimization, this can be omitted for non-virtual public functions that
1157 do not have preconditions, postconditions and exception guarantees, within
1158 classes that have no invariants.
1159 Virtual public functions should always use
1160 @RefMacro{BOOST_CONTRACT_PUBLIC_FUNCTION} otherwise this library will not
1161 be able to correctly use them for subcontracting.
1163 This is an overloaded variadic macro and it can be used in the following
1164 different ways (note that no code is generated when
1165 @RefMacro{BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS} is defined).
1167 1\. <c>BOOST_CONTRACT_PUBLIC_FUNCTION(obj)</c> expands to code
1168 equivalent to the following (for non-virtual public functions that are
1169 not static and do not override, returning void or not):
1172 #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
1173 boost::contract::check internal_var =
1174 boost::contract::public_function(obj)
1178 2\. <c>BOOST_CONTRACT_PUBLIC_FUNCTION(v, obj)</c> expands to code
1179 equivalent to the following (for virtual public functions that do not
1180 override, returning void):
1183 #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
1184 boost::contract::check internal_var =
1185 boost::contract::public_function(v, obj)
1189 3\. <c>BOOST_CONTRACT_PUBLIC_FUNCTION(v, r, obj)</c> expands to code
1190 equivalent to the following (for virtual public functions that do not
1191 override, not returning void):
1194 #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
1195 boost::contract::check internal_var =
1196 boost::contract::public_function(v, r, obj)
1200 Where (these are all variadic macro parameters so they can contain commas
1201 not protected by round parenthesis):
1203 @arg <c><b>v</b></c> is the extra parameter of type
1204 @RefClass{boost::contract::virtual_}<c>*</c> and default value @c 0
1205 from the enclosing virtual public function declaring the contract.
1206 @arg <c><b>r</b></c> is a reference to the return value of the enclosing
1207 virtual public function declaring the contract.
1208 This is usually a local variable declared by the enclosing virtual
1209 public function just before the contract, but programmers must set
1210 it to the actual value being returned by the function at each
1211 @c return statement.
1212 @arg <c><b>obj</b></c> is the object @c this from the scope of the
1213 enclosing public function declaring the contract.
1214 This object might be mutable, @c const, @c volatile, or
1215 <c>const volatile</c> depending on the cv-qualifier of the enclosing
1216 function (volatile public functions will check volatile class
1217 invariants, see @RefSect{extras.volatile_public_functions,
1218 Volatile Public Functions}).
1219 @arg <c><b>internal_var</b></c> is a variable name internally generated
1220 by this library (this name is unique but only on different line
1221 numbers so this macro cannot be expanded multiple times on the same
1224 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
1225 Disable Contract Compilation},
1226 @RefSect{tutorial.public_functions, Public Functions},
1227 @RefSect{tutorial.virtual_public_functions,
1228 Virtual Public Functions}
1230 #define BOOST_CONTRACT_PUBLIC_FUNCTION(...)
1233 Program contracts that can be completely disabled at compile-time for
1234 public function overrides.
1236 This is used together with @RefMacro{BOOST_CONTRACT_PRECONDITION},
1237 @RefMacro{BOOST_CONTRACT_POSTCONDITION}, @RefMacro{BOOST_CONTRACT_EXCEPT},
1238 and @RefMacro{BOOST_CONTRACT_OLD} to specify preconditions, postconditions,
1239 exception guarantees, and old value copies at body that can be completely
1240 disabled at compile-time for public function overrides (virtual or not):
1244 #define BASES private boost::contract::constructor_precondition<u>, \
1248 friend class boost::contract::access;
1250 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
1253 BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
1254 BOOST_CONTRACT_ASSERT(...);
1258 BOOST_CONTRACT_OVERRIDES(f, g)
1261 // Override from `b::f`, and void.
1262 void f(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) {
1263 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
1264 BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_f)(
1265 v, &u::f, this, a_1, ..., a_n)
1266 BOOST_CONTRACT_PRECONDITION([&] { // Optional.
1267 BOOST_CONTRACT_ASSERT(...);
1270 BOOST_CONTRACT_OLD([&] { // Optional.
1271 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
1274 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
1275 BOOST_CONTRACT_ASSERT(...);
1278 BOOST_CONTRACT_EXCEPT([&] { // Optional.
1279 BOOST_CONTRACT_ASSERT(...);
1282 ; // Trailing `;` is required.
1284 ... // Function body.
1287 // Override from `b::g`, and void.
1288 t g(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) {
1290 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
1291 BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_g)(
1292 v, result, &u::g, this, a_1, ..., a_n)
1294 BOOST_CONTRACT_OLD([&] { // Optional.
1295 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
1298 BOOST_CONTRACT_POSTCONDITION([&] (t const& result) { // Optional
1299 BOOST_CONTRACT_ASSERT(...);
1303 ; // Trailing `;` is required.
1305 ... // Function body (use `return result = return_expr`).
1312 Public function overrides should always use
1313 @RefMacro{BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE} otherwise this library
1314 will not be able to correctly use it for subcontracting.
1316 This is an overloaded variadic macro and it can be used in the following
1317 different ways (note that no code is generated when
1318 @RefMacro{BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS} is defined).
1320 1\. <c>BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_type)(v, f, obj,
1321 ...)</c> expands to code equivalent to the following (for public
1322 function overrides that return void):
1325 #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
1326 boost::contract::check internal_var = boost::contract::
1327 public_function<override_type>(v, f, obj, ...)
1331 2\. <c>BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_type)(v, r, f, obj,
1332 ...)</c> expands to code equivalent to the following (for public
1333 function overrides that do not return void):
1336 #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
1337 boost::contract::check internal_var = boost::contract::
1338 public_function<override_type>(v, r, f, obj, ...)
1342 Where (these are all variadic macro parameters so they can contain commas
1343 not protected by round parenthesis):
1345 @arg <c><b>override_type</b></c> is the type
1346 <c>override_<i>function-name</i></c> declared using the
1347 @RefMacro{BOOST_CONTRACT_OVERRIDE} or related macros.
1348 @arg <c><b>v</b></c> is the extra parameter of type
1349 @RefClass{boost::contract::virtual_}<c>*</c> and default value @c 0
1350 from the enclosing virtual public function declaring the contract.
1351 @arg <c><b>r</b></c> is a reference to the return value of the enclosing
1352 virtual public function declaring the contract.
1353 This is usually a local variable declared by the enclosing virtual
1354 public function just before the contract, but programmers must set
1355 it to the actual value being returned by the function at each
1356 @c return statement.
1357 @arg <c><b>f</b></c> is a pointer to the enclosing public function
1358 override declaring the contract.
1359 @arg <c><b>obj</b></c> is the object @c this from the scope of the
1360 enclosing public function declaring the contract.
1361 This object might be mutable, @c const, @c volatile, or
1362 <c>const volatile</c> depending on the cv-qualifier of the enclosing
1363 function (volatile public functions will check volatile class
1364 invariants, see @RefSect{extras.volatile_public_functions,
1365 Volatile Public Functions}).
1366 @arg <c><b>...</b></c> is a variadic macro parameter listing all the
1367 arguments passed to the enclosing public function override declaring
1368 the contract (by reference and in the order they appear in the
1369 enclosing function declaration), but excluding the trailing
1371 @arg <c><b>internal_var</b></c> is a variable name internally generated
1372 by this library (this name is unique but only on different line
1373 numbers so this macro cannot be expanded multiple times on the same
1376 @see @RefSect{extras.disable_contract_compilation__macro_interface_,
1377 Disable Contract Compilation},
1378 @RefSect{tutorial.public_function_overrides__subcontracting_,
1379 Public Function Overrides}
1381 #define BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(...)
1382 #elif !defined(BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS)
1383 #include <boost/contract/public_function.hpp>
1384 #include <boost/contract/check.hpp>
1385 #include <boost/contract/detail/name.hpp>
1387 #define BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(...) \
1388 boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \
1389 boost::contract::public_function< __VA_ARGS__ >()
1391 #define BOOST_CONTRACT_PUBLIC_FUNCTION(...) \
1392 boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \
1393 boost::contract::public_function(__VA_ARGS__)
1395 #define BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(...) \
1396 boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \
1397 boost::contract::public_function<__VA_ARGS__>
1399 #include <boost/preprocessor/tuple/eat.hpp>
1401 #define BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(...) /* nothing */
1403 #define BOOST_CONTRACT_PUBLIC_FUNCTION(...) /* nothing */
1405 #define BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(...) BOOST_PP_TUPLE_EAT(0)
1408 #endif // #include guard