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_function_object.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 template <class Base = boost::mpl::empty_base>
22 struct test_func
23     : Base
24 {
25     template<typename T>
26     struct result;
27 
28     template<class Self, typename T0, typename T1>
29     struct result< Self(T0, T1) >
30     {
31         typedef int type;
32     };
33 
34     template <typename T0, typename T1>
operator ()test_func35     int operator()(T0 const & x, T1 const & y) const
36     {
37         return 1+x-y;
38     }
39 
40     template <typename T0, typename T1>
operator ()test_func41     int operator()(T0 const & x, T1 const & y)
42     {
43         return 2+x-y;
44     }
45 
46     template <typename T0, typename T1>
operator ()test_func47     int operator()(T0 & x, T1 & y) const
48     {
49         return 3+x-y;
50     }
51 
52     template <typename T0, typename T1>
operator ()test_func53     int operator()(T0 & x, T1 & y)
54     {
55         return 4+x-y;
56     }
57 };
58 
main()59 int main()
60 {
61     test_func<noncopyable> f;
62     fusion::fused_function_object< test_func<> > fused_func;
63     fusion::fused_function_object< test_func<noncopyable> & > fused_func_ref(f);
64     fusion::fused_function_object< test_func<> const > fused_func_c;
65     fusion::fused_function_object< test_func<> > const fused_func_c2;
66     fusion::fused_function_object< test_func<noncopyable> const & > fused_func_c_ref(f);
67 
68     fusion::vector<int,char> lv_vec(1,'\004');
69     BOOST_TEST(fused_func(lv_vec) == 1);
70     BOOST_TEST(fused_func_c(lv_vec) == 0);
71     BOOST_TEST(fused_func_c2(lv_vec) == 0);
72     BOOST_TEST(fused_func_ref(lv_vec) == 1);
73     BOOST_TEST(fused_func_c_ref(lv_vec) == 0);
74 
75     BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
76     BOOST_TEST(fused_func_c(fusion::make_vector(2,'\003')) == 0);
77     BOOST_TEST(fused_func_c2(fusion::make_vector(2,'\003')) == 0);
78     BOOST_TEST(fused_func_ref(fusion::make_vector(2,'\003')) == 1);
79     BOOST_TEST(fused_func_c_ref(fusion::make_vector(2,'\003')) == 0);
80 
81     return boost::report_errors();
82 }
83 
84