Boost logo

Boost Users :

From: Yuri Muhitov (muhitov_at_[hidden])
Date: 2004-09-03 07:14:04


Hello All !

Please tell, can I create nullary functor returning predefined value, using
boost::function & boost::bind ?
Example uses "portable" syntax of boost::function :

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

struct InterfaceA;

InterfaceA *getInterface ();

template<typename T>
T forward ( T t )
{
  return t;
}

int main ( int, char ** )
{
  typedef boost::function0<InterfaceA *,void> functor_type;

// Value of InterfaceA * supplied by getInterface () function. Usage is
straightforward :
  functor_type f1 = boost::bind ( getInterface );

  InterfaceA *p = NULL;
// Value of InterfaceA * is known here. How to create functor, returning it
?
// functor_type f2 = boost::bind ( ??? );

  // Possible workaround. Can I do this without forward<> template function
?
  functor_type f3 = boost::bind ( &forward<InterfaceA *>, p );

  return 0;
}

Thanks!

Yuri.


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