[contract] static if instead of assertion requirements

Hello all, I was reading the proposal to add "static if" to C++1x and I will use such a syntax for assertion requirements: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3329.pdf Current syntax for assertion requirements: postcondition( back() == value, requires boost::has_equal<T>::value ) Will be replaced with static if: postcondition( static if(boost::has_equal<T>::value) ( back() == value ) // optional else ( ... ) ) If there were interested, I could even provide a separate BOOST_STATIC_IF(const_condition, then_code, else_code)... however, such a macro could only be used at namespace and class scope, not a function scope :( --Lorenzo

On 10/02/2012 11:32 PM, Lorenzo Caminiti wrote:
Hello all,
I was reading the proposal to add "static if" to C++1x and I will use such a syntax for assertion requirements: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3329.pdf
Current syntax for assertion requirements:
postcondition( back() == value, requires boost::has_equal<T>::value )
Will be replaced with static if:
postcondition( static if(boost::has_equal<T>::value) ( back() == value ) // optional else ( ... ) )
If there were interested, I could even provide a separate BOOST_STATIC_IF(const_condition, then_code, else_code)... however, such a macro could only be used at namespace and class scope, not a function scope :(
Huh? How does that work? The only way to implement static if that I know of only works at function scope.

On Tue, Oct 2, 2012 at 9:10 PM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
On 10/02/2012 11:32 PM, Lorenzo Caminiti wrote:
Hello all,
I was reading the proposal to add "static if" to C++1x and I will use such a syntax for assertion requirements: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3329.pdf
Current syntax for assertion requirements:
postcondition( back() == value, requires boost::has_equal<T>::value )
Will be replaced with static if:
postcondition( static if(boost::has_equal<T>::value) ( back() == value ) // optional else ( ... ) )
If there were interested, I could even provide a separate BOOST_STATIC_IF(const_condition, then_code, else_code)... however, such a macro could only be used at namespace and class scope, not a function scope :(
Huh? How does that work?
The only way to implement static if that I know of only works at function scope.
Yeah, can't do BOOST_STATIC_IF... sorry, I spoke to soon... (I can still do static if in pre/post/inv because that's for expressions within Boost.Contract syntax and extra function templates are declared to wrap the expression but disabled if the static if condition is false. That works same as Boost.Contract current assertion requirements only using the "static if(const_bool) ( ... ) [else (...)]" syntax instead of "bool, requires const_bool".) --Lorenzo
participants (2)
-
Lorenzo Caminiti
-
Mathias Gaunard