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 <boost/core/lightweight_test.hpp> 14 #include <iostream> 15 #include <functional> 16 17 struct Y { YY18 Y(int y = 0) : y_(y) {} operator ==Y19 bool operator==(const Y& rhs) { return y_ == rhs.y_; } 20 private: 21 int y_; 22 }; 23 24 struct X { 25 int foo(int); 26 Y& foo2(Y&) const; 27 }; foo(int x)28int X::foo(int x) { return -x; } foo2(Y & x) const29Y& X::foo2(Y& x) const { return x; } 30 main()31int main() 32 { 33 boost::function2<int, X*, int> f; 34 boost::function2<Y&, X*, Y&> f2; 35 Y y1; 36 37 f = &X::foo; 38 f2 = &X::foo2; 39 40 X x; 41 BOOST_TEST(f(&x, 5) == -5); 42 BOOST_TEST(f2(&x, boost::ref(y1)) == y1); 43 44 return ::boost::report_errors(); 45 } 46