deduce_sequence.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*=============================================================================
  2. Copyright (c) 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/config.hpp>
  8. #include <boost/fusion/support/deduce_sequence.hpp>
  9. #include <boost/fusion/mpl.hpp>
  10. #include <boost/detail/lightweight_test.hpp>
  11. #include <boost/mpl/equal.hpp>
  12. #include <boost/ref.hpp>
  13. #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
  14. #include <functional>
  15. #endif
  16. using boost::is_same;
  17. using boost::reference_wrapper;
  18. using boost::fusion::traits::deduce;
  19. using boost::fusion::traits::deduce_sequence;
  20. namespace fusion = boost::fusion;
  21. template <class Args>
  22. struct test_seq_ctor
  23. {
  24. typename deduce_sequence<Args>::type fsq_args;
  25. test_seq_ctor(Args const & args)
  26. : fsq_args(args)
  27. { }
  28. };
  29. #define TEST_SAME_TYPE(a,b) BOOST_TEST(( is_same< a, b >::value ))
  30. #define TEST_SAME_ELEMENTS(a,b) BOOST_TEST(( boost::mpl::equal< a, b >::type::value ))
  31. typedef fusion::vector<int, int const, int &, int const &> args1;
  32. typedef fusion::vector<int, int, int &, int> storable1;
  33. template struct test_seq_ctor<args1>;
  34. typedef fusion::vector< reference_wrapper<int> &, reference_wrapper<int const> &,
  35. reference_wrapper<int> const &, reference_wrapper<int const> const & > args2;
  36. typedef fusion::vector<int &, int const &, int &, int const &> storable2;
  37. template struct test_seq_ctor<args2>;
  38. typedef fusion::vector<int *, int const *, int const * const, int const * &, int const * const &> args3;
  39. typedef fusion::vector<int *, int const *, int const *, int const * &, int const * > storable3;
  40. template struct test_seq_ctor<args3>;
  41. typedef fusion::vector<int(&)[2], int const(&)[2]> args4;
  42. typedef args4 storable4;
  43. template struct test_seq_ctor<args4>;
  44. int main()
  45. {
  46. TEST_SAME_TYPE(deduce<int &>::type, int &);
  47. TEST_SAME_TYPE(deduce<int volatile &>::type, int volatile &);
  48. TEST_SAME_TYPE(deduce<int>::type, int);
  49. TEST_SAME_TYPE(deduce<int const &>::type, int);
  50. TEST_SAME_TYPE(deduce<int const volatile &>::type, int);
  51. TEST_SAME_TYPE(deduce< reference_wrapper<int> & >::type, int &);
  52. TEST_SAME_TYPE(deduce< reference_wrapper<int const> & >::type, int const &);
  53. TEST_SAME_TYPE(deduce< reference_wrapper<int> const & >::type, int &);
  54. TEST_SAME_TYPE(deduce< reference_wrapper<int const> const & >::type, int const &);
  55. #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
  56. TEST_SAME_TYPE(deduce< std::reference_wrapper<int> & >::type, int &);
  57. TEST_SAME_TYPE(deduce< std::reference_wrapper<int const> & >::type, int const &);
  58. TEST_SAME_TYPE(deduce< std::reference_wrapper<int> const & >::type, int &);
  59. TEST_SAME_TYPE(deduce< std::reference_wrapper<int const> const & >::type, int const &);
  60. #endif
  61. TEST_SAME_TYPE(deduce< int(&)[2] >::type, int(&)[2]);
  62. TEST_SAME_TYPE(deduce< int const (&)[2] >::type, int const (&)[2]);
  63. TEST_SAME_TYPE(deduce< int volatile (&)[2] >::type, int volatile (&)[2]);
  64. TEST_SAME_TYPE(deduce< int const volatile (&)[2] >::type, int const volatile (&)[2]);
  65. TEST_SAME_ELEMENTS(deduce_sequence<args1>::type,storable1);
  66. TEST_SAME_ELEMENTS(deduce_sequence<args2>::type,storable2);
  67. TEST_SAME_ELEMENTS(deduce_sequence<args3>::type,storable3);
  68. TEST_SAME_ELEMENTS(deduce_sequence<args4>::type,storable4);
  69. return boost::report_errors();
  70. }