front_extended_deque.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*=============================================================================
  2. Copyright (c) 1999-2003 Jaakko Jarvi
  3. Copyright (c) 2001-2011 Joel de Guzman
  4. Copyright (c) 2006 Dan Marsden
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #include <boost/detail/lightweight_test.hpp>
  9. #include <boost/fusion/container/deque/deque.hpp>
  10. #include <boost/fusion/container/deque/front_extended_deque.hpp>
  11. #include <boost/fusion/sequence/comparison.hpp>
  12. #include <boost/fusion/container/generation/make_vector.hpp>
  13. #include <boost/fusion/mpl.hpp>
  14. #include <boost/fusion/sequence/intrinsic.hpp>
  15. #include <boost/fusion/iterator.hpp>
  16. #include <boost/mpl/assert.hpp>
  17. #include <boost/type_traits/is_same.hpp>
  18. int main()
  19. {
  20. using namespace boost::fusion;
  21. {
  22. typedef deque<> initial_deque_type;
  23. initial_deque_type initial_deque;
  24. typedef front_extended_deque<initial_deque_type, int> extended_type;
  25. extended_type extended(initial_deque, 1);
  26. BOOST_TEST(size(extended) == 1);
  27. BOOST_TEST(extended == make_vector(1));
  28. BOOST_TEST(*begin(extended) == 1);
  29. BOOST_TEST(*prior(end(extended)) == 1);
  30. BOOST_TEST(distance(begin(extended), end(extended)) == 1);
  31. }
  32. {
  33. namespace mpl = boost::mpl;
  34. typedef deque<> initial_deque_type;
  35. typedef front_extended_deque<initial_deque_type, int> extended_type;
  36. BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 0>::type, int>));
  37. BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, int>));
  38. BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<1> >));
  39. }
  40. {
  41. int i(1);
  42. typedef deque<> initial_deque_type;
  43. initial_deque_type initial_deque;
  44. typedef front_extended_deque<initial_deque_type, int&> extended_type;
  45. extended_type extended(initial_deque, i);
  46. BOOST_TEST(extended == make_vector(1));
  47. int i2(2);
  48. extended_type extended2(initial_deque_type(), i2);
  49. extended = extended2;
  50. BOOST_TEST(extended == make_vector(2));
  51. BOOST_TEST(i == i2);
  52. }
  53. {
  54. typedef deque<char, long> initial_deque_type;
  55. initial_deque_type initial_deque('a', 101L);
  56. typedef front_extended_deque<initial_deque_type, int> extended_type;
  57. extended_type extended(initial_deque, 1);
  58. BOOST_TEST(size(extended) == 3);
  59. BOOST_TEST(extended == make_vector(1, 'a', 101L));
  60. BOOST_TEST(*begin(extended) == 1);
  61. BOOST_TEST(*next(begin(extended)) == 'a');
  62. BOOST_TEST(*prior(end(extended)) == 101L);
  63. BOOST_TEST(distance(begin(extended), end(extended)) == 3);
  64. BOOST_TEST(*advance_c<2>(begin(extended)) == 101L);
  65. }
  66. {
  67. namespace mpl = boost::mpl;
  68. typedef deque<char, long> initial_deque_type;
  69. typedef front_extended_deque<initial_deque_type, int> extended_type;
  70. BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 0>::type, int>));
  71. BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 1>::type, char>));
  72. BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 2>::type, long>));
  73. BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, int>));
  74. BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<3> >));
  75. }
  76. {
  77. char ch('a');
  78. long l(101L);
  79. int i(1);
  80. typedef deque<char&, long&> initial_deque_type;
  81. initial_deque_type initial_deque(ch, l);
  82. typedef front_extended_deque<initial_deque_type, int&> extended_type;
  83. extended_type extended(initial_deque, i);
  84. BOOST_TEST(extended == make_vector(1, 'a', 101L));
  85. char ch2('b');
  86. long l2(202L);
  87. int i2(2);
  88. extended_type extended2(initial_deque_type(ch2, l2), i2);
  89. extended = extended2;
  90. BOOST_TEST(extended == make_vector(2, 'b', 202L));
  91. BOOST_TEST(i == i2);
  92. BOOST_TEST(ch == ch2);
  93. BOOST_TEST(l == l2);
  94. }
  95. return boost::report_errors();
  96. }