copy.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <string>
  8. #include <boost/detail/lightweight_test.hpp>
  9. #include <boost/fusion/sequence/intrinsic/at.hpp>
  10. #include <boost/fusion/mpl.hpp>
  11. #include <boost/preprocessor/cat.hpp>
  12. #include <boost/mpl/insert_range.hpp>
  13. #include <boost/mpl/vector.hpp>
  14. #include <boost/mpl/begin.hpp>
  15. #include <boost/mpl/equal.hpp>
  16. #include <boost/static_assert.hpp>
  17. #include "fixture.hpp"
  18. #if !defined(FUSION_AT)
  19. #define FUSION_AT at_c
  20. #endif
  21. #if !defined(FUSION_MAKE)
  22. #define FUSION_MAKE BOOST_PP_CAT(make_, FUSION_SEQUENCE)
  23. #endif
  24. #if !defined(FUSION_TIE)
  25. #define FUSION_TIE BOOST_PP_CAT(FUSION_SEQUENCE, _tie)
  26. #endif
  27. namespace test_detail
  28. {
  29. // classes with different kinds of conversions
  30. class AA {};
  31. class BB : public AA {};
  32. struct CC { CC() {} CC(const BB&) {} };
  33. struct DD { operator CC() const { return CC(); }; };
  34. }
  35. void test_mpl()
  36. {
  37. using namespace boost::fusion;
  38. typedef FUSION_SEQUENCE<int, char> seq;
  39. typedef
  40. boost::mpl::insert_range<
  41. boost::mpl::vector<>
  42. , boost::mpl::end< boost::mpl::vector<> >::type
  43. , seq
  44. >::type
  45. sequence;
  46. typedef boost::mpl::equal<sequence, boost::mpl::vector<int, char> > equal;
  47. BOOST_STATIC_ASSERT(equal::value);
  48. }
  49. template <template <typename> class Scenario>
  50. void
  51. test()
  52. {
  53. using namespace boost::fusion;
  54. using namespace test_detail;
  55. FUSION_SEQUENCE<int, char> t1(4, 'a');
  56. FUSION_SEQUENCE<int, char> t2(5, 'b');
  57. t2 = t1;
  58. BOOST_TEST(FUSION_AT<0>(t1) == FUSION_AT<0>(t2));
  59. BOOST_TEST(FUSION_AT<1>(t1) == FUSION_AT<1>(t2));
  60. FUSION_SEQUENCE<long, std::string> t3(2, "a");
  61. t3 = t1;
  62. BOOST_TEST((double)FUSION_AT<0>(t1) == FUSION_AT<0>(t3));
  63. BOOST_TEST(FUSION_AT<1>(t1) == FUSION_AT<1>(t3)[0]);
  64. BOOST_TEST(FUSION_AT<0>(t1) == 4);
  65. BOOST_TEST(FUSION_AT<1>(t1) == 'a');
  66. // testing copy and assignment with implicit conversions
  67. // between elements testing tie
  68. FUSION_SEQUENCE<char, BB*, BB, DD> t;
  69. FUSION_SEQUENCE<int, AA*, CC, CC> a(t);
  70. a = t;
  71. int i; char c; double d;
  72. FUSION_TIE(i, c, d) = FUSION_MAKE(1, 'a', 5.5);
  73. BOOST_TEST(i==1);
  74. BOOST_TEST(c=='a');
  75. BOOST_TEST(d>5.4 && d<5.6);
  76. test_mpl();
  77. BOOST_TEST((run< Scenario< FUSION_SEQUENCE<> > >(FUSION_SEQUENCE<>())));
  78. BOOST_TEST((
  79. run< Scenario< FUSION_SEQUENCE<int> > >(FUSION_SEQUENCE<int>(500))
  80. ));
  81. BOOST_TEST((
  82. run< Scenario< FUSION_SEQUENCE<convertible> > >(
  83. FUSION_SEQUENCE<int>(500)
  84. )
  85. ));
  86. BOOST_TEST((
  87. run< Scenario< FUSION_SEQUENCE<int> > >(
  88. FUSION_SEQUENCE<int, int>(500, 100)
  89. , FUSION_SEQUENCE<int>(500)
  90. )
  91. ));
  92. BOOST_TEST((
  93. run< Scenario< FUSION_SEQUENCE<convertible> > >(
  94. FUSION_SEQUENCE<int, int>(500, 100)
  95. , FUSION_SEQUENCE<convertible>(500)
  96. )
  97. ));
  98. BOOST_TEST((
  99. run< Scenario< FUSION_SEQUENCE<int, int> > >(
  100. FUSION_SEQUENCE<int, int>(500, 600)
  101. )
  102. ));
  103. BOOST_TEST((
  104. run< Scenario< FUSION_SEQUENCE<convertible, int> > >(
  105. FUSION_SEQUENCE<convertible, int>(100, 500)
  106. )
  107. ));
  108. BOOST_TEST((
  109. run< Scenario< FUSION_SEQUENCE<int, convertible> > >(
  110. FUSION_SEQUENCE<int, convertible>(500, 600)
  111. )
  112. ));
  113. BOOST_TEST((
  114. run< Scenario< FUSION_SEQUENCE<convertible, convertible> > >(
  115. FUSION_SEQUENCE<int, int>(400, 500)
  116. )
  117. ));
  118. BOOST_TEST((
  119. run< Scenario< FUSION_SEQUENCE<int, int> > >(
  120. FUSION_SEQUENCE<int, int, int>(500, 100, 323)
  121. , FUSION_SEQUENCE<int, int>(500, 100)
  122. )
  123. ));
  124. BOOST_TEST((
  125. run< Scenario< FUSION_SEQUENCE<convertible, convertible> > >(
  126. FUSION_SEQUENCE<int, int, int>(500, 600, 100)
  127. , FUSION_SEQUENCE<convertible, convertible>(500, 600)
  128. )
  129. ));
  130. }