Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::bind used with boost shared_ptr
From: Kevin Ludwig (kevin.ludwig_at_[hidden])
Date: 2009-03-04 15:12:34


Hi,

This is with RHEL, gcc version 3.4.6. I *think* the boost version is 1.32.0.

-bash-3.00$ gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk
--host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)
-bash-3.00$

The complete mini program I use is:
[code]
#include <map>

#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>

class A {
  public:
  void reset() {}
};

typedef boost::shared_ptr<A> ptr_type;

typedef std::map<int,ptr_type> map_type;

map_type m;

int main()
{
    m[1] = ptr_type(new A());
    m[2] = ptr_type(new A());

    for_each (m.begin(), m.end(),
        boost::bind(&A::reset,
        boost::bind(&map_type::value_type::second, _1)));

    return 0;
}

[/code]

The following is the compiler error received:

[output]
-bash-3.00$ g++ -o tc tc.cpp
/usr/include/boost/bind.hpp: In member function `void
boost::_bi::list1<A1>::operator()(boost::_bi::type<void>, F&, A&, int) [with
F = boost::_mfi::mf0<void, A>, A = boost::_bi::list1<std::pair<const int,
ptr_type>&>, A1 = boost::_bi::bind_t<ptr_type, boost::_mfi::dm<ptr_type,
std::pair<const int, ptr_type> >, boost::_bi::list1<boost::arg<1> > >]':
/usr/include/boost/bind/bind_template.hpp:32: instantiated from `typename
boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F,
L>::operator()(A1&) [with A1 = std::pair<const int, ptr_type>, R = void, F =
boost::_mfi::mf0<void, A>, L =
boost::_bi::list1<boost::_bi::bind_t<ptr_type, boost::_mfi::dm<ptr_type,
std::pair<const int, ptr_type> >, boost::_bi::list1<boost::arg<1> > > >]'
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:158:
instantiated from `_Function std::for_each(_InputIterator, _InputIterator,
_Function) [with _InputIterator = std::_Rb_tree_iterator<std::pair<const
int, ptr_type> >, _Function = boost::_bi::bind_t<void,
boost::_mfi::mf0<void, A>, boost::_bi::list1<boost::_bi::bind_t<ptr_type,
boost::_mfi::dm<ptr_type, std::pair<const int, ptr_type> >,
boost::_bi::list1<boost::arg<1> > > > >]'
tc.cpp:24: instantiated from here
/usr/include/boost/bind.hpp:228: error: no match for call to
`(boost::_mfi::mf0<void, A>) (ptr_type)'
/usr/include/boost/bind/mem_fn_template.hpp:44: note: candidates are: R
boost::_mfi::mf0<R, T>::operator()(T*) const [with R = void, T = A]
/usr/include/boost/bind/mem_fn_template.hpp:49: note: R
boost::_mfi::mf0<R, T>::operator()(U&) const [with U = ptr_type, R = void, T
= A]
/usr/include/boost/bind/mem_fn_template.hpp:54: note: R
boost::_mfi::mf0<R, T>::operator()(T&) const [with R = void, T = A]
-bash-3.00$
[/output]

Anyway, since it works on VC7.1 I imagine that it was fixed in some later
version of the library.

Thanks,
--Kevin

On Wed, Mar 4, 2009 at 11:49 AM, Peter Dimov <pdimov_at_[hidden]> wrote:

> Kevin Ludwig:
>
>> Hi,
>>
>> I've recently been making more use of boost::bind, and I coded the
>> following, which I thought would work:
>>
>> class A {
>> public:
>> void reset () {}
>> };
>> typedef std::map<int, boost::shared_ptr<A> > map_type;
>> map_type m;
>> std::for_each (m.begin(), m.end(),
>> boost::bind(&A::reset,
>> boost::bind(&map_type::value_type::second, _1)));
>>
>> but fails to compile.
>>
>
> This compiles for me with MSVC 7.1. What compiler and Boost version do you
> use? What errors do you get?
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Kevin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net