stlab.adobe.com Adobe Systems Incorporated
check_traversable.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2008 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #include <adobe/config.hpp>
10 
11 #include <boost/concept_check.hpp>
12 
14 #include <adobe/implementation/swap.hpp>
15 #include <iostream>
16 
17 namespace adobe {
21 template <typename T>
22 void check_traversable(const T& c)
23 {
24 
25 // http://www.sgi.com/tech/stl/Container.html
26 
27  boost::function_requires< boost::ContainerConcept<T> >();
28  check_regular(c);
29  {
30  // some valid expressions
31  const T d1(c);
32  T d2(c);
33  typename T::const_iterator i1=d1.begin(), i2=d1.end(), i3=d2.begin(), i4=d2.end();
34  typename T::iterator j1=d2.begin(), j2=d2.end();
35  }
36 
37 
38  {
39  T d(c);
40  BOOST_CHECK_MESSAGE(c.size() == d.size(), "container copy-ctor size");
41  typename T::const_iterator i=c.begin(), j=d.begin();
42 
43  BOOST_CHECK_MESSAGE(d==c, "container copy-ctor values");
44  }
45 
46  {
47  T d;
48  d = c;
49  BOOST_CHECK_MESSAGE(c.size() == d.size(), "container assignment copy-ctor size");
50 
51 
52  BOOST_CHECK_MESSAGE(d==c, "container copy-ctor values");
53  }
54 
55 
56  {
57  T d;
58  BOOST_CHECK_MESSAGE(c.max_size() >= c.size() && 0 <= c.size(), "container maximum size");
59  BOOST_CHECK_MESSAGE(d.max_size() >= d.size() && 0 <= d.size(), "container maximum size");
60  BOOST_CHECK_MESSAGE(c.empty() == (c.size() == 0), "container empty");
61  BOOST_CHECK_MESSAGE(d.empty() == (d.size() == 0), "container empty");
62  }
63 
64 
65  {
66  using std::swap;
67  T d1(c);
68  T d2(c);
69  T d3;
70  T d4;
71 
72  d1.swap(d3);
73  swap(d3,d4);
74  BOOST_CHECK_MESSAGE(d1 == d3 && d2 == d4, "container swap");
75  }
76 
77  {
78 
79  typename T::iterator x;
80  typename T::const_iterator y;
81 
82  y = x; // Make sure mutable iterator can be converted to const.
83 
84  y == x; // Make sure const/mutable iterators can be compared.
85  x == y;
86 
87  }
88 
89 
90 
91 }
92 
93 #if 0
94 //gcc always instantiates this
95 BOOST_TEST_CASE_TEMPLATE_FUNCTION(check_traversables, T)
96 {
97  check_traversable(arbitrary_traversable<T>());
98 }
99 #endif
100 
101 }
102 

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google