ret_test.cpp 1.4 KB

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