aboutsummaryrefslogtreecommitdiff
path: root/common/lazy-ptr
diff options
context:
space:
mode:
Diffstat (limited to 'common/lazy-ptr')
-rw-r--r--common/lazy-ptr/driver.cxx44
-rw-r--r--common/lazy-ptr/test.hxx20
2 files changed, 53 insertions, 11 deletions
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 <memory> // std::auto_ptr
+#include <utility> // std::move
#include <cassert>
#include <iostream>
@@ -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<obj> () == o->id);
assert (o->c.object_id<cont> () == 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<obj> () == o->id);
assert (o->c.object_id<cont> () == 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<cont> (*db, c1));
assert (lc1 != lazy_shared_ptr<cont> (*db, c2));
+ // Test move constructors.
+ //
+#ifdef HAVE_CXX11
+ {
+ lazy_shared_ptr<cont> tmp (*db, 1);
+ lazy_shared_ptr<cont> l (std::move (tmp));
+ assert (lc1 == l);
+ }
+
+ {
+ shared_ptr<cont> tmp (c1);
+ lazy_shared_ptr<cont> 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<obj> () == o->id);
assert (o->c.object_id<cont> () == c->id);
+#endif
// Load.
//
@@ -315,7 +346,12 @@ main (int argc, char* argv[])
assert (!c->o[1].loaded ());
lazy_shared_ptr<obj> 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<obj> () == c->o[1].object_id<obj> ());
+#endif
// Reload.
//
diff --git a/common/lazy-ptr/test.hxx b/common/lazy-ptr/test.hxx
index f9362f8..0adddf8 100644
--- a/common/lazy-ptr/test.hxx
+++ b/common/lazy-ptr/test.hxx
@@ -5,7 +5,7 @@
#ifndef TEST_HXX
#define TEST_HXX
-#include <common/config.hxx> // HAVE_TR1_MEMORY
+#include <common/config.hxx> // HAVE_CXX11, HAVE_TR1_MEMORY
#include <vector>
#include <string>
@@ -14,7 +14,7 @@
#include <odb/core.hxx>
#include <odb/lazy-ptr.hxx>
-#ifdef HAVE_TR1_MEMORY
+#if !defined(HAVE_CXX11) && defined(HAVE_TR1_MEMORY)
# include <odb/tr1/memory.hxx>
# include <odb/tr1/lazy-ptr.hxx>
#endif
@@ -59,8 +59,8 @@ inline cont1::
~cont1 ()
{
for (obj_list::iterator i (o.begin ()); i != o.end (); ++i)
- if (i->loaded ())
- delete i->get ();
+ if (obj1* p = i->get ())
+ delete p;
}
// Auto pointer.
@@ -98,14 +98,20 @@ public:
lazy_ptr<cont2> c; // weak
};
-// TR1.
+// shared_ptr
//
-#ifdef HAVE_TR1_MEMORY
-namespace tr1
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
+namespace shared
{
+#ifdef HAVE_CXX11
+ using std::shared_ptr;
+ using odb::lazy_shared_ptr;
+ using odb::lazy_weak_ptr;
+#else
using std::tr1::shared_ptr;
using odb::tr1::lazy_shared_ptr;
using odb::tr1::lazy_weak_ptr;
+#endif
class obj;