Boost logo

Boost :

From: Dirk Gerrits (dirkg_at_[hidden])
Date: 2002-05-23 05:35:59


----- Original Message -----
From: "Yitzhak Sapir" <yitzhaks_at_[hidden]>

> boost::ref is a class generator that creates a reference wrapper.
> operator() is not defined for the wrapper.

Suppose you have an object r of a type generated by boost::ref for an
object of type T. (That's boost::reference_wrapper<T> right?)
Now let's say we have this line of code:
r();
boost::reference_wrapper<T> has no operator() but it does have an
implict conversion to T&. If that type T does have an operator() taking
no arguments, wouldn't the above code be perfectly legal?

I have tried the following on my compiler and it worked perfectly:

#include <boost/function.hpp>
#include <boost/ref.hpp>

void func(boost::function0<void> f) { f(); }

struct functor
{
  void operator()() {std::cout << "It works!" << std::endl; }
};

int main()
{
  functor f;
  func(f);
  func(boost::ref(f));
}

Output:
It works!
It works!

If this doesn't work for you, then is my logic (and my compiler) flawed?

Dirk Gerrits


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