make.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*=============================================================================
  2. Copyright (c) 1999-2003 Jaakko Jarvi
  3. Copyright (c) 2001-2011 Joel de Guzman
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #include <boost/detail/lightweight_test.hpp>
  8. #include <boost/fusion/sequence/intrinsic/at.hpp>
  9. #include <boost/fusion/sequence/comparison/equal_to.hpp>
  10. #include <string>
  11. #if !defined(FUSION_AT)
  12. #define FUSION_AT at_c
  13. #endif
  14. #if !defined(FUSION_MAKE)
  15. #define FUSION_MAKE BOOST_PP_CAT(make_, FUSION_SEQUENCE)
  16. #endif
  17. namespace test_detail
  18. {
  19. // something to prevent warnings for unused variables
  20. template<class T> void dummy(const T&) {}
  21. class A {};
  22. class B {};
  23. }
  24. void make_tuple_test() {}
  25. void
  26. test()
  27. {
  28. using namespace boost::fusion;
  29. using namespace test_detail;
  30. {
  31. FUSION_SEQUENCE<int, char> t1 = FUSION_MAKE(5, 'a');
  32. BOOST_TEST(FUSION_AT<0>(t1) == 5);
  33. BOOST_TEST(FUSION_AT<1>(t1) == 'a');
  34. FUSION_SEQUENCE<int, std::string> t2;
  35. t2 = FUSION_MAKE((short int)2, std::string("Hi"));
  36. BOOST_TEST(FUSION_AT<0>(t2) == 2);
  37. BOOST_TEST(FUSION_AT<1>(t2) == "Hi");
  38. }
  39. { // This test was previously disallowed for non-PTS compilers.
  40. A a = A(); B b;
  41. const A ca = a;
  42. FUSION_MAKE(boost::cref(a), b);
  43. FUSION_MAKE(boost::ref(a), b);
  44. FUSION_MAKE(boost::ref(a), boost::cref(b));
  45. FUSION_MAKE(boost::ref(ca));
  46. }
  47. { // the result of make_xxx is assignable:
  48. BOOST_TEST(FUSION_MAKE(2, 4, 6) ==
  49. (FUSION_MAKE(1, 2, 3) = FUSION_MAKE(2, 4, 6)));
  50. }
  51. { // This test was previously disallowed for non-PTS compilers.
  52. FUSION_MAKE("Donald", "Daisy"); // should work;
  53. // std::make_pair("Doesn't","Work"); // fails
  54. }
  55. {
  56. // You can store a reference to a function in a sequence
  57. FUSION_SEQUENCE<void(&)()> adf(make_tuple_test);
  58. dummy(adf); // avoid warning for unused variable
  59. }
  60. #if defined(FUSION_TEST_FAIL)
  61. {
  62. // But make_xxx doesn't work
  63. // with function references, since it creates a const
  64. // qualified function type
  65. FUSION_MAKE(make_tuple_test);
  66. }
  67. #endif
  68. {
  69. // With function pointers, make_xxx works just fine
  70. FUSION_MAKE(&make_tuple_test);
  71. }
  72. }