• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////
2 // noinvoke.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 <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 struct Test
17   : proto::when<
18         _
19       , proto::noinvoke<
20             // This remove_pointer invocation is bloked by noinvoke
21             boost::remove_pointer<
22                 // This add_pointer invocation is *not* blocked by noinvoke
23                 boost::add_pointer<_>
24             >
25         >()
26     >
27 {};
28 
29 struct Test2
30   : proto::when<
31         _
32         // This add_pointer gets invoked because a substitution takes place
33         // within it.
34       , boost::add_pointer<
35             proto::noinvoke<
36                 // This remove_pointer invocation is bloked by noinvoke
37                 boost::remove_pointer<
38                     // This add_pointer invocation is *not* blocked by noinvoke
39                     boost::add_pointer<_>
40                 >
41             >
42         >()
43     >
44 {};
45 
46 template<typename T, typename U>
47 struct select2nd
48 {
49     typedef U type;
50 };
51 
52 struct Test3
53   : proto::when<
54         _
55         // This add_pointer gets invoked because a substitution takes place
56         // within it.
57       , select2nd<
58             void
59           , proto::noinvoke<
60                 // This remove_pointer invocation is bloked by noinvoke
61                 select2nd<
62                     void
63                     // This add_pointer invocation is *not* blocked by noinvoke
64                   , boost::add_pointer<_>
65                 >
66             >
67         >()
68     >
69 {};
70 
71 
test_noinvoke()72 void test_noinvoke()
73 {
74     typedef proto::terminal<int>::type Int;
75     Int i = {42};
76 
77     BOOST_MPL_ASSERT((
78         boost::is_same<
79             boost::result_of<Test(Int)>::type
80           , boost::remove_pointer<Int *>
81         >
82     ));
83 
84     boost::remove_pointer<Int *> t = Test()(i);
85 
86     BOOST_MPL_ASSERT((
87         boost::is_same<
88             boost::result_of<Test2(Int)>::type
89           , boost::remove_pointer<Int *> *
90         >
91     ));
92 
93     boost::remove_pointer<Int *> * t2 = Test2()(i);
94 
95     BOOST_MPL_ASSERT((
96         boost::is_same<
97             boost::result_of<Test3(Int)>::type
98           , select2nd<void, Int *>
99         >
100     ));
101 
102     select2nd<void, Int *> t3 = Test3()(i);
103 }
104 
105 using namespace boost::unit_test;
106 ///////////////////////////////////////////////////////////////////////////////
107 // init_unit_test_suite
108 //
init_unit_test_suite(int argc,char * argv[])109 test_suite* init_unit_test_suite( int argc, char* argv[] )
110 {
111     test_suite *test = BOOST_TEST_SUITE("test proto::noinvoke");
112 
113     test->add(BOOST_TEST_CASE(&test_noinvoke));
114 
115     return test;
116 }
117