• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2006-2007 Tobias Schwinger
3 
4     Use modification and distribution are subject to the Boost Software
5     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6     http://www.boost.org/LICENSE_1_0.txt).
7 ==============================================================================*/
8 
9 #include <boost/fusion/functional/generation/make_fused_procedure.hpp>
10 #include <boost/detail/lightweight_test.hpp>
11 
12 #include <boost/noncopyable.hpp>
13 #include <boost/mpl/empty_base.hpp>
14 
15 #include <boost/fusion/container/generation/make_vector.hpp>
16 #include <boost/fusion/container/vector.hpp>
17 
18 namespace fusion = boost::fusion;
19 using boost::noncopyable;
20 using boost::cref;
21 using boost::ref;
22 
23 int effect;
24 
25 #define CHECK_EFFECT(t,e)        \
26     {                            \
27         effect = 1234567; t;     \
28         BOOST_TEST(effect == e); \
29     }
30 
31 template <class Base = boost::mpl::empty_base>
32 struct test_func
33     : Base
34 {
35     template <typename T0, typename T1>
operator ()test_func36     int operator()(T0 const & x, T1 const & y) const
37     {
38         return effect = 1+x-y;
39     }
40 
41     template <typename T0, typename T1>
operator ()test_func42     int operator()(T0 const & x, T1 const & y)
43     {
44         return effect = 2+x-y;
45     }
46 
47     template <typename T0, typename T1>
operator ()test_func48     int operator()(T0 & x, T1 & y) const
49     {
50         return effect = 3+x-y;
51     }
52 
53     template <typename T0, typename T1>
operator ()test_func54     int operator()(T0 & x, T1 & y)
55     {
56         return effect = 4+x-y;
57     }
58 };
59 
60 template <typename T>
const_(T const & t)61 inline T const & const_(T const & t)
62 {
63     return t;
64 }
65 
main()66 int main()
67 {
68     fusion::vector<int,char> lv_vec(1,'\004');
69     test_func<> f;
70     test_func<noncopyable> f_nc;
71 
72     boost::fusion::result_of::make_fused_procedure< test_func<> >::type fused_func
73         = fusion::make_fused_procedure(f);
74 
75     CHECK_EFFECT(fused_func(lv_vec), 1);
76     CHECK_EFFECT(const_(fused_func)(lv_vec), 0);
77     CHECK_EFFECT(fusion::make_fused_procedure(const_(f))(lv_vec), 1);
78     CHECK_EFFECT(fusion::make_fused_procedure(ref(f_nc))(lv_vec), 1);
79     CHECK_EFFECT(fusion::make_fused_procedure(cref(f_nc))(lv_vec), 0);
80 
81     CHECK_EFFECT(fused_func(fusion::make_vector(2,'\003')), 1);
82     CHECK_EFFECT(const_(fused_func)(fusion::make_vector(2,'\003')), 0);
83     CHECK_EFFECT(fusion::make_fused_procedure(const_(f))(fusion::make_vector(2,'\003')), 1);
84     CHECK_EFFECT(fusion::make_fused_procedure(ref(f_nc))(fusion::make_vector(2,'\003')), 1);
85     CHECK_EFFECT(fusion::make_fused_procedure(cref(f_nc))(fusion::make_vector(2,'\003')), 0);
86 
87     return boost::report_errors();
88 }
89 
90 
91 
92