summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/phoenix/test/object
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/object
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.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/object')
-rw-r--r--src/boost/libs/phoenix/test/object/cast_tests.cpp67
-rw-r--r--src/boost/libs/phoenix/test/object/new_delete_tests.cpp59
2 files changed, 126 insertions, 0 deletions
diff --git a/src/boost/libs/phoenix/test/object/cast_tests.cpp b/src/boost/libs/phoenix/test/object/cast_tests.cpp
new file mode 100644
index 00000000..11745269
--- /dev/null
+++ b/src/boost/libs/phoenix/test/object/cast_tests.cpp
@@ -0,0 +1,67 @@
+/*=============================================================================
+ 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 <string>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/object.hpp>
+
+using std::string;
+
+struct T
+{
+ string foo() { return "T"; }
+};
+
+struct U : T
+{
+ string foo() { return "U"; }
+};
+
+struct VT
+{
+ virtual string foo() { return "T"; }
+};
+
+struct VU : VT
+{
+ virtual string foo() { return "U"; }
+};
+
+int
+main()
+{
+ using boost::phoenix::arg_names::arg1;
+ using boost::phoenix::const_cast_;
+ using boost::phoenix::dynamic_cast_;
+ using boost::phoenix::reinterpret_cast_;
+ using boost::phoenix::static_cast_;
+
+ {
+ U u;
+ BOOST_TEST(arg1(u).foo() == "U");
+ BOOST_TEST(static_cast_<T&>(arg1)(u).foo() == "T");
+ }
+
+ {
+ U const u = U();
+ BOOST_TEST(const_cast_<U&>(arg1)(u).foo() == "U");
+ }
+
+ {
+ VU u;
+ VT* tp = &u;
+ BOOST_TEST(arg1(tp)->foo() == "U");
+ BOOST_TEST(dynamic_cast_<VU*>(arg1)(tp) != 0);
+ }
+
+ {
+ void* p = 0;
+ reinterpret_cast_<VU*>(arg1)(p); // compile test only
+ }
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/phoenix/test/object/new_delete_tests.cpp b/src/boost/libs/phoenix/test/object/new_delete_tests.cpp
new file mode 100644
index 00000000..a84168f4
--- /dev/null
+++ b/src/boost/libs/phoenix/test/object/new_delete_tests.cpp
@@ -0,0 +1,59 @@
+/*=============================================================================
+ 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 <vector>
+#include <algorithm>
+#include <boost/shared_ptr.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/object.hpp>
+#include <boost/phoenix/operator.hpp>
+
+int n = 0;
+
+using std::cout;
+using std::endl;
+
+struct X
+{
+ X(int, int, int) { cout << "new X(int, int, int)" << endl; ++n; }
+ X() { cout << "new X" << endl; ++n; }
+ ~X() { cout << "delete X" << endl; --n; }
+};
+
+int
+main()
+{
+ using boost::phoenix::arg_names::arg1;
+ using boost::phoenix::construct;
+ using boost::phoenix::delete_;
+ using boost::phoenix::new_;
+
+ using std::for_each;
+ using std::vector;
+
+ {
+ vector<X*> v(10);
+
+ for_each(v.begin(), v.end(), arg1 = new_<X>());
+ for_each(v.begin(), v.end(), delete_(arg1));
+
+ for_each(v.begin(), v.end(), arg1 = new_<X>(1, 2, 3));
+ for_each(v.begin(), v.end(), delete_(arg1));
+ }
+
+ {
+ using boost::shared_ptr;
+ vector<shared_ptr<X> > v(10);
+ for_each(v.begin(), v.end(),
+ arg1 = boost::phoenix::construct<shared_ptr<X> >(new_<X>())
+ );
+ }
+
+ BOOST_TEST(n == 0);
+ return boost::report_errors();
+}