deep_copy.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // deep_copy.hpp
  3. //
  4. // Copyright 2008 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include <iostream>
  8. #include <boost/utility/addressof.hpp>
  9. #include <boost/proto/core.hpp>
  10. #include <boost/test/unit_test.hpp>
  11. using namespace boost;
  12. void foo() {}
  13. void test1()
  14. {
  15. using namespace proto;
  16. int i = 42;
  17. terminal<int &>::type t1 = {i};
  18. terminal<int>::type r1 = deep_copy(t1);
  19. BOOST_CHECK_EQUAL(42, value(r1));
  20. plus<terminal<int>::type, terminal<int>::type>::type r2 = deep_copy(t1 + 24);
  21. BOOST_CHECK_EQUAL(42, value(left(r2)));
  22. BOOST_CHECK_EQUAL(24, value(right(r2)));
  23. char buf[16] = {'\0'};
  24. terminal<char (&)[16]>::type t3 = {buf};
  25. terminal<char[16]>::type r3 = deep_copy(t3);
  26. terminal<void(&)()>::type t4 = {foo};
  27. plus<terminal<void(&)()>::type, terminal<int>::type>::type r4 = deep_copy(t4 + t1);
  28. BOOST_CHECK_EQUAL(42, value(right(r4)));
  29. BOOST_CHECK_EQUAL(&foo, &value(left(r4)));
  30. terminal<std::ostream &>::type cout_ = {std::cout};
  31. shift_left<terminal<std::ostream &>::type, terminal<int>::type>::type r5 = deep_copy(cout_ << t1);
  32. BOOST_CHECK_EQUAL(42, value(right(r5)));
  33. BOOST_CHECK_EQUAL(boost::addressof(std::cout), boost::addressof(value(left(r5))));
  34. }
  35. using namespace unit_test;
  36. ///////////////////////////////////////////////////////////////////////////////
  37. // init_unit_test_suite
  38. //
  39. test_suite* init_unit_test_suite( int argc, char* argv[] )
  40. {
  41. test_suite *test = BOOST_TEST_SUITE("test deep_copy of proto parse trees");
  42. test->add(BOOST_TEST_CASE(&test1));
  43. return test;
  44. }