From 41eb864595ee66f6cdaeeed64460cdfc858dd2a4 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Fri, 5 Jun 2009 01:20:06 +0000 Subject: [PATCH] Add result_type to lambda::ret. Fixes #1222 [SVN r53648] --- .../lambda/detail/lambda_functor_base.hpp | 2 + test/Jamfile | 1 + test/ret_test.cpp | 53 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 test/ret_test.cpp diff --git a/include/boost/lambda/detail/lambda_functor_base.hpp b/include/boost/lambda/detail/lambda_functor_base.hpp index 6a43c14..e5bb02a 100644 --- a/include/boost/lambda/detail/lambda_functor_base.hpp +++ b/include/boost/lambda/detail/lambda_functor_base.hpp @@ -270,6 +270,8 @@ class lambda_functor_base, Args> public: Args args; + typedef RET result_type; + explicit lambda_functor_base(const Args& a) : args(a) {} template struct sig { typedef RET type; }; diff --git a/test/Jamfile b/test/Jamfile index 99a9757..4080eb3 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -30,4 +30,5 @@ test-suite lambda [ run operator_tests_simple.cpp ] [ run phoenix_control_structures.cpp ] [ run switch_construct.cpp ] + [ run ret_test.cpp ] ; diff --git a/test/ret_test.cpp b/test/ret_test.cpp new file mode 100644 index 0000000..82c947f --- /dev/null +++ b/test/ret_test.cpp @@ -0,0 +1,53 @@ +// ret_test.cpp - The Boost Lambda Library ----------------------- +// +// Copyright (C) 2009 Steven Watanabe +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// For more information, see www.boost.org + +#include + +#include + +#include +#include + +template +void test_ret(R r, F f) { + typename F::result_type x = f(); + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_CHECK(x == r); +} + +template +void test_ret(R r, F f, T1& t1) { + typename F::result_type x = f(t1); + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_CHECK(x == r); +} + +class add_result { +public: + add_result(int i = 0) : value(i) {} + friend bool operator==(const add_result& lhs, const add_result& rhs) { + return(lhs.value == rhs.value); + } +private: + int value; +}; + +class addable {}; +add_result operator+(addable, addable) { + return add_result(7); +} + +int test_main(int, char*[]) { + addable test; + test_ret(add_result(7), boost::lambda::ret(boost::lambda::_1 + test), test); + test_ret(8.0, boost::lambda::ret(boost::lambda::constant(7) + 1)); + + return 0; +}