• 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/adapter/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 
21 int effect;
22 
23 #define CHECK_EFFECT(t,e)        \
24     {                            \
25         effect = 1234567; t;     \
26         BOOST_TEST(effect == e); \
27     }
28 
29 template <class Base = boost::mpl::empty_base>
30 struct test_func
31     : Base
32 {
33     template <typename T0, typename T1>
operator ()test_func34     int operator()(T0 const & x, T1 const & y) const
35     {
36         return effect = 1+x-y;
37     }
38 
39     template <typename T0, typename T1>
operator ()test_func40     int operator()(T0 const & x, T1 const & y)
41     {
42         return effect = 2+x-y;
43     }
44 
45     template <typename T0, typename T1>
operator ()test_func46     int operator()(T0 & x, T1 & y) const
47     {
48         return effect = 3+x-y;
49     }
50 
51     template <typename T0, typename T1>
operator ()test_func52     int operator()(T0 & x, T1 & y)
53     {
54         return effect = 4+x-y;
55     }
56 };
57 
main()58 int main()
59 {
60     test_func<noncopyable> f;
61     fusion::fused_procedure< test_func<> > fused_proc;
62     fusion::fused_procedure< test_func<noncopyable> & > fused_proc_ref(f);
63     fusion::fused_procedure< test_func<> const > fused_proc_c;
64     fusion::fused_procedure< test_func<> > const fused_proc_c2;
65     fusion::fused_procedure< test_func<noncopyable> const & > fused_proc_c_ref(f);
66 
67     fusion::vector<int,char> lv_vec(1,'\004');
68     CHECK_EFFECT(fused_proc(lv_vec), 1);
69     CHECK_EFFECT(fused_proc_c(lv_vec), 0);
70     CHECK_EFFECT(fused_proc_c2(lv_vec), 0);
71     CHECK_EFFECT(fused_proc_ref(lv_vec), 1);
72     CHECK_EFFECT(fused_proc_c_ref(lv_vec), 0);
73 
74     CHECK_EFFECT(fused_proc(fusion::make_vector(2,'\003')), 1);
75     CHECK_EFFECT(fused_proc_c(fusion::make_vector(2,'\003')), 0);
76     CHECK_EFFECT(fused_proc_c2(fusion::make_vector(2,'\003')), 0);
77     CHECK_EFFECT(fused_proc_ref(fusion::make_vector(2,'\003')), 1);
78     CHECK_EFFECT(fused_proc_c_ref(fusion::make_vector(2,'\003')), 0);
79 
80     return boost::report_errors();
81 }
82 
83