Boost logo

Boost :

Subject: Re: [boost] [contract] assertion requirements as meta-functions or not?
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2012-04-24 13:40:15


Vicente Botet wrote
>
> Le 24/04/12 14:31, lcaminiti a écrit :
>> Hello all,
>>
>> Boost.Contract allows to specify "assertion requirements":
>>
>> /assertion-condition/, requires /assertion-requirement/
>>
>> If the requirement is not met then the assertion condition is neither
>> compiled nor checked at run-time.
>>
>> Question: Shall the assertion-requirement be a nullary boolean
>> meta-function
>> or just a static boolean value?
>>
>> For example:
>>
>> CONTRACT_FUNCTION(
>> template( typename T ) requires( boost::LessThanComparable<T> )
>> (T const&) (min) ( (T const&) x, (T const&) y )
>> postcondition(
>> auto result = return,
>> x< y ? result == x : result == y,
>> requires boost::has_equal_to<T>::value // static
>> boolean
>> )
>> ) {
>> return x< y ? x : y; // OK: T is less than comparable `<`.
>> }
>>
>> For now, the assertion requirement is a static boolean value so it can be
>> more easily manipulated (using !,&&, ||, etc instead of mpl::not,
>> mpl::and,
>> mpl::or, etc). However, is there any strong reason for marking the
>> assertion
>> requirement a nullary boolean meta-function instead like the following
>> code?
>>
>> x< y ? result == x : result == y,
>> requires boost::has_equal_to<T> // meta-function
>>
> Hi,
>
> I don't know if following the the _c suffix rule in Boost could help.
>
> x< y ? result == x : result == y,
> requires boost::has_equal_to<T> // meta-function
>
> and
>
> x< y ? result == x : result == y,
> requires*_c* boost::has_equal_to<T>::value // value
>

Yes, that is possible and a reasonable suggestion but I fear it will be
confusing for the user. There are already a lot of syntactic elements users
need to familiarize themselves in using Boost.Contract so I'd rather pick
one syntax (meta-function or not) and offer just that. Users can make
meta-functions from static values and vice versa if they need to.

Thanks.
--Lorenzo

--
View this message in context: http://boost.2283326.n4.nabble.com/boost-contract-assertion-requirements-as-meta-functions-or-not-tp4583283p4584308.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