mirror of
https://github.com/boostorg/function.git
synced 2025-07-30 04:47:14 +02:00
@ -10,22 +10,28 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
struct X {
|
struct X {
|
||||||
int foo(int);
|
int foo(int);
|
||||||
|
std::ostream& foo2(std::ostream&) const;
|
||||||
};
|
};
|
||||||
int X::foo(int x) { return -x; }
|
int X::foo(int x) { return -x; }
|
||||||
|
std::ostream& X::foo2(std::ostream& x) const { return x; }
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
boost::function<int (X*, int)> f;
|
boost::function<int (X*, int)> f;
|
||||||
|
boost::function<std::ostream& (X*, std::ostream&)> f2;
|
||||||
|
|
||||||
f = &X::foo;
|
f = &X::foo;
|
||||||
|
f2 = &X::foo2;
|
||||||
X x;
|
|
||||||
f(&x, 5);
|
|
||||||
|
|
||||||
return 0;
|
X x;
|
||||||
|
BOOST_TEST(f(&x, 5) == -5);
|
||||||
|
BOOST_TEST(f2(&x, boost::ref(std::cout)) == std::cout);
|
||||||
|
|
||||||
|
return ::boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@ -10,22 +10,28 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
struct X {
|
struct X {
|
||||||
int foo(int);
|
int foo(int);
|
||||||
|
std::ostream& foo2(std::ostream&) const;
|
||||||
};
|
};
|
||||||
int X::foo(int x) { return -x; }
|
int X::foo(int x) { return -x; }
|
||||||
|
std::ostream& X::foo2(std::ostream& x) const { return x; }
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
boost::function2<int, X*, int> f;
|
boost::function2<int, X*, int> f;
|
||||||
|
boost::function2<std::ostream&, X*, std::ostream&> f2;
|
||||||
|
|
||||||
f = &X::foo;
|
f = &X::foo;
|
||||||
|
f2 = &X::foo2;
|
||||||
X x;
|
|
||||||
f(&x, 5);
|
|
||||||
|
|
||||||
return 0;
|
X x;
|
||||||
|
BOOST_TEST(f(&x, 5) == -5);
|
||||||
|
BOOST_TEST(f2(&x, boost::ref(std::cout)) == std::cout);
|
||||||
|
|
||||||
|
return ::boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user