[Boost-bugs] [Boost C++ Libraries] #10128: Use lockable_adapter with const objects or const members

Subject: [Boost-bugs] [Boost C++ Libraries] #10128: Use lockable_adapter with const objects or const members
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-06-17 11:06:02


#10128: Use lockable_adapter with const objects or const members
------------------------------+----------------------
 Reporter: anonymous | Owner: anthonyw
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: thread
  Version: Boost 1.54.0 | Severity: Problem
 Keywords: |
------------------------------+----------------------
 I would like to use lockable_adapter pattern with const objects. Usually,
 we need to access in protected mode to one const object (read some value).

 We have a compiler error when we connect unique_lock and one derived class
 from lockable_adapter and the object is const.

 int func(const Class1& obj)
 {
     boost::unique_lock<Class1> lock(obj);
     //boost::unique_lock<Class1> lock(const_cast<Class1&>(obj));
     return obj.get();
 }
  ->
 error C2664:
 'boost::unique_lock<Mutex>::unique_lock(boost::upgrade_lock<Mutex> &)' :
 no se puede convertir el parámetro 1 de 'const Class1' a
 'boost::upgrade_lock<Mutex> &'

 The solution for us is rewrite the sentence with one const_cast<Class1> ->
 boost::unique_lock<Class1> lock(const_cast<Class1&>(obj));


 We are using Visual C++ 2010

 Best regards

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10128>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC