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
11 #include <boost/test/minimal.hpp>
12
13 #include <boost/lambda/lambda.hpp>
14
15 #include <boost/mpl/assert.hpp>
16 #include <boost/type_traits/is_same.hpp>
17
18 template<class R, class F>
test_ret(R r,F f)19 void test_ret(R r, F f) {
20 typename F::result_type x = f();
21 BOOST_MPL_ASSERT((boost::is_same<R, typename F::result_type>));
22 BOOST_CHECK(x == r);
23 }
24
25 template<class R, class F, class T1>
test_ret(R r,F f,T1 & t1)26 void test_ret(R r, F f, T1& t1) {
27 typename F::result_type x = f(t1);
28 BOOST_MPL_ASSERT((boost::is_same<R, typename F::result_type>));
29 BOOST_CHECK(x == r);
30 }
31
32 class add_result {
33 public:
add_result(int i=0)34 add_result(int i = 0) : value(i) {}
operator ==(const add_result & lhs,const add_result & rhs)35 friend bool operator==(const add_result& lhs, const add_result& rhs) {
36 return(lhs.value == rhs.value);
37 }
38 private:
39 int value;
40 };
41
42 class addable {};
operator +(addable,addable)43 add_result operator+(addable, addable) {
44 return add_result(7);
45 }
46
test_main(int,char * [])47 int test_main(int, char*[]) {
48 addable test;
49 test_ret(add_result(7), boost::lambda::ret<add_result>(boost::lambda::_1 + test), test);
50 test_ret(8.0, boost::lambda::ret<double>(boost::lambda::constant(7) + 1));
51
52 return 0;
53 }
54