|
Boost : |
Subject: Re: [boost] [contract] Macro syntax?
From: Alan Manuel Gloria (almkglor_at_[hidden])
Date: 2010-03-21 18:48:30
On Sat, Mar 20, 2010 at 6:54 AM, Lorenzo Caminiti <lorcaminiti_at_[hidden]> wrote:
> OPTION 1: The function declaration is programmed using the usual C++
> syntax just before the CONTRACT_FUNCTION() macro.
>
> template<typename T>
> class myvector {
>
> CONTRACT_INVARIANT( ({
> ...
> }) )
>
> public:
> void push_back(const T& element) // Usual C++ push_back() declaration.
> CONTRACT_FUNCTION( (class) (copyable)(myvector)
> (public) (void) (push_back)( (const T&)(element) )
> (precondition)({
> ...
> })
> (postcondition)({
> ...
> })
> (body)({
> ...
> }) )
>
> ...
> };
>
> OPTION 2: The CONTRACT_FUNCTION() macro automatically programs also
> the function declaration.
>
> template<typename T>
> class myvector {
>
> CONTRACT_INVARIANT( ({
> ...
> }) )
>
> public:
> // No usual C++ push_back() declaration here.
> CONTRACT_FUNCTION( (class) (copyable)(myvector)
> (public) (void) (push_back)( (const T&)(element) )
> (precondition)({
> ...
> })
> (postcondition)({
> ...
> })
> (body)({
> ...
> }) )
>
> ...
> };
The OPTION 1 example looks nicer, simply because there's a separate,
"classic" C++ declaration before that weird CONTRACT_FUNCTION macro.
Someone completely ignorant of Boost.Contract might not want to take
the trouble of learning everything, and the (void) (push_back)((const
T&) (element) )declaration in OPTION 2 might be skipped because it's
right after all those (class)(copyable) etc. etc. because it looks too
similar to them (and someone scanning and skipping over
CONTRACT_FUNCTION might skip over them).
Sincerely,
AmkG
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk