test_emplacement.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright 2016 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/poly_collection for library home page.
  7. */
  8. #include "test_emplacement.hpp"
  9. #include <boost/core/lightweight_test.hpp>
  10. #include "any_types.hpp"
  11. #include "base_types.hpp"
  12. #include "function_types.hpp"
  13. #include "test_utilities.hpp"
  14. using namespace test_utilities;
  15. template<typename PolyCollection,typename ValueFactory,typename... Types>
  16. void test_emplacement()
  17. {
  18. {
  19. using type=first_of<
  20. constraints<
  21. is_constructible_from_int,is_not_copy_constructible,
  22. is_not_copy_assignable,
  23. is_equality_comparable
  24. >,
  25. Types...
  26. >;
  27. using iterator=typename PolyCollection::iterator;
  28. using local_base_iterator=typename PolyCollection::local_base_iterator;
  29. using local_iterator=
  30. typename PolyCollection::template local_iterator<type>;
  31. PolyCollection p;
  32. iterator it=p.template emplace<type>(4);
  33. BOOST_TEST(*p.template begin<type>()==type{4});
  34. BOOST_TEST(&*it==&*p.begin(typeid(type)));
  35. iterator it2=p.template emplace_hint<type>(it,3);
  36. BOOST_TEST(*p.template begin<type>()==type{3});
  37. BOOST_TEST(&*it2==&*p.begin(typeid(type)));
  38. iterator it3=p.template emplace_hint<type>(p.cend(),5);
  39. BOOST_TEST(*(p.template end<type>()-1)==type{5});
  40. BOOST_TEST(&*it3==&*(p.end(typeid(type))-1));
  41. local_base_iterator lbit=
  42. p.template emplace_pos<type>(p.begin(typeid(type)),2);
  43. BOOST_TEST(*static_cast<local_iterator>(lbit)==type{2});
  44. BOOST_TEST(lbit==p.begin(typeid(type)));
  45. local_base_iterator lbit2=
  46. p.template emplace_pos<type>(p.cend(typeid(type)),6);
  47. BOOST_TEST(*static_cast<local_iterator>(lbit2)==type{6});
  48. BOOST_TEST(lbit2==p.end(typeid(type))-1);
  49. local_iterator lit=p.emplace_pos(p.template begin<type>(),1);
  50. BOOST_TEST(*lit==type{1});
  51. BOOST_TEST(lit==p.template begin<type>());
  52. local_iterator lit2=p.emplace_pos(p.template cend<type>(),7);
  53. BOOST_TEST(*lit2==type{7});
  54. BOOST_TEST(lit2==p.template end<type>()-1);
  55. }
  56. {
  57. using type=first_of<
  58. constraints<is_default_constructible>,
  59. Types...
  60. >;
  61. PolyCollection p;
  62. p.template emplace<type>();
  63. p.template emplace_hint<type>(p.begin());
  64. p.template emplace_hint<type>(p.cend());
  65. p.template emplace_pos<type>(p.begin(typeid(type)));
  66. p.template emplace_pos<type>(p.cend(typeid(type)));
  67. p.emplace_pos(p.template begin<type>());
  68. p.emplace_pos(p.template cend<type>());
  69. BOOST_TEST(p.size()==7);
  70. }
  71. {
  72. using type=first_of<
  73. constraints<is_not_copy_constructible>,
  74. Types...
  75. >;
  76. PolyCollection p;
  77. ValueFactory v;
  78. p.template emplace<type>(v.template make<type>());
  79. p.template emplace_hint<type>(p.begin(),v.template make<type>());
  80. p.template emplace_hint<type>(p.cend(),v.template make<type>());
  81. p.template emplace_pos<type>(
  82. p.begin(typeid(type)),v.template make<type>());
  83. p.template emplace_pos<type>(
  84. p.cend(typeid(type)),v.template make<type>());
  85. p.emplace_pos(p.template begin<type>(),v.template make<type>());
  86. p.emplace_pos(p.template cend<type>(),v.template make<type>());
  87. BOOST_TEST(p.size()==7);
  88. }
  89. }
  90. void test_emplacement()
  91. {
  92. test_emplacement<
  93. any_types::collection,auto_increment,
  94. any_types::t1,any_types::t2,any_types::t3,
  95. any_types::t4,any_types::t5>();
  96. test_emplacement<
  97. base_types::collection,auto_increment,
  98. base_types::t1,base_types::t2,base_types::t3,
  99. base_types::t4,base_types::t5>();
  100. test_emplacement<
  101. function_types::collection,auto_increment,
  102. function_types::t1,function_types::t2,function_types::t3,
  103. function_types::t4,function_types::t5>();
  104. }