stlab.adobe.com Adobe Systems Incorporated

check_traversable.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2008 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #include <adobe/config.hpp>
00010 
00011 #include <boost/concept_check.hpp>
00012 
00013 #include <adobe/test/check_regular.hpp>
00014 #include <adobe/implementation/swap.hpp>
00015 #include <iostream> 
00016 
00017 namespace adobe {
00021 template <typename T>
00022 void check_traversable(const T& c)
00023 {
00024 
00025 // http://www.sgi.com/tech/stl/Container.html
00026 
00027     boost::function_requires< boost::ContainerConcept<T> >();
00028     check_regular(c);
00029     {
00030         // some valid expressions
00031         const T d1(c);
00032         T d2(c);
00033         typename T::const_iterator i1=d1.begin(), i2=d1.end(), i3=d2.begin(), i4=d2.end();
00034         typename T::iterator j1=d2.begin(), j2=d2.end();
00035     }
00036 
00037 
00038     {
00039         T d(c);
00040         BOOST_CHECK_MESSAGE(c.size() == d.size(), "container copy-ctor size");
00041         typename T::const_iterator i=c.begin(), j=d.begin();
00042     
00043         BOOST_CHECK_MESSAGE(d==c, "container copy-ctor values");
00044     }
00045     
00046     {
00047         T d;
00048         d = c;
00049         BOOST_CHECK_MESSAGE(c.size() == d.size(), "container assignment copy-ctor size");
00050 
00051     
00052         BOOST_CHECK_MESSAGE(d==c, "container copy-ctor values");
00053     }
00054 
00055 
00056     {
00057         T d;
00058         BOOST_CHECK_MESSAGE(c.max_size() >= c.size() && 0 <= c.size(), "container maximum size");
00059         BOOST_CHECK_MESSAGE(d.max_size() >= d.size() && 0 <= d.size(), "container maximum size");
00060         BOOST_CHECK_MESSAGE(c.empty() == (c.size() == 0), "container empty");
00061         BOOST_CHECK_MESSAGE(d.empty() == (d.size() == 0), "container empty");
00062     }
00063     
00064      
00065     {
00066         using std::swap;
00067         T d1(c);
00068         T d2(c);
00069         T d3;
00070         T d4;
00071         
00072         d1.swap(d3);
00073         swap(d3,d4);
00074         BOOST_CHECK_MESSAGE(d1 == d3 && d2 == d4, "container swap");
00075     }
00076 
00077     {
00078 
00079         typename T::iterator x;
00080         typename T::const_iterator y;
00081         
00082         y = x; // Make sure mutable iterator can be converted to const.
00083         
00084         y == x; // Make sure const/mutable iterators can be compared.
00085         x == y;
00086 
00087     }
00088     
00089 
00090 
00091 }
00092 
00093 #if 0
00094 //gcc always instantiates this
00095 BOOST_TEST_CASE_TEMPLATE_FUNCTION(check_traversables, T)
00096 {
00097     check_traversable(arbitrary_traversable<T>());
00098 }
00099 #endif
00100 
00101 }
00102 

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