From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/phoenix/test/object/cast_tests.cpp | 67 ++++++++++++++++++++++ .../libs/phoenix/test/object/new_delete_tests.cpp | 59 +++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/boost/libs/phoenix/test/object/cast_tests.cpp create mode 100644 src/boost/libs/phoenix/test/object/new_delete_tests.cpp (limited to 'src/boost/libs/phoenix/test/object') 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 +#include +#include +#include + +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_(arg1)(u).foo() == "T"); + } + + { + U const u = U(); + BOOST_TEST(const_cast_(arg1)(u).foo() == "U"); + } + + { + VU u; + VT* tp = &u; + BOOST_TEST(arg1(tp)->foo() == "U"); + BOOST_TEST(dynamic_cast_(arg1)(tp) != 0); + } + + { + void* p = 0; + reinterpret_cast_(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 +#include +#include +#include +#include +#include +#include +#include + +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 v(10); + + for_each(v.begin(), v.end(), arg1 = new_()); + for_each(v.begin(), v.end(), delete_(arg1)); + + for_each(v.begin(), v.end(), arg1 = new_(1, 2, 3)); + for_each(v.begin(), v.end(), delete_(arg1)); + } + + { + using boost::shared_ptr; + vector > v(10); + for_each(v.begin(), v.end(), + arg1 = boost::phoenix::construct >(new_()) + ); + } + + BOOST_TEST(n == 0); + return boost::report_errors(); +} -- cgit v1.2.3