|
Boost Users : |
Subject: [Boost-users] Nesting bind with shared_ptr<T>::operator* and ref
From: Chris Stankevitz (chrisstankevitz_at_[hidden])
Date: 2013-06-03 16:15:45
Hello,
Can you please help me uncomment out the last "bind" of the program
pasted below? The problem is that it will require some kind of
mechanism to dereference the shared_ptr.
Thank you,
Chris
===
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
using namespace boost;
struct C : noncopyable { C() {} void f() {} };
shared_ptr<C> GetC(int) { return make_shared<C>(); }
int main()
{
function<void(C&)> x = bind(&C::f, _1);
function<void(shared_ptr<C>)> y = bind(&C::f, _1);
// Call x after first computing 42, GetC, and shared_ptr::operator*
x(*GetC(42));
// Same as above, but with bind and ref
bind(x, ref(*GetC(42)))();
// Similar to above, but delay calling 42, GetC, shared_ptr::operator*,
// and ref until later. Also use y (takes a shared_ptr) vs x (that takes
// a reference)
bind(y, bind(GetC, _1))(42);
// Same as above, but use x vs y
// todo: add call to operator*
// todo: add call to ref
//
// bind(x, bind(GetC, _1))(42);
return 0;
}
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