diff --git a/include/boost/lambda/detail/function_adaptors.hpp b/include/boost/lambda/detail/function_adaptors.hpp index 58c6b50..35db8b4 100644 --- a/include/boost/lambda/detail/function_adaptors.hpp +++ b/include/boost/lambda/detail/function_adaptors.hpp @@ -16,6 +16,9 @@ #include "boost/tuple/tuple.hpp" #include "boost/type_traits/same_traits.hpp" #include "boost/type_traits/remove_reference.hpp" +#include "boost/type_traits/remove_cv.hpp" +#include "boost/type_traits/add_const.hpp" +#include "boost/type_traits/add_volatile.hpp" #include "boost/utility/result_of.hpp" namespace boost { @@ -237,22 +240,26 @@ struct function_adaptor { // the data member is accessed is const, and finally adding a reference template class sig { typedef typename boost::tuples::element<1, Args>::type argument_type; + typedef typename boost::remove_reference< + argument_type + >::type unref_type; - typedef typename detail::IF::value, + typedef typename detail::IF::value, typename boost::add_const::type, T >::RET properly_consted_return_type; - typedef typename detail::IF< - boost::is_volatile::value, + typedef typename detail::IF::value, typename boost::add_volatile::type, properly_consted_return_type >::RET properly_cvd_return_type; public: - typedef typename - boost::add_reference::type type; + typedef typename detail::IF::value, + typename boost::add_reference::type, + typename boost::remove_cv::type + >::RET type; }; template diff --git a/test/bind_tests_simple.cpp b/test/bind_tests_simple.cpp index d9a05fa..1e63d69 100644 --- a/test/bind_tests_simple.cpp +++ b/test/bind_tests_simple.cpp @@ -80,6 +80,23 @@ void test_member_functions() // bind(&A::add, a, _1); } +struct B { + B(int n) : i(n) {}; + int i; +}; + +void test_data_members() +{ + using boost::ref; + B b(10); + BOOST_CHECK(bind(&B::i, ref(b))() == 10); + BOOST_CHECK(bind(&B::i, b)() == 10); + BOOST_CHECK(bind(&B::i, _1)(b) == 10); + BOOST_CHECK(bind(&B::i, _1)(B(11)) == 11); + bind(&B::i, ref(b))() = 1; + BOOST_CHECK(b.i == 1); +} + int test_main(int, char *[]) { int i = 1; int j = 2; int k = 3;