From 439bc0ff201f38025d224ce421c86ca44f3dc063 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 28 Feb 2012 12:46:48 +0200 Subject: Test std::shared_ptr in C++11 mode and std::tr1::shared_ptr in C++98 mode --- common/lazy-ptr/driver.cxx | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'common/lazy-ptr/driver.cxx') diff --git a/common/lazy-ptr/driver.cxx b/common/lazy-ptr/driver.cxx index 8065e2c..3e031d3 100644 --- a/common/lazy-ptr/driver.cxx +++ b/common/lazy-ptr/driver.cxx @@ -6,6 +6,7 @@ // #include // std::auto_ptr +#include // std::move #include #include @@ -113,8 +114,13 @@ main (int argc, char* argv[]) // Correct object ids. // +#ifdef HAVE_CXX11 + assert (c->o[0].object_id () == o->id); + assert (o->c.object_id () == c->id); +#else assert (c->o[0].object_id () == o->id); assert (o->c.object_id () == c->id); +#endif // Load. // @@ -185,8 +191,13 @@ main (int argc, char* argv[]) // Correct object ids. // +#ifdef HAVE_CXX11 + assert (c->o.object_id () == o->id); + assert (o->c.object_id () == c->id); +#else assert (c->o.object_id () == o->id); assert (o->c.object_id () == c->id); +#endif // Load. // @@ -218,12 +229,11 @@ main (int argc, char* argv[]) } } - // TR1. + // Shared pointer from C++11 or TR1. // -#ifdef HAVE_TR1_MEMORY +#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) { - using namespace ::tr1; - using std::tr1::shared_ptr; + using namespace shared; // persist // @@ -258,6 +268,22 @@ main (int argc, char* argv[]) assert (lc1 == lazy_shared_ptr (*db, c1)); assert (lc1 != lazy_shared_ptr (*db, c2)); + // Test move constructors. + // +#ifdef HAVE_CXX11 + { + lazy_shared_ptr tmp (*db, 1); + lazy_shared_ptr l (std::move (tmp)); + assert (lc1 == l); + } + + { + shared_ptr tmp (c1); + lazy_shared_ptr l (*db, std::move (tmp)); + assert (lc1 == l); + } +#endif + { transaction t (db->begin ()); @@ -289,8 +315,13 @@ main (int argc, char* argv[]) // Correct object ids. // +#ifdef HAVE_CXX11 + assert (c->o[0].object_id () == o->id); + assert (o->c.object_id () == c->id); +#else assert (c->o[0].object_id () == o->id); assert (o->c.object_id () == c->id); +#endif // Load. // @@ -315,7 +346,12 @@ main (int argc, char* argv[]) assert (!c->o[1].loaded ()); lazy_shared_ptr l (c->o[1].lock ()); assert (!l.loaded ()); + +#ifdef HAVE_CXX11 + assert (l.object_id () == c->o[1].object_id ()); +#else assert (l.object_id () == c->o[1].object_id ()); +#endif // Reload. // -- cgit v1.1