Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2004-07-16 22:42:58


Christopher Currie wrote:

>
> As a compromise, we could create lock_transfer<> objects that wouldn't
> lock a mutex, but would allow initialization syntax in places where the
> language makes it difficult (this is just a quick sketch, there may be
> errors):
>

<code snipped>

This won't work. Try to compile this with Comeau online:

   struct lock_transfer {};

   struct scoped_lock
   {
       scoped_lock( lock_transfer ) {}
   private:
       scoped_lock( scoped_lock const & );
       scoped_lock & operator =( scoped_lock const & );
   };

   int main()
   {
       scoped_lock l = lock_transfer();
       return 0;
   }

You'll get:

   "ComeauTest.c", line 13: error: "scoped_lock::scoped_lock(const
   scoped_lock &)",
           required for copy that was eliminated, is inaccessible
           scoped_lock l = lock_transfer();
                       ^

Non-copyable types can't be initialized this way. The code I posted
earlier worked around this problem by enabling just enough move
semantics to allow a lock to be returned from a function, but nothing
else. The lock is still non-copyable.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

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