• 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.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     typedef int result_type;
28 
29     template <typename T0, typename T1>
operator ()test_func30     int operator()(T0 const & x, T1 const & y) const
31     {
32         return 1+x-y;
33     }
34 
35     template <typename T0, typename T1>
operator ()test_func36     int operator()(T0 const & x, T1 const & y)
37     {
38         return 2+x-y;
39     }
40 
41     template <typename T0, typename T1>
operator ()test_func42     int operator()(T0 & x, T1 & y) const
43     {
44         return 3+x-y;
45     }
46 
47     template <typename T0, typename T1>
operator ()test_func48     int operator()(T0 & x, T1 & y)
49     {
50         return 4+x-y;
51     }
52 };
53 
54 template <typename T>
const_(T const & t)55 inline T const & const_(T const & t)
56 {
57     return t;
58 }
59 
main()60 int main()
61 {
62     fusion::vector<int,char> lv_vec(1,'\004');
63     test_func<> f;
64     test_func<noncopyable> f_nc;
65 
66     boost::fusion::result_of::make_fused< test_func<> >::type fused_func
67         = fusion::make_fused(f);
68 
69     BOOST_TEST(fused_func(lv_vec) == 1);
70     BOOST_TEST(const_(fused_func)(lv_vec) == 0);
71     BOOST_TEST(fusion::make_fused(const_(f))(lv_vec) == 1);
72     BOOST_TEST(fusion::make_fused(ref(f_nc))(lv_vec) == 1);
73     BOOST_TEST(fusion::make_fused(cref(f_nc))(lv_vec) == 0);
74 
75     BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
76     BOOST_TEST(const_(fused_func)(fusion::make_vector(2,'\003')) == 0);
77     BOOST_TEST(fusion::make_fused(const_(f))(fusion::make_vector(2,'\003')) == 1);
78     BOOST_TEST(fusion::make_fused(ref(f_nc))(fusion::make_vector(2,'\003')) == 1);
79     BOOST_TEST(fusion::make_fused(cref(f_nc))(fusion::make_vector(2,'\003')) == 0);
80 
81     return boost::report_errors();
82 }
83 
84 
85 
86