1 // Function library
2 
3 // Copyright (C) 2001-2003 Douglas Gregor
4 
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 // For more information, see http://www.boost.org/
10 
11 
12 #include <boost/function.hpp>
13 #include <iostream>
14 
mul_ints(int x,int y)15 float mul_ints(int x, int y) { return ((float)x) * y; }
16 struct int_div {
operator ()int_div17   float operator()(int x, int y) const { return ((float)x)/y; };
18 };
main()19 int main()
20 {
21     boost::function2<float, int, int> f;
22     f = int_div();
23     std::cout << f(5, 3) << std::endl;
24     if (f)
25   std::cout << f(5, 3) << std::endl;
26 else
27   std::cout << "f has no target, so it is unsafe to call" << std::endl;
28     f = 0;
29     f = &mul_ints;
30 
31     return 0;
32 }
33