]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // ret_test.cpp - The Boost Lambda Library ----------------------- |
2 | // | |
3 | // Copyright (C) 2009 Steven Watanabe | |
4 | // | |
5 | // Distributed under the Boost Software License, Version 1.0. (See | |
6 | // accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | // | |
9 | // For more information, see www.boost.org | |
10 | ||
1e59de90 TL |
11 | #include <boost/core/lightweight_test.hpp> |
12 | #define BOOST_CHECK BOOST_TEST | |
7c673cae FG |
13 | |
14 | #include <boost/lambda/lambda.hpp> | |
15 | ||
16 | #include <boost/mpl/assert.hpp> | |
17 | #include <boost/type_traits/is_same.hpp> | |
18 | ||
19 | template<class R, class F> | |
20 | void test_ret(R r, F f) { | |
21 | typename F::result_type x = f(); | |
22 | BOOST_MPL_ASSERT((boost::is_same<R, typename F::result_type>)); | |
23 | BOOST_CHECK(x == r); | |
24 | } | |
25 | ||
26 | template<class R, class F, class T1> | |
27 | void test_ret(R r, F f, T1& t1) { | |
28 | typename F::result_type x = f(t1); | |
29 | BOOST_MPL_ASSERT((boost::is_same<R, typename F::result_type>)); | |
30 | BOOST_CHECK(x == r); | |
31 | } | |
32 | ||
33 | class add_result { | |
34 | public: | |
35 | add_result(int i = 0) : value(i) {} | |
36 | friend bool operator==(const add_result& lhs, const add_result& rhs) { | |
37 | return(lhs.value == rhs.value); | |
38 | } | |
39 | private: | |
40 | int value; | |
41 | }; | |
42 | ||
43 | class addable {}; | |
44 | add_result operator+(addable, addable) { | |
45 | return add_result(7); | |
46 | } | |
47 | ||
1e59de90 | 48 | int main() { |
7c673cae FG |
49 | addable test; |
50 | test_ret(add_result(7), boost::lambda::ret<add_result>(boost::lambda::_1 + test), test); | |
51 | test_ret(8.0, boost::lambda::ret<double>(boost::lambda::constant(7) + 1)); | |
52 | ||
1e59de90 | 53 | return boost::report_errors(); |
7c673cae | 54 | } |