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
15
mul_ints(int x,int y)16 float mul_ints(int x, int y) { return ((float)x) * y; }
17 struct int_div {
operator ()int_div18 float operator()(int x, int y) const { return ((float)x)/y; };
19 };
20
main()21 int main()
22 {
23 boost::function<float (int x, int y)> f;
24 f = int_div();
25 std::cout << f(5, 3) << std::endl;
26 if (f)
27 std::cout << f(5, 3) << std::endl;
28 else
29 std::cout << "f has no target, so it is unsafe to call" << std::endl;
30 f = 0;
31 f = &mul_ints;
32
33 return 0;
34 }
35