
Hello, I'm new to the Boost library and quite excited to see some of the tools available to assist writing functional-style code. Recently I wanted to perform an action on every object in a container of smart pointers (boost::shared_ptr). I couldn't seem to find a concise way to do so. Here is a small example (no container involved) demonstrating the problem I'm encountering. #include <iostream> #include <string> #include <boost/shared_ptr.hpp> #include <boost/bind.hpp> using namespace std; using namespace boost; void xprint(ostream *os, shared_ptr<string> p) { *os << p.get()->c_str() << endl; } void xprint2(ostream *os, string *p) { *os << p->c_str() << endl; } int main(int ac, char *av[]) { shared_ptr<string> p(new string("Test")); bind(xprint, &cerr, _1)(p); #ifdef THIS_DOES_NOT_WORK bind(xprint2, &cerr, _1)( bind(&shared_ptr<string>::get, _1)(p) ); #else string *q = bind(&shared_ptr<string>::get, _1)(p); bind(xprint2, &cerr, _1)(q); #endif return 0; } Using GCC 3.2, I encounter a `no match for call' error in the `THIS_DOES_NOT_WORK' section of code. (Full diagnostics below.) I have tried many variations using mem_fn, apply, and by specifying the return type of the functor explicitly, but with no success. I'm afraid I don't understand the problem. I hoped someone here might be able to hit me with a clue-stick :-) Cheers, -- Jacques Vidrine . NTT/Verio SME . FreeBSD UNIX . Heimdal nectar@celabo.org . jvidrine@verio.net . nectar@freebsd.org . nectar@kth.se g++ -DTHIS_DOES_NOT_WORK -I/usr/local/include example.cc example.cc: In function `int main(int, char**)': example.cc:31: no match for call to `(boost::_bi::bind_t<void, void (*)(std::ostream*, std::string*), boost::_bi::list2<boost::_bi::value<std::ostream*>, boost::arg<1> > >) ( std::string*)' /usr/local/include/boost/bind/bind_template.hpp:19: candidates are: boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()() [with R = void, F = void (*)(std::ostream*, std::string*), L = boost::_bi::list2<boost::_bi::value<std::ostream*>, boost::arg<1> >] /usr/local/include/boost/bind/bind_template.hpp:25: boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()() const [with R = void, F = void (*)(std::ostream*, std::string*), L = boost::_bi::list2<boost::_bi::value<std::ostream*>, boost::arg<1> >] /usr/local/include/boost/bind/bind_template.hpp:31: boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&) [with A1 = std::string*, R = void, F = void (*)(std::ostream*, std::string*), L = boost::_bi::list2<boost::_bi::value<std::ostream*>, boost::arg<1> >] /usr/local/include/boost/bind/bind_template.hpp:37: boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&) const [with A1 = std::string*, R = void, F = void (*)(std::ostream*, std::string*), L = boost::_bi::list2<boost::_bi::value<std::ostream*>, boost::arg<1> >]