diff --git a/Control/AthenaKernel/AthenaKernel/DataObjectSharedPtr.h b/Control/AthenaKernel/AthenaKernel/DataObjectSharedPtr.h index cb0ae7a3834aa658799d26e978d122a10d331d88..b09890f6ab507d98605fbb3db6ba4267a089ebdd 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 7e425e6d6b3acf0c12df41801f240f05e7576bae..3cee042cee6aefbccdf8c087134f53b79b7ccccc 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 3f23b6b1a68a590b59dd06e5c6d9bf61899ea61e..08931cf49a2edce09df6f62e30aad885b7bdac60 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; }