• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
12 #define BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
13 
14 #include <boost/container/detail/config_begin.hpp>
15 
16 namespace boost{
17 namespace container {
18 namespace test{
19 
20 
21 template<class Container>
as_const(Container & c)22 const Container &as_const(Container &c)
23 {  return c;   }
24 
25 //nth, index_of
26 template<class Container>
test_nth_index_of(Container & c)27 bool test_nth_index_of(Container &c)
28 {
29    typename Container::iterator it;
30    typename Container::const_iterator cit;
31    typename Container::size_type sz, csz;
32    //index 0
33    it = c.nth(0);
34    sz = c.index_of(it);
35    cit = (as_const)(c).nth(0);
36    csz = (as_const)(c).index_of(cit);
37 
38    if(it != c.begin())
39       return false;
40    if(cit != c.cbegin())
41       return false;
42    if(sz != 0)
43       return false;
44    if(csz != 0)
45       return false;
46 
47    //index size()/2
48    const typename Container::size_type sz_div_2 = c.size()/2;
49    it = c.nth(sz_div_2);
50    sz = c.index_of(it);
51    cit = (as_const)(c).nth(sz_div_2);
52    csz = (as_const)(c).index_of(cit);
53 
54    if(it != (c.begin()+sz_div_2))
55       return false;
56    if(cit != (c.cbegin()+sz_div_2))
57       return false;
58    if(sz != sz_div_2)
59       return false;
60    if(csz != sz_div_2)
61       return false;
62 
63    //index size()
64    it = c.nth(c.size());
65    sz = c.index_of(it);
66    cit = (as_const)(c).nth(c.size());
67    csz = (as_const)(c).index_of(cit);
68 
69    if(it != c.end())
70       return false;
71    if(cit != c.cend())
72       return false;
73    if(sz != c.size())
74       return false;
75    if(csz != c.size())
76       return false;
77    return true;
78 }
79 
80 }  //namespace test{
81 }  //namespace container {
82 }  //namespace boost{
83 
84 #include <boost/container/detail/config_end.hpp>
85 
86 #endif //#ifndef BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
87