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:
{{{
github.com/ruslo/thread/commit/ea30f0dc6b1fe7951d1d0dff88fd03e946429669
}}}
For function without c++11 variadic templates, Func parameter is now
movable:
{{{
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(
boost::forward<Arg>(arg)
);
}
}}}
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_STATIC_ASSERT(boost::is_function<Func>::value);
boost::lock_guard<Lockable> lock(m);
return func(
boost::forward<Arg1>(arg1),
boost::forward<Arg2>(arg2)
);
}
}}}
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: https://svn.boost.org/trac/boost/ticket/7311
I've added test:
{{{
test_with_lock_guard_bind.cpp
test_with_lock_guard_lambda.cpp
test_with_lock_guard_move.cpp
test_with_lock_guard_simple.cpp
}}}
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: <https://svn.boost.org/trac/boost/ticket/9058#comment:11> 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:14 UTC