Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54492 - sandbox/monotonic/libs/monotonic/test/clones
From: christian.schladetsch_at_[hidden]
Date: 2009-06-28 20:33:53


Author: cschladetsch
Date: 2009-06-28 20:33:52 EDT (Sun, 28 Jun 2009)
New Revision: 54492
URL: http://svn.boost.org/trac/boost/changeset/54492

Log:
added test of std::vector<boost::variant>
Text files modified:
   sandbox/monotonic/libs/monotonic/test/clones/tests.cpp | 18 +++++++++++++++++-
   1 files changed, 17 insertions(+), 1 deletions(-)

Modified: sandbox/monotonic/libs/monotonic/test/clones/tests.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/tests.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/clones/tests.cpp 2009-06-28 20:33:52 EDT (Sun, 28 Jun 2009)
@@ -11,6 +11,7 @@
 #include <boost/heterogenous/vector.hpp>
 #include <boost/bind.hpp>
 #include <boost/any.hpp>
+#include <boost/variant.hpp>
 
 using namespace std;
 using namespace boost;
@@ -60,10 +61,12 @@
 };
 
 void test_any();
+void test_variant();
 
 int main()
 {
         test_any();
+ test_variant();
 
         // a 'heterogenous' container of objects of any type that derives from common_base
         typedef heterogenous::vector<> vec;
@@ -128,7 +131,8 @@
         typedef std::vector<any_type, monotonic::allocator<any_type> > vec;
         vec v;
 
- // an issue here is that instances are copy-constructed into the container
+ // an issue here is that instances are copy-constructed into the container.
+ // but, types added do not have to derive from anything in order for duplication to work.
         v.push_back(derived(42));
         v.push_back(derived2("foo"));
 
@@ -137,4 +141,16 @@
         BOOST_ASSERT(any_cast<derived2 &>(v2[1]).str == "foo");
 }
 
+void test_variant()
+{
+ // need to declare all the possible types that could be used at the point of declaration
+ typedef variant<derived, derived2, derived3> var;
+ typedef std::vector<var, monotonic::allocator<var> > vec;
+ vec v0;
+ v0.push_back(derived(42));
+ v0.push_back(derived2("foo"));
+ vec v1 = v0;
+ BOOST_ASSERT(boost::get<derived2>(v1[1]).str == "foo");
+
+}
 //EOF


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk