1.template<typename Functor> Functor* target(); template<typename Functor> const Functor* target() const;
about: if this stores a target of type functor, returns the address of the target otherwise returns the null pointer
2.template<typename Functor> bool contains(const Functor& f) const;
about :it returns true if this-> target<Functor>() is non null
Program:
#include <boost/function.hpp>// the main header file
using namespace std;
struct example
{
int demo(std::ostream &os,int a,int b)
{
os << "LCM of "<<a<<"and"<<b<<":"<<boost::math::lcm(a,b);//math function for finding lcm
return 0;
}
};
int main()
{
boost::function<int(example*, std::ostream&, int,int)> f = &example::demo;
// above is the boost::function target access template
example w;
if (f.empty()) /* this is function which used to check whether
the function is empty or it has any value*/
cout << "f has no target, so it is unsafe to call" <<endl;
else
f(&w, std::ref(std::cout) , 10,20);
}output:
lcm of 10and20:20
Comments