• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include <iostream>
9 #include <boost/utility/addressof.hpp>
10 #include <boost/proto/core.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 using namespace boost;
14 
foo()15 void foo() {}
16 
test1()17 void test1()
18 {
19     using namespace proto;
20 
21     int i = 42;
22     terminal<int &>::type t1 = {i};
23     terminal<int>::type r1 = deep_copy(t1);
24     BOOST_CHECK_EQUAL(42, value(r1));
25 
26     plus<terminal<int>::type, terminal<int>::type>::type r2 = deep_copy(t1 + 24);
27     BOOST_CHECK_EQUAL(42, value(left(r2)));
28     BOOST_CHECK_EQUAL(24, value(right(r2)));
29 
30     char buf[16] = {'\0'};
31     terminal<char (&)[16]>::type t3 = {buf};
32     terminal<char[16]>::type r3 = deep_copy(t3);
33 
34     terminal<void(&)()>::type t4 = {foo};
35     plus<terminal<void(&)()>::type, terminal<int>::type>::type r4 = deep_copy(t4 + t1);
36     BOOST_CHECK_EQUAL(42, value(right(r4)));
37     BOOST_CHECK_EQUAL(&foo, &value(left(r4)));
38 
39     terminal<std::ostream &>::type cout_ = {std::cout};
40     shift_left<terminal<std::ostream &>::type, terminal<int>::type>::type r5 = deep_copy(cout_ << t1);
41     BOOST_CHECK_EQUAL(42, value(right(r5)));
42     BOOST_CHECK_EQUAL(boost::addressof(std::cout), boost::addressof(value(left(r5))));
43 }
44 
45 using namespace unit_test;
46 ///////////////////////////////////////////////////////////////////////////////
47 // init_unit_test_suite
48 //
init_unit_test_suite(int argc,char * argv[])49 test_suite* init_unit_test_suite( int argc, char* argv[] )
50 {
51     test_suite *test = BOOST_TEST_SUITE("test deep_copy of proto parse trees");
52 
53     test->add(BOOST_TEST_CASE(&test1));
54 
55     return test;
56 }
57