=Constant assertions =
I would expect that the old are always const so the following
postcondition(
auto old_even = CONTRACT_OLDOF even,
auto old_odd = CONTRACT_OLDOF odd,
// [old_]even
and [old_]odd
all const&
within
assertions.
const( even, old_even ) even == old_even + 2,
const( odd, old_odd ) odd == old_odd + 2
)
old_... are const but you need to specify them in const( ... ) so they
can be accessed by the constant-assertion boolean condition:
const( var1, var2, ... ) boolean-condition-using-var1-var2-...
Why?
Because constant-assertions are implemented using local functions
which have such a limitation. Essentially, constant-assertions are
local function's constant blocks:
http://www.boost.org/doc/libs/1_51_0/libs/local_function/doc/html/boost_localfunction/examples.html#boost_localfunction.examples.constant_blocks
I'll document this rationale.
Also clarify that reversing order of operator== arguments is a good practice but not good enough in general:
old_odd + 2 == odd
Sure. In general assertions might call f(old_odd, odd) where f's
arguments are non-const references but for easy checks like == the
above is a good practice as usual (e.g., that's how I usually write
if-conditions).