container_common_tests.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
  11. #define BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
  12. #include <boost/container/detail/config_begin.hpp>
  13. namespace boost{
  14. namespace container {
  15. namespace test{
  16. template<class Container>
  17. const Container &as_const(Container &c)
  18. { return c; }
  19. //nth, index_of
  20. template<class Container>
  21. bool test_nth_index_of(Container &c)
  22. {
  23. typename Container::iterator it;
  24. typename Container::const_iterator cit;
  25. typename Container::size_type sz, csz;
  26. //index 0
  27. it = c.nth(0);
  28. sz = c.index_of(it);
  29. cit = (as_const)(c).nth(0);
  30. csz = (as_const)(c).index_of(cit);
  31. if(it != c.begin())
  32. return false;
  33. if(cit != c.cbegin())
  34. return false;
  35. if(sz != 0)
  36. return false;
  37. if(csz != 0)
  38. return false;
  39. //index size()/2
  40. const typename Container::size_type sz_div_2 = c.size()/2;
  41. it = c.nth(sz_div_2);
  42. sz = c.index_of(it);
  43. cit = (as_const)(c).nth(sz_div_2);
  44. csz = (as_const)(c).index_of(cit);
  45. if(it != (c.begin()+sz_div_2))
  46. return false;
  47. if(cit != (c.cbegin()+sz_div_2))
  48. return false;
  49. if(sz != sz_div_2)
  50. return false;
  51. if(csz != sz_div_2)
  52. return false;
  53. //index size()
  54. it = c.nth(c.size());
  55. sz = c.index_of(it);
  56. cit = (as_const)(c).nth(c.size());
  57. csz = (as_const)(c).index_of(cit);
  58. if(it != c.end())
  59. return false;
  60. if(cit != c.cend())
  61. return false;
  62. if(sz != c.size())
  63. return false;
  64. if(csz != c.size())
  65. return false;
  66. return true;
  67. }
  68. } //namespace test{
  69. } //namespace container {
  70. } //namespace boost{
  71. #include <boost/container/detail/config_end.hpp>
  72. #endif //#ifndef BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP