From 2fd906d11b4e3295a11de1ee4044f73074282f61 Mon Sep 17 00:00:00 2001
From: scott snyder <sss@karma>
Date: Thu, 9 May 2019 15:31:34 +0200
Subject: [PATCH] AthenaKernel: Add DataObjectSharedPtr ctor taking
 std::unique_ptr.

Add a constructor overload to DataObjectSharedPtr taking directly
a std::unique_ptr.  Can avoid having to do an explicit release().
---
 .../AthenaKernel/DataObjectSharedPtr.h            |  5 ++++-
 .../share/DataObjectSharedPtr_test.ref            |  3 +++
 .../test/DataObjectSharedPtr_test.cxx             | 15 ++++++++++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/Control/AthenaKernel/AthenaKernel/DataObjectSharedPtr.h b/Control/AthenaKernel/AthenaKernel/DataObjectSharedPtr.h
index cb0ae7a3834..b09890f6ab5 100644
--- a/Control/AthenaKernel/AthenaKernel/DataObjectSharedPtr.h
+++ b/Control/AthenaKernel/AthenaKernel/DataObjectSharedPtr.h
@@ -1,7 +1,7 @@
 // This file's extension implies that it's C, but it's really -*- C++ -*-.
 
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 // $Id$
@@ -19,6 +19,7 @@
 
 #include "GaudiKernel/DataObject.h"
 #include "boost/intrusive_ptr.hpp"
+#include <memory>
 
 
 inline void intrusive_ptr_add_ref (DataObject* o)
@@ -48,6 +49,8 @@ public:
   DataObjectSharedPtr() {}
   explicit DataObjectSharedPtr (T* p, bool add_ref = true)
     : Base (p, add_ref) {}
+  explicit DataObjectSharedPtr (std::unique_ptr<T> p, bool add_ref = true)
+    : Base (p.release(), add_ref) {}
   DataObjectSharedPtr (const DataObjectSharedPtr& rhs)
     : Base (rhs) {}
   template <class U>
diff --git a/Control/AthenaKernel/share/DataObjectSharedPtr_test.ref b/Control/AthenaKernel/share/DataObjectSharedPtr_test.ref
index 7e425e6d6b3..3cee042cee6 100644
--- a/Control/AthenaKernel/share/DataObjectSharedPtr_test.ref
+++ b/Control/AthenaKernel/share/DataObjectSharedPtr_test.ref
@@ -1,3 +1,6 @@
 test1
 should call dtor now
 MyObj dtor
+test2
+should call dtor now
+MyObj dtor
diff --git a/Control/AthenaKernel/test/DataObjectSharedPtr_test.cxx b/Control/AthenaKernel/test/DataObjectSharedPtr_test.cxx
index 3f23b6b1a68..08931cf49a2 100644
--- a/Control/AthenaKernel/test/DataObjectSharedPtr_test.cxx
+++ b/Control/AthenaKernel/test/DataObjectSharedPtr_test.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 // $Id$
@@ -49,8 +49,21 @@ void test1()
 }
 
 
+void test2()
+{
+  std::cout << "test2\n";
+  {
+    auto uptr = std::make_unique<MyObj>();
+    SG::DataObjectSharedPtr<MyObj> ptr (std::move (uptr));
+    assert (ptr->refCount() == 1);
+    std::cout << "should call dtor now\n";
+  }
+}
+
+
 int main()
 {
   test1();
+  test2();
   return 0;
 }
-- 
GitLab