]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/functional/unfused_typed.cpp
1 /*=============================================================================
2 Copyright (c) 2006-2007 Tobias Schwinger
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 ==============================================================================*/
9 #include <boost/fusion/functional/adapter/unfused_typed.hpp>
10 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/noncopyable.hpp>
14 #include <boost/mpl/empty_base.hpp>
15 #include <boost/mpl/identity.hpp>
16 #include <boost/mpl/placeholders.hpp>
18 #include <boost/utility/result_of.hpp>
20 #include <boost/fusion/algorithm/iteration/fold.hpp>
22 namespace fusion
= boost::fusion
;
23 namespace mpl
= boost::mpl
;
24 using mpl::placeholders::_
;
26 using boost::noncopyable
;
28 typedef fusion::vector
<> types0
;
29 typedef fusion::vector
<long &> types1
;
30 typedef fusion::vector
<long &,int,char> types3
;
32 template <class Base
= boost::mpl::empty_base
>
39 template <class Self
, class Seq
>
40 struct result
< Self(Seq
) >
44 template <typename Seq
>
45 long operator()(Seq
const & seq
) const
48 return fusion::fold(seq
, state
, fold_op());
51 template < typename Seq
>
52 long operator()(Seq
const & seq
)
55 return fusion::fold(seq
, state
, fold_op());
62 typedef long result_type
;
65 long operator()(long value
, T
const & elem
) const
67 return value
+ sizeof(T
) * elem
;
71 long operator()(long value
, T
& elem
) const
79 void result_type_tests()
83 typedef fusion::unfused_typed
< test_func
<>, types0
> t0
;
84 BOOST_TEST(( is_same
< boost::result_of
< t0 () >::type
, long >::value
));
85 typedef fusion::unfused_typed
< test_func
<>, types1
> t1
;
86 BOOST_TEST(( is_same
< boost::result_of
< t1 (long &) >::type
, long >::value
));
89 #if defined(BOOST_MSVC) && BOOST_MSVC < 1400
90 # define BOOST_TEST_NO_VC71(cond) (void)((cond)?0:1)
92 # define BOOST_TEST_NO_VC71(cond) BOOST_TEST(cond)
97 test_func
<noncopyable
> f
;
98 fusion::unfused_typed
< test_func
<>, types0
> unfused_func
;
99 fusion::unfused_typed
< test_func
<noncopyable
> &, types0
> unfused_func_ref(f
);
100 fusion::unfused_typed
< test_func
<> const, types0
> unfused_func_c
;
101 fusion::unfused_typed
< test_func
<>, types0
> const unfused_func_c2
;
102 fusion::unfused_typed
< test_func
<noncopyable
> const &, types0
> unfused_func_c_ref(f
);
104 BOOST_TEST(unfused_func() == 100);
105 BOOST_TEST(unfused_func_ref() == 100);
106 BOOST_TEST(unfused_func_c() == 0);
107 BOOST_TEST(unfused_func_c2() == 0);
108 BOOST_TEST(unfused_func_c_ref() == 0);
113 test_func
<noncopyable
> f
;
114 fusion::unfused_typed
< test_func
<>, types1
> unfused_func
;
115 fusion::unfused_typed
< test_func
<noncopyable
> &, types1
> unfused_func_ref(f
);
116 fusion::unfused_typed
< test_func
<> const, types1
> unfused_func_c
;
117 fusion::unfused_typed
< test_func
<>, types1
> const unfused_func_c2
;
118 fusion::unfused_typed
< test_func
<noncopyable
> const &, types1
> unfused_func_c_ref(f
);
121 BOOST_TEST_NO_VC71(unfused_func(lvalue
) == 100);
122 BOOST_TEST(lvalue
== 1 + 1*sizeof(lvalue
));
123 BOOST_TEST(unfused_func_ref(lvalue
) == 100);
124 BOOST_TEST(lvalue
== 1 + 2*sizeof(lvalue
));
125 BOOST_TEST(unfused_func_c(lvalue
) == 0);
126 BOOST_TEST(lvalue
== 1 + 3*sizeof(lvalue
));
127 BOOST_TEST(unfused_func_c2(lvalue
) == 0);
128 BOOST_TEST(lvalue
== 1 + 4*sizeof(lvalue
));
129 BOOST_TEST(unfused_func_c_ref(lvalue
) == 0);
130 BOOST_TEST(lvalue
== 1 + 5*sizeof(lvalue
));
135 test_func
<noncopyable
> f
;
136 fusion::unfused_typed
< test_func
<>, types3
> unfused_func
;
137 fusion::unfused_typed
< test_func
<noncopyable
> &, types3
> unfused_func_ref(f
);
138 fusion::unfused_typed
< test_func
<> const, types3
> unfused_func_c
;
139 fusion::unfused_typed
< test_func
<>, types3
> const unfused_func_c2
;
140 fusion::unfused_typed
< test_func
<noncopyable
> const &, types3
> unfused_func_c_ref(f
);
143 static const long expected
= 2*sizeof(int) + 7*sizeof(char);
144 BOOST_TEST_NO_VC71(unfused_func(lvalue
,2,'\007') == 100 + expected
);
145 BOOST_TEST(lvalue
== 1 + 1*sizeof(lvalue
));
146 BOOST_TEST(unfused_func_ref(lvalue
,2,'\007') == 100 + expected
);
147 BOOST_TEST(lvalue
== 1 + 2*sizeof(lvalue
));
148 BOOST_TEST(unfused_func_c(lvalue
,2,'\007') == 0 + expected
);
149 BOOST_TEST(lvalue
== 1 + 3*sizeof(lvalue
));
150 BOOST_TEST(unfused_func_c2(lvalue
,2,'\007') == 0 + expected
);
151 BOOST_TEST(lvalue
== 1 + 4*sizeof(lvalue
));
152 BOOST_TEST(unfused_func_c_ref(lvalue
,2,'\007') == 0 + expected
);
153 BOOST_TEST(lvalue
== 1 + 5*sizeof(lvalue
));
163 return boost::report_errors();