Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53648 - in trunk: boost/lambda/detail libs/lambda/test
From: steven_at_[hidden]
Date: 2009-06-04 21:20:07


Author: steven_watanabe
Date: 2009-06-04 21:20:06 EDT (Thu, 04 Jun 2009)
New Revision: 53648
URL: http://svn.boost.org/trac/boost/changeset/53648

Log:
Add result_type to lambda::ret. Fixes #1222
Added:
   trunk/libs/lambda/test/ret_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/lambda/detail/lambda_functor_base.hpp | 2 ++
   trunk/libs/lambda/test/Jamfile | 1 +
   2 files changed, 3 insertions(+), 0 deletions(-)

Modified: trunk/boost/lambda/detail/lambda_functor_base.hpp
==============================================================================
--- trunk/boost/lambda/detail/lambda_functor_base.hpp (original)
+++ trunk/boost/lambda/detail/lambda_functor_base.hpp 2009-06-04 21:20:06 EDT (Thu, 04 Jun 2009)
@@ -270,6 +270,8 @@
 public:
   Args args;
 
+ typedef RET result_type;
+
   explicit lambda_functor_base(const Args& a) : args(a) {}
 
   template <class SigArgs> struct sig { typedef RET type; };

Modified: trunk/libs/lambda/test/Jamfile
==============================================================================
--- trunk/libs/lambda/test/Jamfile (original)
+++ trunk/libs/lambda/test/Jamfile 2009-06-04 21:20:06 EDT (Thu, 04 Jun 2009)
@@ -30,4 +30,5 @@
     [ run operator_tests_simple.cpp ]
     [ run phoenix_control_structures.cpp ]
     [ run switch_construct.cpp ]
+ [ run ret_test.cpp ]
   ;

Added: trunk/libs/lambda/test/ret_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/lambda/test/ret_test.cpp 2009-06-04 21:20:06 EDT (Thu, 04 Jun 2009)
@@ -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 <boost/test/minimal.hpp>
+
+#include <boost/lambda/lambda.hpp>
+
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+template<class R, class F>
+void test_ret(R r, F f) {
+ typename F::result_type x = f();
+ BOOST_MPL_ASSERT((boost::is_same<R, typename F::result_type>));
+ BOOST_CHECK(x == r);
+}
+
+template<class R, class F, class T1>
+void test_ret(R r, F f, T1& t1) {
+ typename F::result_type x = f(t1);
+ BOOST_MPL_ASSERT((boost::is_same<R, typename F::result_type>));
+ 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<add_result>(boost::lambda::_1 + test), test);
+ test_ret(8.0, boost::lambda::ret<double>(boost::lambda::constant(7) + 1));
+
+ return 0;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk