summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp')
-rw-r--r--src/boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp111
1 files changed, 111 insertions, 0 deletions
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 000000000..9c5255440
--- /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();
+}