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

source code of boost/libs/container/test/container_common_tests.hpp