Boost logo

Boost :

From: Michael Goldshteyn (mgoldshteyn_at_[hidden])
Date: 2008-07-14 17:27:04


Sorry, post got garbled, here it is again:

#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <string>

// Define a simple class for our example class Crayon {
public:
  explicit Crayon(const std::string &color=std::string()):m_color(color) {}
  const std::string &GetColor() const {return m_color;}

private:
  std::string m_color;
};

int main(int argc, char *argv[])
{
  using namespace std;
  using namespace boost;

  Crayon cr("blue");
  boost::reference_wrapper<const Crayon> crefCr(cr);

  // This compiles
  std::string color(boost::bind(&Crayon::GetColor,_1)(cr));

  // This also compiles, using an explicit get on crefCr
  std::string
colorFromConstRef(boost::bind(&Crayon::GetColor,boost::bind(&boost::referenc
e_wrapper<const Crayon>::get,_1))(crefCr));
 
  // This doesn't compile, however, even though the reference_wrapper class
template has
  // an overloaded operator T& () const function

  std::string colorFromConstRef2(boost::bind(&Crayon::GetColor,_1)(crefCr));
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk