From 2fe506b51ac213e9cfa0427bd8dd82f40b3ba072 Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@dune-project.org> Date: Mon, 7 Dec 2009 10:27:21 +0000 Subject: [PATCH] implement get() [[Imported from SVN: r5749]] --- dune/common/shared_ptr.hh | 5 +++++ dune/common/test/smartpointertest.cc | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/dune/common/shared_ptr.hh b/dune/common/shared_ptr.hh index ce4546b64..5ca23029f 100644 --- a/dune/common/shared_ptr.hh +++ b/dune/common/shared_ptr.hh @@ -90,6 +90,11 @@ namespace Dune /** \brief Dereference as const pointer */ inline const element_type* operator->() const; + /** \brief Access to the raw pointer, if you really want it */ + element_type* get() const { + return rep_->rep_; + } + /** \brief Decrease the reference count by one and free the memory if the reference count has reached 0 */ diff --git a/dune/common/test/smartpointertest.cc b/dune/common/test/smartpointertest.cc index 66c091f59..9871296f4 100644 --- a/dune/common/test/smartpointertest.cc +++ b/dune/common/test/smartpointertest.cc @@ -38,6 +38,10 @@ int main(){ assert(bar); assert(bar.use_count()==1); + // test get() + double* barPtr = bar.get(); + assert(barPtr); + // test constructor from a given pointer shared_ptr<double> b(new double(42.0)); { -- GitLab