aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-06-10 15:13:48 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-06-10 15:13:48 +0000
commit8681eb2a437c6fb4ec94299dd4d39faf7b0cbb7a (patch)
tree78a47f8625d05e7da34150adee8ec33440eb5cb5
parent03167b52437733063bb106639c5a60660abdece8 (diff)
downloadpaludis-8681eb2a437c6fb4ec94299dd4d39faf7b0cbb7a.tar.gz
paludis-8681eb2a437c6fb4ec94299dd4d39faf7b0cbb7a.tar.xz
Make ActiveObjectPtr<DeferredConstructionPtr<...> > only construct once.
-rw-r--r--paludis/util/active_object_ptr.hh2
-rw-r--r--paludis/util/deferred_construction_ptr_TEST.cc47
2 files changed, 48 insertions, 1 deletions
diff --git a/paludis/util/active_object_ptr.hh b/paludis/util/active_object_ptr.hh
index b8a65ca..d3cce21 100644
--- a/paludis/util/active_object_ptr.hh
+++ b/paludis/util/active_object_ptr.hh
@@ -47,7 +47,7 @@ namespace paludis
{
}
- T_ operator-> () const
+ const T_ & operator-> () const
{
return _ptr->_ptr;
}
diff --git a/paludis/util/deferred_construction_ptr_TEST.cc b/paludis/util/deferred_construction_ptr_TEST.cc
index f04f976..b7b2243 100644
--- a/paludis/util/deferred_construction_ptr_TEST.cc
+++ b/paludis/util/deferred_construction_ptr_TEST.cc
@@ -86,5 +86,52 @@ namespace test_cases
TEST_CHECK_EQUAL(q->length(), 5u);
}
} test_dereferred_active;
+
+ struct TestConstructOnlyOnce : TestCase
+ {
+ TestConstructOnlyOnce() : TestCase("construct only once") { }
+
+ struct Flag
+ {
+ bool value;
+ Flag() : value(false) { }
+ };
+
+ static std::tr1::shared_ptr<Flag> make_flag()
+ {
+ return make_shared_ptr(new Flag);
+ }
+
+ void run()
+ {
+ DeferredConstructionPtr<std::tr1::shared_ptr<Flag> > f(make_flag);
+ f->value = true;
+ TEST_CHECK(f->value);
+ }
+ } test_construct_only_once;
+
+ struct TestConstructOnlyOnceActive : TestCase
+ {
+ TestConstructOnlyOnceActive() : TestCase("construct only once active") { }
+
+ struct Flag
+ {
+ bool value;
+ Flag() : value(false) { }
+ };
+
+ static std::tr1::shared_ptr<Flag> make_flag()
+ {
+ return make_shared_ptr(new Flag);
+ }
+
+ void run()
+ {
+ ActiveObjectPtr<DeferredConstructionPtr<std::tr1::shared_ptr<Flag> > > f((
+ DeferredConstructionPtr<std::tr1::shared_ptr<Flag> >(make_flag)));
+ f->value = true;
+ TEST_CHECK(f->value);
+ }
+ } test_construct_only_once_active;
}