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

Subject: Re: [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 16:14:31


#10128: Use lockable_adapter with const objects or const members
-------------------------------+----------------------
  Reporter: anonymous | Owner: viboes
      Type: Feature Requests | Status: assigned
 Milestone: To Be Determined | Component: thread
   Version: Boost 1.54.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+----------------------
Changes (by viboes):

 * owner: anthonyw => viboes
 * status: new => assigned


Old description:

> 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

New description:

 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#comment:1>
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