static_vector_test.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Boost.Container static_vector
  2. // Unit Test
  3. // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
  4. // Copyright (c) 2012-2013 Andrew Hundt.
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP
  9. #define BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP
  10. #include <boost/container/static_vector.hpp>
  11. #define BOOST_SP_DISABLE_THREADS
  12. #include <boost/shared_ptr.hpp>
  13. #include "movable_int.hpp"
  14. using namespace boost::container;
  15. class value_ndc
  16. {
  17. public:
  18. explicit value_ndc(int a) : aa(a) {}
  19. ~value_ndc() {}
  20. bool operator==(value_ndc const& v) const { return aa == v.aa; }
  21. bool operator<(value_ndc const& v) const { return aa < v.aa; }
  22. private:
  23. value_ndc(value_ndc const&) {}
  24. value_ndc & operator=(value_ndc const&) { return *this; }
  25. int aa;
  26. };
  27. class value_nd
  28. {
  29. public:
  30. explicit value_nd(int a) : aa(a) {}
  31. ~value_nd() {}
  32. bool operator==(value_nd const& v) const { return aa == v.aa; }
  33. bool operator<(value_nd const& v) const { return aa < v.aa; }
  34. private:
  35. int aa;
  36. };
  37. class value_nc
  38. {
  39. public:
  40. explicit value_nc(int a = 0) : aa(a) {}
  41. ~value_nc() {}
  42. bool operator==(value_nc const& v) const { return aa == v.aa; }
  43. bool operator<(value_nc const& v) const { return aa < v.aa; }
  44. private:
  45. value_nc(value_nc const&) {}
  46. value_nc & operator=(value_ndc const&) { return *this; }
  47. int aa;
  48. };
  49. class counting_value
  50. {
  51. BOOST_COPYABLE_AND_MOVABLE(counting_value)
  52. public:
  53. explicit counting_value(int a = 0, int b = 0) : aa(a), bb(b) { ++c(); }
  54. counting_value(counting_value const& v) : aa(v.aa), bb(v.bb) { ++c(); }
  55. counting_value(BOOST_RV_REF(counting_value) p) : aa(p.aa), bb(p.bb) { p.aa = 0; p.bb = 0; ++c(); } // Move constructor
  56. counting_value& operator=(BOOST_RV_REF(counting_value) p) { aa = p.aa; p.aa = 0; bb = p.bb; p.bb = 0; return *this; } // Move assignment
  57. counting_value& operator=(BOOST_COPY_ASSIGN_REF(counting_value) p) { aa = p.aa; bb = p.bb; return *this; } // Copy assignment
  58. ~counting_value() { --c(); }
  59. bool operator==(counting_value const& v) const { return aa == v.aa && bb == v.bb; }
  60. bool operator<(counting_value const& v) const { return aa < v.aa || ( aa == v.aa && bb < v.bb ); }
  61. static size_t count() { return c(); }
  62. private:
  63. static size_t & c() { static size_t co = 0; return co; }
  64. int aa, bb;
  65. };
  66. namespace boost {
  67. template <class T>
  68. struct has_nothrow_move;
  69. template <>
  70. struct has_nothrow_move<counting_value>
  71. {
  72. static const bool value = true;
  73. };
  74. }
  75. class shptr_value
  76. {
  77. typedef boost::shared_ptr<int> Ptr;
  78. public:
  79. explicit shptr_value(int a = 0) : m_ptr(new int(a)) {}
  80. bool operator==(shptr_value const& v) const { return *m_ptr == *(v.m_ptr); }
  81. bool operator<(shptr_value const& v) const { return *m_ptr < *(v.m_ptr); }
  82. private:
  83. boost::shared_ptr<int> m_ptr;
  84. };
  85. #endif // BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP