• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////
2 // protect.hpp
3 //
4 //  Copyright 2012 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 <boost/proto/core.hpp>
9 #include <boost/proto/transform/make.hpp>
10 #include <boost/type_traits/add_pointer.hpp>
11 #include <boost/type_traits/remove_pointer.hpp>
12 #include <boost/test/unit_test.hpp>
13 namespace proto=boost::proto;
14 using proto::_;
15 
16 template<typename T>
17 struct identity
18 {
19     typedef T type;
20 };
21 
22 struct TestWithMake
23   : proto::make< proto::protect<_> >
24 {};
25 
26 struct TestWithMake1
27   : proto::make< identity<proto::protect<_> > >
28 {};
29 
30 struct TestWithMake2
31   : proto::make< identity<proto::protect<int> > >
32 {};
33 
34 struct TestWithMake3
35   : proto::make< identity<proto::protect<identity<_> > > >
36 {};
37 
38 struct TestWithMake4
39   : proto::make< identity<proto::protect<identity<int> > > >
40 {};
41 
42 struct TestWithMake5
43   : proto::make< identity<proto::protect<identity<identity<int> > > > >
44 {};
45 
test_protect_with_make()46 void test_protect_with_make()
47 {
48     proto::terminal<int>::type i = {42};
49 
50     _ t = TestWithMake()(i);
51     _ t1 = TestWithMake1()(i);
52     int t2 = TestWithMake2()(i);
53     identity<_> t3 = TestWithMake3()(i);
54     identity<int> t4 = TestWithMake4()(i);
55     identity<identity<int> > t5 = TestWithMake5()(i);
56 }
57 
58 //struct TestWithWhen
59 //  : proto::when<_, proto::protect<_>() >
60 //{};
61 
62 struct TestWithWhen1
63   : proto::when<_, identity<proto::protect<_> >() >
64 {};
65 
66 struct TestWithWhen2
67   : proto::when<_, identity<proto::protect<int> >() >
68 {};
69 
70 struct TestWithWhen3
71   : proto::when<_, identity<proto::protect<identity<_> > >() >
72 {};
73 
74 struct TestWithWhen4
75   : proto::when<_, identity<proto::protect<identity<int> > >() >
76 {};
77 
78 struct TestWithWhen5
79   : proto::when<_, identity<proto::protect<identity<identity<int> > > >() >
80 {};
81 
test_protect_with_when()82 void test_protect_with_when()
83 {
84     proto::terminal<int>::type i = {42};
85 
86     //_ t = TestWithWhen()(i);
87     _ t1 = TestWithWhen1()(i);
88     int t2 = TestWithWhen2()(i);
89     identity<_> t3 = TestWithWhen3()(i);
90     identity<int> t4 = TestWithWhen4()(i);
91     identity<identity<int> > t5 = TestWithWhen5()(i);
92 }
93 
94 using namespace boost::unit_test;
95 ///////////////////////////////////////////////////////////////////////////////
96 // init_unit_test_suite
97 //
init_unit_test_suite(int argc,char * argv[])98 test_suite* init_unit_test_suite( int argc, char* argv[] )
99 {
100     test_suite *test = BOOST_TEST_SUITE("test proto::protect");
101 
102     test->add(BOOST_TEST_CASE(&test_protect_with_make));
103     test->add(BOOST_TEST_CASE(&test_protect_with_when));
104 
105     return test;
106 }
107