|
Boost : |
Subject: Re: [boost] [contract] syntax redesign
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2011-09-27 11:43:18
lcaminiti wrote:
>
> After a long time of inactivity for Boost.Contract, I am considering
> how to re-design its macro syntax to make it simpler.
>
Hello all,
Playing with pp a bit more I realized this alternative syntax is also
possible:
CONTRACT_CLASS( // option A
template( typename T )
class (vector)
) {
CONTRACT_CLASS_INVARIANT(
assert(empty() == (size() == 0)) // no trailing `,` or `;` etc
assert(size() <= capacity)
)
public:
CONTRACT_FUNCTION_TPL(
public void (push_back) ( (const T&) value )
precondition(
assert(size() < max_size())
)
postcondition(
var(auto old_size = CONTRACT_OLDOF size())
var(auto old_capacity = CONTRACT_OLDOF capacity())
assert(back() == val) requires(boost::has_equal_to<T>::value)
assert(size() == old_size + 1)
assert(capacity() >= old_capacity)
const_assert(x, y, x == y)
static_assert(sizeof(T) >= sizeof(int), "large enough")
)
) ;
};
While currently I am implementing:
CONTRACT_CLASS( // option B
template( typename T )
class (vector)
) {
CONTRACT_CLASS_INVARIANT(
empty() == (size() == 0),
size() <= capacity
)
public:
CONTRACT_FUNCTION_TPL(
public void (push_back) ( (const T&) value )
precondition(
size() < max_size()
)
postcondition(
auto old_size = CONTRACT_OLDOF size(),
auto old_capacity = CONTRACT_OLDOF capacity(),
back() == val, requires boost::has_equal_to<T>::value,
size() == old_size + 1,
capacity() >= old_capacity,
const( x, y ) x == y,
static_assert(sizeof(T) >= sizeof(int), "large enough")
)
) ;
};
I think option B (current) is still better than option A because A requires
(1) more parenthesis and (2) the extra assertion word spelled out all the
times but A doesn't require the trailing `,` which is a plus.
Do you have a strong opinion about which one is better between A and B? I'd
say B is better but I'm quite biased at this point ;)
Thanks a lot.
--Lorenzo
-- View this message in context: http://boost.2283326.n4.nabble.com/contract-syntax-redesign-tp3563993p3847911.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk