2003-02-14 18:05:26 +00:00
|
|
|
// Function library
|
|
|
|
|
|
|
|
// Copyright (C) 2001-2003 Douglas Gregor
|
|
|
|
|
2003-10-01 04:10:37 +00:00
|
|
|
// Use, modification and distribution is subject to the Boost Software
|
|
|
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
2003-02-14 18:05:26 +00:00
|
|
|
|
|
|
|
// For more information, see http://www.boost.org/
|
2002-12-28 03:44:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <boost/function.hpp>
|
2011-03-21 21:32:38 +00:00
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
2002-12-28 03:44:00 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
struct X {
|
|
|
|
int foo(int);
|
2011-03-21 21:32:38 +00:00
|
|
|
std::ostream& foo2(std::ostream&) const;
|
2002-12-28 03:44:00 +00:00
|
|
|
};
|
2003-01-19 14:44:34 +00:00
|
|
|
int X::foo(int x) { return -x; }
|
2011-03-21 21:32:38 +00:00
|
|
|
std::ostream& X::foo2(std::ostream& x) const { return x; }
|
2003-01-19 14:44:34 +00:00
|
|
|
|
2002-12-28 03:44:00 +00:00
|
|
|
int main()
|
|
|
|
{
|
2003-02-14 18:05:26 +00:00
|
|
|
boost::function<int (X*, int)> f;
|
2011-03-21 21:32:38 +00:00
|
|
|
boost::function<std::ostream& (X*, std::ostream&)> f2;
|
2002-12-28 03:44:00 +00:00
|
|
|
|
2011-03-21 21:32:38 +00:00
|
|
|
f = &X::foo;
|
|
|
|
f2 = &X::foo2;
|
2002-12-28 03:44:00 +00:00
|
|
|
|
2011-03-21 21:32:38 +00:00
|
|
|
X x;
|
|
|
|
BOOST_TEST(f(&x, 5) == -5);
|
|
|
|
BOOST_TEST(f2(&x, boost::ref(std::cout)) == std::cout);
|
|
|
|
|
|
|
|
return ::boost::report_errors();
|
2002-12-28 03:44:00 +00:00
|
|
|
}
|