
Hi Lorenzo, If I understand your question and Boost.Contract design correctly, it looks like the former approach is more flexible in cases where I do _not_ want to use a meta-function to describe a constraint: postcondition( auto result = return, some_cond1(result), requires x / 2 == 0, some_cond2(result), requires noexcept(x), some_cond3(result), requires sizeof(x) > 2, ) Although I am not sure if such constraints would be useful in real life. Regards, &rzej. 2012/4/24 lcaminiti <lorcaminiti@gmail.com>
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
Thanks. --Lorenzo
-- View this message in context: http://boost.2283326.n4.nabble.com/boost-contract-assertion-requirements-as-... Sent from the Boost - Dev mailing list archive at Nabble.com.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost