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_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 using boost::cref;
21 using boost::ref;
22
23 template <class Base = boost::mpl::empty_base>
24 struct test_func
25 : Base
26 {
27 template<typename T>
28 struct result
29 {
30 };
31
32
33 template<class Self, typename T0, typename T1>
34 struct result< Self(T0, T1) >
35 {
36 typedef int type;
37 };
38
39 template <typename T0, typename T1>
operator ()test_func40 int operator()(T0 const & x, T1 const & y) const
41 {
42 return 1+x-y;
43 }
44
45 template <typename T0, typename T1>
operator ()test_func46 int operator()(T0 const & x, T1 const & y)
47 {
48 return 2+x-y;
49 }
50
51 template <typename T0, typename T1>
operator ()test_func52 int operator()(T0 & x, T1 & y) const
53 {
54 return 3+x-y;
55 }
56
57 template <typename T0, typename T1>
operator ()test_func58 int operator()(T0 & x, T1 & y)
59 {
60 return 4+x-y;
61 }
62 };
63
64 template <typename T>
const_(T const & t)65 inline T const & const_(T const & t)
66 {
67 return t;
68 }
69
main()70 int main()
71 {
72 fusion::vector<int,char> lv_vec(1,'\004');
73 test_func<> f;
74 test_func<noncopyable> f_nc;
75
76 boost::fusion::result_of::make_fused_function_object< test_func<> >::type fused_func
77 = fusion::make_fused_function_object(f);
78
79 BOOST_TEST(fused_func(lv_vec) == 1);
80 BOOST_TEST(const_(fused_func)(lv_vec) == 0);
81 BOOST_TEST(fusion::make_fused_function_object(const_(f))(lv_vec) == 1);
82 BOOST_TEST(fusion::make_fused_function_object(ref(f_nc))(lv_vec) == 1);
83 BOOST_TEST(fusion::make_fused_function_object(cref(f_nc))(lv_vec) == 0);
84
85 BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
86 BOOST_TEST(const_(fused_func)(fusion::make_vector(2,'\003')) == 0);
87 BOOST_TEST(fusion::make_fused_function_object(const_(f))(fusion::make_vector(2,'\003')) == 1);
88 BOOST_TEST(fusion::make_fused_function_object(ref(f_nc))(fusion::make_vector(2,'\003')) == 1);
89 BOOST_TEST(fusion::make_fused_function_object(cref(f_nc))(fusion::make_vector(2,'\003')) == 0);
90
91 return boost::report_errors();
92 }
93
94
95
96