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/core/lightweight_test.hpp>
12#define BOOST_CHECK BOOST_TEST
13
14#include <boost/lambda/lambda.hpp>
15
16#include <boost/mpl/assert.hpp>
17#include <boost/type_traits/is_same.hpp>
18
19template<class R, class F>
20void 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
26template<class R, class F, class T1>
27void 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
33class add_result {
34public:
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 }
39private:
40 int value;
41};
42
43class addable {};
44add_result operator+(addable, addable) {
45 return add_result(7);
46}
47
48int main() {
49 addable test;
50 test_ret(r: add_result(7), f: boost::lambda::ret<add_result>(a1: boost::lambda::_1 + test), t1&: test);
51 test_ret(r: 8.0, f: boost::lambda::ret<double>(a1: boost::lambda::constant(t: 7) + 1));
52
53 return boost::report_errors();
54}
55

source code of boost/libs/lambda/test/ret_test.cpp