cast_tests.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #include <string>
  7. #include <boost/detail/lightweight_test.hpp>
  8. #include <boost/phoenix/core.hpp>
  9. #include <boost/phoenix/object.hpp>
  10. using std::string;
  11. struct T
  12. {
  13. string foo() { return "T"; }
  14. };
  15. struct U : T
  16. {
  17. string foo() { return "U"; }
  18. };
  19. struct VT
  20. {
  21. virtual string foo() { return "T"; }
  22. };
  23. struct VU : VT
  24. {
  25. virtual string foo() { return "U"; }
  26. };
  27. int
  28. main()
  29. {
  30. using boost::phoenix::arg_names::arg1;
  31. using boost::phoenix::const_cast_;
  32. using boost::phoenix::dynamic_cast_;
  33. using boost::phoenix::reinterpret_cast_;
  34. using boost::phoenix::static_cast_;
  35. {
  36. U u;
  37. BOOST_TEST(arg1(u).foo() == "U");
  38. BOOST_TEST(static_cast_<T&>(arg1)(u).foo() == "T");
  39. }
  40. {
  41. U const u = U();
  42. BOOST_TEST(const_cast_<U&>(arg1)(u).foo() == "U");
  43. }
  44. {
  45. VU u;
  46. VT* tp = &u;
  47. BOOST_TEST(arg1(tp)->foo() == "U");
  48. BOOST_TEST(dynamic_cast_<VU*>(arg1)(tp) != 0);
  49. }
  50. {
  51. void* p = 0;
  52. reinterpret_cast_<VU*>(arg1)(p); // compile test only
  53. }
  54. return boost::report_errors();
  55. }