bind1st.cpp 658 B

1234567891011121314151617181920212223242526272829303132
  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. #include <functional>
  10. struct X {
  11. X(int val) : value(val) {}
  12. int foo(int x) { return x * value; }
  13. int value;
  14. };
  15. int
  16. main()
  17. {
  18. boost::function<int (int)> f;
  19. X x(7);
  20. f = std::bind1st(std::mem_fun(&X::foo), &x);
  21. std::cout << f(5) << std::endl; // Call x.foo(5)
  22. return 0;
  23. }