From 70c935285f0a91cc069e1ee32dba6afc36badd6e Mon Sep 17 00:00:00 2001
From: Christian Engwer <christi@dune-project.org>
Date: Wed, 17 Oct 2012 21:08:39 +0000
Subject: [PATCH] [shared_ptr] test initialization from nullptr fix bool cast
 of Dune implementation

[[Imported from SVN: r7040]]
---
 dune/common/shared_ptr.hh          | 5 +++++
 dune/common/test/shared_ptrtest.cc | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/dune/common/shared_ptr.hh b/dune/common/shared_ptr.hh
index a6b99b6b0..8ffc4f85b 100644
--- a/dune/common/shared_ptr.hh
+++ b/dune/common/shared_ptr.hh
@@ -112,6 +112,11 @@ namespace Dune
       return rep_==0 ? 0 : rep_->rep_;
     }
 
+    /** \brief Checks if shared_ptr manages an object, i.e. whether get() != 0. */
+    explicit operator bool() const {
+      return rep_ != 0 && rep_->rep_ != 0;
+    }
+
     /** \brief Swap content of this shared_ptr and another */
     inline void swap(shared_ptr& other);
 
diff --git a/dune/common/test/shared_ptrtest.cc b/dune/common/test/shared_ptrtest.cc
index 921a353a6..aed314aae 100644
--- a/dune/common/test/shared_ptrtest.cc
+++ b/dune/common/test/shared_ptrtest.cc
@@ -128,6 +128,11 @@ int main(){
     shared_ptr<double> bar(new double(43.0));
     assert(bar);
 
+    // test constructor from nullptr
+    shared_ptr<double> bar_null(nullptr);
+    assert(!bar_null);
+    assert(!bar_null.get());
+
     // test reset()
     bar.reset();
     assert(!bar);
-- 
GitLab