Boost logo

Boost :

Subject: Re: [boost] [contract] diff n1962
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-04-30 13:53:29


On Thu, Apr 15, 2010 at 7:02 PM, Alexander Nasonov <alnsn_at_[hidden]> wrote:
> vicente.botet wrote:
>> VBE> Boost.ScopeExit showed a technique that can be used to
>> emulate local functions. Alexander proposed long time ago to provide
>> it independently from ScopeExit but to my knowledge this has not
>> been done.
>
> Sorry for the late reply, I'm not following every boost thread, I got
> this message via google alerts.

No problem: There is no rush and thanks a lot for your reply.

> Yes, this has not been done. Local function can borrow argument
> binding syntax from ScopeExit but there are other things I need to think
> of. For instance, in
>
> int BOOST_LOCAL_FUNCTION(f,
>    (BOOST_LOCAL_FUNCTION_BIND( (a)(&b) ), int c)) {
>    // ...
> } BOOST_LOCAL_FUNCTION_END
>
> syntax, is there any way to shorten BOOST_LOCAL_FUNCTION_BIND to "bind"?

For using this in Boost.Contract I see the following issues:
1) The CONTRACT_BLOCK_INVARIANT() macro will have to take as
parameters also `a`, `&b`, `int`, `c`, etc. This is as complex as
requesting the user to program a separate (private) member const
function with these const parameters and then call that function to
check the block invariant condition in a constant-correct context:

   struct x {
       void f(int a) {
           int b = a;
           // CONTRACT_BLOCK_INVARIANT(a == b); // Don't use this
because it is not const-correct.
           CONTRACT_BLOCK_INVARIANT(equal(a, b)); // Const-correct.
           ...
       }
    private:
        bool equal(const int& a, cont int& b) const { return a == b; }
// Const-correct for a, b, and object this.
   };

2) How do I make the object (this) available within the local
function? I could pass it as a 'self' parameter but then the assertion
code will have to say, for example, `self.size()` instead of just
`size()` and that is less readable...

> The syntax doesn't have to be exactly as above. If someone could
> take a lead on this it would be great. I don't have time for this,
> I'm afraid.

I will experiment with this a bit more. If I can use
BOOST_LOCAL_FUNCTION_... for CONTRACT_BLOCK_INVARIANT() (resolving
issues 1) and 2) above) then I am happy to take the lead in separating
this functionality from Boost.ScopeExit as part of Boost.Contract
development.

-- 
Lorenzo

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