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
13using namespace boost;
14
15void foo() {}
16
17void test1()
18{
19 using namespace proto;
20
21 int i = 42;
22 terminal<int &>::type t1 = {.child0: i};
23 terminal<int>::type r1 = deep_copy(e: t1);
24 BOOST_CHECK_EQUAL(42, value(r1));
25
26 plus<terminal<int>::type, terminal<int>::type>::type r2 = deep_copy(e: 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 = {.child0: buf};
32 terminal<char[16]>::type r3 = deep_copy(e: t3);
33
34 terminal<void(&)()>::type t4 = {.child0: foo};
35 plus<terminal<void(&)()>::type, terminal<int>::type>::type r4 = deep_copy(e: 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_ = {.child0: std::cout};
40 shift_left<terminal<std::ostream &>::type, terminal<int>::type>::type r5 = deep_copy(e: 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
45using namespace unit_test;
46///////////////////////////////////////////////////////////////////////////////
47// init_unit_test_suite
48//
49test_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

source code of boost/libs/proto/test/deep_copy.cpp