Re: [Boost-bugs] [Boost C++ Libraries] #9058: with_lock_guard function

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #9058: with_lock_guard function
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-09-01 10:56:44

#9058: with_lock_guard function
  Reporter: ruslan_baratov@… | Owner: viboes
      Type: Feature Requests | Status: assigned
 Milestone: To Be Determined | Component: thread
   Version: Boost 1.54.0 | Severity: Problem
Resolution: | Keywords:

Comment (by ruslan_baratov@…):

 Updated version on github:

 For function without c++11 variadic templates, Func parameter is now

 template <class Lockable, class Func, class Arg>
 typename boost::result_of<Func(Arg)>::type with_lock_guard(
     Lockable& m,
     BOOST_FWD_REF(Func) func,
     BOOST_FWD_REF(Arg) arg
 ) {
   boost::lock_guard<Lockable> lock(m);
   return func(

 overloaded version for function pointers:

 template <class Lockable, class Func, class Arg1, class Arg2>
 typename boost::result_of<
     typename boost::add_pointer<Func>::type(Arg1, Arg2)
>::type with_lock_guard(
     Lockable& m,
     Func* func,
     BOOST_FWD_REF(Arg1) arg1,
     BOOST_FWD_REF(Arg2) arg2
 ) {

   boost::lock_guard<Lockable> lock(m);
   return func(

 In this version boost::bind which call non-const class method still not
 working (for variadic template
 version is OK). It's because BOOST_FWD_REF(Func) = const Func&. I can't
 figure out how to do
 a workaround in not ugly way. I can make version with copy-by-value for
 types with T::result_type defined if this is appropriate.

 If used with lambda, BOOST_RESULT_OF_USE_DECLTYPE may need to be defined,
 see this bug:

 I've added test:

 Replying to [comment:10 viboes]:
> The C++11 definition must be protected also with no rvalue references
 and no decltype.
 I've add BOOST_NO_CXX11_DECLTYPE check; do
 BOOST_NO_CXX11_RVALUE_REFERENCES check really needed? I thought it
 automatically checked in BOOST_FWD_REF (?)

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

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