make_fused.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*=============================================================================
  2. Copyright (c) 2006-2007 Tobias Schwinger
  3. Use modification and distribution are subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ==============================================================================*/
  7. #include <boost/fusion/functional/generation/make_fused.hpp>
  8. #include <boost/detail/lightweight_test.hpp>
  9. #include <boost/noncopyable.hpp>
  10. #include <boost/mpl/empty_base.hpp>
  11. #include <boost/fusion/container/generation/make_vector.hpp>
  12. #include <boost/fusion/container/vector.hpp>
  13. namespace fusion = boost::fusion;
  14. using boost::noncopyable;
  15. using boost::cref;
  16. using boost::ref;
  17. template <class Base = boost::mpl::empty_base>
  18. struct test_func
  19. : Base
  20. {
  21. typedef int result_type;
  22. template <typename T0, typename T1>
  23. int operator()(T0 const & x, T1 const & y) const
  24. {
  25. return 1+x-y;
  26. }
  27. template <typename T0, typename T1>
  28. int operator()(T0 const & x, T1 const & y)
  29. {
  30. return 2+x-y;
  31. }
  32. template <typename T0, typename T1>
  33. int operator()(T0 & x, T1 & y) const
  34. {
  35. return 3+x-y;
  36. }
  37. template <typename T0, typename T1>
  38. int operator()(T0 & x, T1 & y)
  39. {
  40. return 4+x-y;
  41. }
  42. };
  43. template <typename T>
  44. inline T const & const_(T const & t)
  45. {
  46. return t;
  47. }
  48. int main()
  49. {
  50. fusion::vector<int,char> lv_vec(1,'\004');
  51. test_func<> f;
  52. test_func<noncopyable> f_nc;
  53. boost::fusion::result_of::make_fused< test_func<> >::type fused_func
  54. = fusion::make_fused(f);
  55. BOOST_TEST(fused_func(lv_vec) == 1);
  56. BOOST_TEST(const_(fused_func)(lv_vec) == 0);
  57. BOOST_TEST(fusion::make_fused(const_(f))(lv_vec) == 1);
  58. BOOST_TEST(fusion::make_fused(ref(f_nc))(lv_vec) == 1);
  59. BOOST_TEST(fusion::make_fused(cref(f_nc))(lv_vec) == 0);
  60. BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
  61. BOOST_TEST(const_(fused_func)(fusion::make_vector(2,'\003')) == 0);
  62. BOOST_TEST(fusion::make_fused(const_(f))(fusion::make_vector(2,'\003')) == 1);
  63. BOOST_TEST(fusion::make_fused(ref(f_nc))(fusion::make_vector(2,'\003')) == 1);
  64. BOOST_TEST(fusion::make_fused(cref(f_nc))(fusion::make_vector(2,'\003')) == 0);
  65. return boost::report_errors();
  66. }