Boost logo

Boost :

Subject: [boost] [contract] Macro syntax?
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-03-20 10:54:39


Hello all,

I would like you to vote between one of the two options below. Which
option do you prefer?

(-) OPTION 1 requires programmers to repeat the function signature
tokens twice -- in the function declaration and in the
CONTRACT_FUNCTION() macro.
(+) However, OPTION 1 seems to make the code more readable -- users
not familiar with Boost.Contract can "skip" the tokens in the
CONTRACT_FUNCTION() signature-sequence and just read the usual C++
function declaration.

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)({
            ...
        }) )

        ...
    };

Thank you.
Lorenzo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk