summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/phoenix/test/bind
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/phoenix/test/bind
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/phoenix/test/bind')
-rw-r--r--src/boost/libs/phoenix/test/bind/bind_function_object_tests.cpp137
-rw-r--r--src/boost/libs/phoenix/test/bind/bind_function_object_tests_phx2.cpp112
-rw-r--r--src/boost/libs/phoenix/test/bind/bind_function_tests.cpp56
-rw-r--r--src/boost/libs/phoenix/test/bind/bind_member_function_tests.cpp77
-rw-r--r--src/boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp111
-rw-r--r--src/boost/libs/phoenix/test/bind/bug5782.cpp23
6 files changed, 516 insertions, 0 deletions
diff --git a/src/boost/libs/phoenix/test/bind/bind_function_object_tests.cpp b/src/boost/libs/phoenix/test/bind/bind_function_object_tests.cpp
new file mode 100644
index 00000000..7e2ee94a
--- /dev/null
+++ b/src/boost/libs/phoenix/test/bind/bind_function_object_tests.cpp
@@ -0,0 +1,137 @@
+/*=============================================================================
+ Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2015 John Fletcher
+
+ Distributed under 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)
+==============================================================================*/
+#include <iostream>
+#include <cmath>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/operator.hpp>
+#include <boost/phoenix/bind.hpp>
+
+namespace phoenix = boost::phoenix;
+using std::cout;
+using std::pow;
+
+ struct test
+ {
+ typedef void result_type;
+
+ void
+ operator()() const
+ {
+ cout << "Test lazy functions...\n";
+ }
+ };
+
+ struct sqr
+ {
+ template <typename Sig>
+ struct result;
+
+ template <typename This, typename Arg>
+ struct result<This(Arg&)>
+ {
+ typedef Arg type;
+ };
+
+ template <typename Arg>
+ Arg
+ operator()(Arg n) const
+ {
+ return n * n;
+ }
+ };
+
+ struct fact
+ {
+ template <typename Sig>
+ struct result;
+
+ template <typename This, typename Arg>
+ struct result<This(Arg&)>
+ {
+ typedef Arg type;
+ };
+
+ template <typename Arg>
+ Arg
+ operator()(Arg n) const
+ {
+ return (n <= 0) ? 1 : n * (*this)(n-1);
+ }
+ };
+
+ struct power
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename Arg1, typename Arg2>
+ struct result<This(Arg1&, Arg2&)>
+ {
+ typedef Arg1 type;
+ };
+
+ template <typename Arg1, typename Arg2>
+ Arg1
+ operator()(Arg1 a, Arg2 b) const
+ {
+ return pow(a, b);
+ }
+ };
+
+ struct add
+ {
+ template <typename Sig>
+ struct result;
+
+ template <typename This, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ struct result<This(Arg1&, Arg2&, Arg3&, Arg4&)>
+ {
+ typedef Arg1 type;
+ };
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ Arg1
+ operator()(Arg1 a, Arg2 b, Arg3 c, Arg4 d) const
+ {
+ return a + b + c + d;
+ }
+ };
+
+int
+main()
+{
+ using phoenix::bind;
+ using phoenix::ref;
+ using phoenix::arg_names::_1;
+ using phoenix::arg_names::arg1;
+ using phoenix::arg_names::arg2;
+
+ int i5 = 5;
+ double d5 = 5, d3 = 3;
+
+ test()();
+ BOOST_TEST(bind(sqr(), arg1)(i5) == (i5*i5));
+ BOOST_TEST(bind(fact(), 4)() == 24);
+ BOOST_TEST(bind(fact(), arg1)(i5) == 120);
+ BOOST_TEST((int)bind(power(), arg1, arg2)(d5, d3) == (int)std::pow(d5, d3));
+ BOOST_TEST((bind(sqr(), arg1) + 5)(i5) == ((i5*i5)+5));
+ BOOST_TEST(bind(add(), arg1, arg1, arg1, arg1)(i5) == (5+5+5+5));
+
+ int const ic5 = 5;
+ // testing consts
+ BOOST_TEST(bind(sqr(), arg1)(ic5) == (ic5*ic5));
+
+ // From Steven Watanabe
+ sqr s;
+ int x = 2;
+ int result = bind(ref(s), _1)(x);
+ BOOST_TEST(result == 4);
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/phoenix/test/bind/bind_function_object_tests_phx2.cpp b/src/boost/libs/phoenix/test/bind/bind_function_object_tests_phx2.cpp
new file mode 100644
index 00000000..45758055
--- /dev/null
+++ b/src/boost/libs/phoenix/test/bind/bind_function_object_tests_phx2.cpp
@@ -0,0 +1,112 @@
+/*=============================================================================
+ Copyright (c) 2001-2007 Joel de Guzman
+
+ Distributed under 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)
+==============================================================================*/
+#include <iostream>
+#include <cmath>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/operator.hpp>
+#include <boost/phoenix/bind.hpp>
+
+using namespace boost::phoenix;
+using namespace boost::phoenix::arg_names;
+using namespace std;
+
+ struct test
+ {
+ typedef void result_type;
+ void operator()() const
+ {
+ cout << "Test lazy functions...\n";
+ }
+ };
+
+ struct sqr
+ {
+ template <typename Arg>
+ struct result
+ {
+ typedef Arg type;
+ };
+
+ template <typename Arg>
+ Arg operator()(Arg n) const
+ {
+ return n * n;
+ }
+ };
+
+ struct fact
+ {
+ template <typename Arg>
+ struct result
+ {
+ typedef Arg type;
+ };
+
+ template <typename Arg>
+ Arg operator()(Arg n) const
+ {
+ return (n <= 0) ? 1 : n * (*this)(n-1);
+ }
+ };
+
+ struct power
+ {
+ template <typename Arg1, typename Arg2>
+ struct result
+ {
+ typedef Arg1 type;
+ };
+
+ template <typename Arg1, typename Arg2>
+ Arg1 operator()(Arg1 a, Arg2 b) const
+ {
+ return pow(a, b);
+ }
+ };
+
+ struct add
+ {
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ struct result
+ {
+ typedef Arg1 type;
+ };
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ Arg1 operator()(Arg1 a, Arg2 b, Arg3 c, Arg4 d) const
+ {
+ return a + b + c + d;
+ }
+ };
+
+int
+main()
+{
+ int i5 = 5;
+ double d5 = 5, d3 = 3;
+
+ test()();
+ BOOST_TEST(bind(sqr(), arg1)(i5) == (i5*i5));
+ BOOST_TEST(bind(fact(), 4)() == 24);
+ BOOST_TEST(bind(fact(), arg1)(i5) == 120);
+ BOOST_TEST((int)bind(power(), arg1, arg2)(d5, d3) == (int)pow(d5, d3));
+ BOOST_TEST((bind(sqr(), arg1) + 5)(i5) == ((i5*i5)+5));
+ BOOST_TEST(bind(add(), arg1, arg1, arg1, arg1)(i5) == (5+5+5+5));
+
+ int const ic5 = 5;
+ // testing consts
+ BOOST_TEST(bind(sqr(), arg1)(ic5) == (ic5*ic5));
+
+ // From Steven Watanabe
+ sqr s;
+ int x = 2;
+ int result = bind(ref(s), _1)(x);
+ BOOST_TEST(result == 4);
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/phoenix/test/bind/bind_function_tests.cpp b/src/boost/libs/phoenix/test/bind/bind_function_tests.cpp
new file mode 100644
index 00000000..04328b60
--- /dev/null
+++ b/src/boost/libs/phoenix/test/bind/bind_function_tests.cpp
@@ -0,0 +1,56 @@
+/*=============================================================================
+ Copyright (c) 2001-2007 Joel de Guzman
+
+ Distributed under 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)
+ ==============================================================================*/
+#include <iostream>
+#include <cmath>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/bind.hpp>
+
+namespace test
+{
+ void
+ test()
+ {
+ std::cout << "Test binding functions...\n";
+ }
+
+ int
+ negate(int n)
+ {
+ return -n;
+ }
+
+ int
+ plus(int a, int b)
+ {
+ return a + b;
+ }
+
+ int
+ plus4(int a, int b, int c, int d)
+ {
+ return a + b + c + d;
+ }
+}
+
+int
+main()
+{
+ using boost::phoenix::bind;
+ using boost::phoenix::arg_names::arg1;
+ using boost::phoenix::arg_names::arg2;
+
+ int a = 123;
+ int b = 256;
+
+ bind(test::test)();
+ BOOST_TEST(bind(test::negate, arg1)(a) == -a);
+ BOOST_TEST(bind(test::plus, arg1, arg2)(a, b) == a+b);
+ BOOST_TEST(bind(test::plus4, arg1, arg2, 3, 4)(a, b) == a+b+3+4);
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/phoenix/test/bind/bind_member_function_tests.cpp b/src/boost/libs/phoenix/test/bind/bind_member_function_tests.cpp
new file mode 100644
index 00000000..ee26f00f
--- /dev/null
+++ b/src/boost/libs/phoenix/test/bind/bind_member_function_tests.cpp
@@ -0,0 +1,77 @@
+/*=============================================================================
+ Copyright (c) 2001-2007 Joel de Guzman
+
+ Distributed under 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)
+==============================================================================*/
+#include <iostream>
+#include <cmath>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/operator.hpp>
+#include <boost/phoenix/bind.hpp>
+
+namespace test
+{
+ struct x //: boost::noncopyable // test non-copyable (hold this by reference)
+ {
+ void
+ test() const
+ {
+ std::cout << "Test binding member functions...\n";
+ }
+ };
+
+ struct y //: boost::noncopyable // test non-copyable (hold this by reference)
+ {
+ int
+ negate(int n) const
+ {
+ return -n;
+ }
+ };
+
+ struct z //: boost::noncopyable // test non-copyable (hold this by reference)
+ {
+ int
+ plus(int a, int b) const
+ {
+ return a + b;
+ }
+ };
+
+ struct zz //: boost::noncopyable // test non-copyable (hold this by reference)
+ {
+ int
+ plus3(int a, int b, int c) const
+ {
+ return a + b + c;
+ }
+ };
+}
+
+int
+main()
+{
+ using boost::phoenix::bind;
+ using boost::phoenix::ref;
+ using boost::phoenix::arg_names::arg1;
+ using boost::phoenix::arg_names::arg2;
+ using boost::phoenix::arg_names::arg3;
+
+ int a = 123;
+ int b = 256;
+ test::x x_;
+ test::y y_;
+ test::z z_;
+ test::zz zz_;
+
+ bind(&test::x::test, x_)();
+ BOOST_TEST(bind(&test::y::negate, y_, arg1)(a) == -a);
+ BOOST_TEST(bind(&test::z::plus, arg1, arg2, arg3)(z_, a, b) == a+b);
+ BOOST_TEST(bind(&test::zz::plus3, zz_, arg1, arg2, arg3)(a, b, a) == a+b+a);
+ BOOST_TEST(bind(&test::y::negate, &y_, 777)(a) == -777);
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp b/src/boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp
new file mode 100644
index 00000000..9c525544
--- /dev/null
+++ b/src/boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp
@@ -0,0 +1,111 @@
+/*=============================================================================
+ Copyright (c) 2001-2007 Joel de Guzman
+
+ Distributed under 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)
+==============================================================================*/
+#include <iostream>
+#include <cmath>
+#include <boost/noncopyable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/bind.hpp>
+
+namespace test
+{
+ struct x //: boost::noncopyable // test non-copyable (hold this by reference)
+ {
+ int m;
+ };
+
+ struct xx {
+ int m;
+ };
+}
+
+template <typename T, typename F>
+void
+write_test(F f)
+{
+ using boost::phoenix::arg_names::arg1;
+ using boost::phoenix::bind;
+
+ T x_;
+
+ bind(&T::m, f(x_))() = 122;
+ BOOST_TEST(x_.m == 122);
+ bind(&T::m, arg1)(f(x_)) = 123;
+ BOOST_TEST(x_.m == 123);
+}
+
+template <typename T, typename F>
+void
+read_test(F f)
+{
+ using boost::phoenix::arg_names::arg1;
+ using boost::phoenix::bind;
+
+ T x_;
+ x_.m = 123;
+
+ BOOST_TEST(bind(&T::m, f(x_))() == 123);
+ BOOST_TEST(bind(&T::m, arg1)(f(x_)) == 123);
+}
+
+struct identity
+{
+ template <typename T>
+ T&
+ operator()(T& t) const
+ {
+ return t;
+ }
+};
+
+struct constify
+{
+ template <typename T>
+ T const&
+ operator()(T const& t) const
+ {
+ return t;
+ }
+};
+
+struct add_pointer
+{
+ template <typename T>
+ T* /*const*/
+ operator()(T& t) const
+ {
+ return &t;
+ }
+};
+
+struct add_const_pointer
+{
+ template <typename T>
+ const T* /*const*/
+ operator()(T const& t) const
+ {
+ return &t;
+ }
+};
+
+int
+main()
+{
+ write_test<test::x>(add_pointer());
+ write_test<test::xx>(add_pointer());
+
+ read_test<test::x>(identity());
+ read_test<test::x>(constify());
+ read_test<test::x>(add_pointer());
+ read_test<test::x>(add_const_pointer());
+ read_test<test::xx>(identity());
+ read_test<test::xx>(constify());
+ read_test<test::xx>(add_pointer());
+ read_test<test::xx>(add_const_pointer());
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/phoenix/test/bind/bug5782.cpp b/src/boost/libs/phoenix/test/bind/bug5782.cpp
new file mode 100644
index 00000000..37b38c97
--- /dev/null
+++ b/src/boost/libs/phoenix/test/bind/bug5782.cpp
@@ -0,0 +1,23 @@
+/*=============================================================================
+ Copyright (c) 2001-2007 Joel de Guzman
+
+ Distributed under 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)
+==============================================================================*/
+#include <boost/phoenix/bind/bind_function.hpp>
+#include <boost/phoenix/core/argument.hpp>
+
+#include <iostream>
+
+using namespace boost::phoenix;
+using namespace boost::phoenix::placeholders;
+
+void foo(int n)
+{
+ std::cout << n << std::endl;
+}
+
+int main()
+{
+ bind(&foo, arg1)(4);
+}