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.hpp>
10 #include <boost/detail/lightweight_test.hpp>
11
12 #include <boost/noncopyable.hpp>
13
14 #include <boost/fusion/container/generation/make_vector.hpp>
15 #include <boost/fusion/container/vector.hpp>
16
17 #include <boost/type_traits/is_same.hpp>
18 #include <boost/mpl/assert.hpp>
19 #include <boost/mpl/empty_base.hpp>
20
21 namespace fusion = boost::fusion;
22 using boost::noncopyable;
23
24 template <class Base = boost::mpl::empty_base>
25 struct test_func
26 : Base
27 {
28 typedef int result_type;
29
30 template <typename T0, typename T1>
operator ()test_func31 int operator()(T0 const & x, T1 const & y) const
32 {
33 return 1+x-y;
34 }
35
36 template <typename T0, typename T1>
operator ()test_func37 int operator()(T0 const & x, T1 const & y)
38 {
39 return 2+x-y;
40 }
41
42 template <typename T0, typename T1>
operator ()test_func43 int operator()(T0 & x, T1 & y) const
44 {
45 return 3+x-y;
46 }
47
48 template <typename T0, typename T1>
operator ()test_func49 int operator()(T0 & x, T1 & y)
50 {
51 return 4+x-y;
52 }
53 };
54
main()55 int main()
56 {
57 test_func<noncopyable> f;
58
59 typedef fusion::fused< test_func<> > ff;
60 ff fused_func;
61
62 typedef fusion::fused< test_func<noncopyable> & > ffr;
63 ffr fused_func_ref(f);
64
65 typedef fusion::fused< test_func<> const > ffc;
66 ffc fused_func_c;
67
68 typedef fusion::fused< test_func<> > const ffc2;
69 ffc2 fused_func_c2;
70
71 typedef fusion::fused< test_func<noncopyable> const & > ffcr;
72 ffcr fused_func_c_ref(f);
73
74 typedef fusion::vector<int,char> vec;
75 vec lv_vec(1,'\004');
76
77 BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ff(vec)>::type, int>));
78 BOOST_TEST(fused_func(lv_vec) == 1);
79 BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffr(vec)>::type, int>));
80 BOOST_TEST(fused_func_c(lv_vec) == 0);
81 BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffc(vec)>::type, int>));
82 BOOST_TEST(fused_func_c2(lv_vec) == 0);
83 BOOST_TEST(fused_func_ref(lv_vec) == 1);
84 BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffcr(vec)>::type, int>));
85 BOOST_TEST(fused_func_c_ref(lv_vec) == 0);
86
87 BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
88 BOOST_TEST(fused_func_c(fusion::make_vector(2,'\003')) == 0);
89 BOOST_TEST(fused_func_c2(fusion::make_vector(2,'\003')) == 0);
90 BOOST_TEST(fused_func_ref(fusion::make_vector(2,'\003')) == 1);
91 BOOST_TEST(fused_func_c_ref(fusion::make_vector(2,'\003')) == 0);
92
93 return boost::report_errors();
94 }
95
96
97
98