int_div.cpp 588 B

1234567891011121314151617181920212223242526
  1. // Boost.Function library examples
  2. // Copyright Douglas Gregor 2001-2003. Use, modification and
  3. // distribution is subject to the Boost Software License, Version
  4. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // For more information, see http://www.boost.org
  7. #include <iostream>
  8. #include <boost/function.hpp>
  9. struct int_div {
  10. float operator()(int x, int y) const { return ((float)x)/y; };
  11. };
  12. int
  13. main()
  14. {
  15. boost::function<float (int, int)> f;
  16. f = int_div();
  17. std::cout << f(5, 3) << std::endl; // 1.66667
  18. return 0;
  19. }