fused_procedure.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/adapter/fused_procedure.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. int effect;
  16. #define CHECK_EFFECT(t,e) \
  17. { \
  18. effect = 1234567; t; \
  19. BOOST_TEST(effect == e); \
  20. }
  21. template <class Base = boost::mpl::empty_base>
  22. struct test_func
  23. : Base
  24. {
  25. template <typename T0, typename T1>
  26. int operator()(T0 const & x, T1 const & y) const
  27. {
  28. return effect = 1+x-y;
  29. }
  30. template <typename T0, typename T1>
  31. int operator()(T0 const & x, T1 const & y)
  32. {
  33. return effect = 2+x-y;
  34. }
  35. template <typename T0, typename T1>
  36. int operator()(T0 & x, T1 & y) const
  37. {
  38. return effect = 3+x-y;
  39. }
  40. template <typename T0, typename T1>
  41. int operator()(T0 & x, T1 & y)
  42. {
  43. return effect = 4+x-y;
  44. }
  45. };
  46. int main()
  47. {
  48. test_func<noncopyable> f;
  49. fusion::fused_procedure< test_func<> > fused_proc;
  50. fusion::fused_procedure< test_func<noncopyable> & > fused_proc_ref(f);
  51. fusion::fused_procedure< test_func<> const > fused_proc_c;
  52. fusion::fused_procedure< test_func<> > const fused_proc_c2;
  53. fusion::fused_procedure< test_func<noncopyable> const & > fused_proc_c_ref(f);
  54. fusion::vector<int,char> lv_vec(1,'\004');
  55. CHECK_EFFECT(fused_proc(lv_vec), 1);
  56. CHECK_EFFECT(fused_proc_c(lv_vec), 0);
  57. CHECK_EFFECT(fused_proc_c2(lv_vec), 0);
  58. CHECK_EFFECT(fused_proc_ref(lv_vec), 1);
  59. CHECK_EFFECT(fused_proc_c_ref(lv_vec), 0);
  60. CHECK_EFFECT(fused_proc(fusion::make_vector(2,'\003')), 1);
  61. CHECK_EFFECT(fused_proc_c(fusion::make_vector(2,'\003')), 0);
  62. CHECK_EFFECT(fused_proc_c2(fusion::make_vector(2,'\003')), 0);
  63. CHECK_EFFECT(fused_proc_ref(fusion::make_vector(2,'\003')), 1);
  64. CHECK_EFFECT(fused_proc_c_ref(fusion::make_vector(2,'\003')), 0);
  65. return boost::report_errors();
  66. }