Boost logo

Boost :

Subject: Re: [boost] [contract] syntax redesign
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2011-09-02 17:45:35


> Comments are always welcome :)

Hi Lorenzo,
The number of examples is impressive. It is a pleasure to observe your
library growing at this pace. I would like to suggest two things. I could
not see from the examples, if the library is capable of supporting "function
try blocks" in constructor and destructor definitions. This is what I mean.
http://msdn.microsoft.com/en-us/library/e9etx778%28v=vs.71%29.aspx
http://www.gotw.ca/gotw/066.htm

Second, I have seen #ifndef pragmas in some of the examples, e.g., in the
body of function myadvance_dispatch you have:

    {
#ifndef CONTRACT_CONFIG_NO_LOOP_VARIANTS
        Distance n_max = n;
#endif
        CONTRACT_LOOP( while(n++) ) {
            CONTRACT_LOOP_VARIANT( const( n_max, n ) n_max - n )
            --i;
        }
    }

I am not sure if the necessity to use this conditional code would occur
often, but if so, perhaps the code would be slightly more clear if instead
the conditional code would be wrapped in an additional macro, like MFC did
with DEBUG_ONLY macro:

    {
        CONTRACT_CONFIG_LOOP_VARIANT_ONLY( Distance n_max = n );

        CONTRACT_LOOP( while(n++) ) {
            CONTRACT_LOOP_VARIANT( const( n_max, n ) n_max - n )
            --i;
        }
    }

That is, macro CONTRACT_CONFIG_LOOP_VARIANT_ONLY is defined as:

  #ifndef CONTRACT_CONFIG_NO_LOOP_VARIANTS
  #define CONTRACT_CONFIG_LOOP_VARIANT_ONLY(ARG) ARG
  #else
  #define CONTRACT_CONFIG_LOOP_VARIANT_ONLY(ARG)
  #endif

Although I am not sure if a similar trick would be possible with the
definition like:

    CONTRACT_FUNCTION(
    template( typename T )
        requires(
            Addable<T>
    #ifndef CONTRACT_CONFIG_NO_POSTCONDITIONS // Equality only for
postconditions.
            , boost::EqualityComparable<T>
    #endif
        )
    (T) (add) ( (T) x, (T) y )
        postcondition( auto result = return, result == x + y )
    ) {
        return x + y;
    }

Regards,
&rzej


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