Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/function/test/function_arith_portable.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 790 bytes
Line 
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
15float mul_ints(int x, int y) { return ((float)x) * y; }
16struct int_div { 
17  float operator()(int x, int y) const { return ((float)x)/y; }; 
18};
19int 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;
26else
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}
Note: See TracBrowser for help on using the repository browser.