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
17struct Y {
18 Y(int y = 0) : y_(y) {}
19 bool operator==(const Y& rhs) const { return y_ == rhs.y_; }
20private:
21 int y_;
22 };
23
24struct X {
25 int foo(int);
26 Y& foo2(Y&) const;
27};
28int X::foo(int x) { return -x; }
29Y& X::foo2(Y& x) const { return x; }
30
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

source code of boost/libs/function/test/mem_fun_portable.cpp