diff --git a/test/function_arith_cxx98.cpp b/test/function_arith_cxx98.cpp new file mode 100644 index 0000000..59fc701 --- /dev/null +++ b/test/function_arith_cxx98.cpp @@ -0,0 +1,38 @@ + + +#include +#include + + + + float mul_ints(int x, int y) { return ((float)x) * y; } + +int main() +{ + +boost::function f; + + +struct int_div { + float operator()(int x, int y) const { return ((float)x)/y; }; +}; + +f = int_div(); + + +std::cout << f(5, 3) >> std::endl; + + +if (f) + std::cout << f(5, 3) << std::endl; +else + std::cout << "f has no target, so it is unsafe to call" << std::endl; + + +f = 0; + + + f = &mul_ints; + + } + \ No newline at end of file diff --git a/test/function_arith_portable.cpp b/test/function_arith_portable.cpp new file mode 100644 index 0000000..e007a32 --- /dev/null +++ b/test/function_arith_portable.cpp @@ -0,0 +1,37 @@ + + +#include +#include + + + float mul_ints(int x, int y) { return ((float)x) * y; } + +int main() +{ + +boost::function2 f; + + +struct int_div { + float operator()(int x, int y) const { return ((float)x)/y; }; +}; + +f = int_div(); + + +std::cout << f(5, 3) >> std::endl; + + +if (f) + std::cout << f(5, 3) << std::endl; +else + std::cout << "f has no target, so it is unsafe to call" << std::endl; + + +f = 0; + + + f = &mul_ints; + +} + \ No newline at end of file diff --git a/test/function_ref_cxx98.cpp b/test/function_ref_cxx98.cpp new file mode 100644 index 0000000..a9b07b4 --- /dev/null +++ b/test/function_ref_cxx98.cpp @@ -0,0 +1,19 @@ + + +#include +#include + + +struct stateful_type { int operator(int) const { return 0; } }; + +int main() +{ + + stateful_type a_function_object; + boost::function f; + f = boost::ref(a_function_object); + + boost::function f2(f); + +} + \ No newline at end of file diff --git a/test/function_ref_portable.cpp b/test/function_ref_portable.cpp new file mode 100644 index 0000000..2fe925d --- /dev/null +++ b/test/function_ref_portable.cpp @@ -0,0 +1,19 @@ + + +#include +#include + + +struct stateful_type { int operator(int) const { return 0; } }; + +int main() +{ + + stateful_type a_function_object; + boost::function1 f; + f = boost::ref(a_function_object); + + boost::function1 f2(f); + +} + \ No newline at end of file diff --git a/test/mem_fun_cxx98.cpp b/test/mem_fun_cxx98.cpp new file mode 100644 index 0000000..17f98c3 --- /dev/null +++ b/test/mem_fun_cxx98.cpp @@ -0,0 +1,23 @@ + + +#include +#include +#include + + +struct X { + int foo(int); +}; + +int main() +{ + +boost::function f; + +f = &X::foo; + +X x; +f(&x, 5); + +} + \ No newline at end of file diff --git a/test/mem_fun_portable.cpp b/test/mem_fun_portable.cpp new file mode 100644 index 0000000..c90f9ee --- /dev/null +++ b/test/mem_fun_portable.cpp @@ -0,0 +1,23 @@ + + +#include +#include +#include + + +struct X { + int foo(int); +}; + +int main() +{ + +boost::function2 f; + +f = &X::foo; + +X x; +f(&x, 5); + +} + \ No newline at end of file diff --git a/test/std_bind_cxx98.cpp b/test/std_bind_cxx98.cpp new file mode 100644 index 0000000..35ebc85 --- /dev/null +++ b/test/std_bind_cxx98.cpp @@ -0,0 +1,22 @@ + + +#include +#include +#include + + +struct X { + int foo(int); +}; + +int main() +{ + + boost::function f; + X x; + f = std::bind1st(std::mem_fun(&X::foo), &x); + + f(5); // Call x.foo(5) + +} + \ No newline at end of file diff --git a/test/std_bind_portable.cpp b/test/std_bind_portable.cpp new file mode 100644 index 0000000..696d58f --- /dev/null +++ b/test/std_bind_portable.cpp @@ -0,0 +1,22 @@ + + +#include +#include +#include + + +struct X { + int foo(int); +}; + +int main() +{ + + boost::function1 f; + X x; + f = std::bind1st(std::mem_fun(&X::foo), &x); + + f(5); // Call x.foo(5) + +} + \ No newline at end of file diff --git a/test/sum_avg_cxx98.cpp b/test/sum_avg_cxx98.cpp new file mode 100644 index 0000000..d41d8b4 --- /dev/null +++ b/test/sum_avg_cxx98.cpp @@ -0,0 +1,24 @@ + + +#include +#include + + +void do_sum_avg(int values[], int n, int& sum, float& avg) +{ + sum = 0; + for (int i = 0; i < n; i++) + sum += values[i]; + avg = (float)sum / n; +} + +int main() +{ + +boost::function sum_avg; + + +sum_avg = &do_sum_avg; + +} + \ No newline at end of file diff --git a/test/sum_avg_portable.cpp b/test/sum_avg_portable.cpp new file mode 100644 index 0000000..54158e5 --- /dev/null +++ b/test/sum_avg_portable.cpp @@ -0,0 +1,24 @@ + + +#include +#include + + +void do_sum_avg(int values[], int n, int& sum, float& avg) +{ + sum = 0; + for (int i = 0; i < n; i++) + sum += values[i]; + avg = (float)sum / n; +} + +int main() +{ + +boost::function4 sum_avg; + + +sum_avg = &do_sum_avg; + +} + \ No newline at end of file