From b3e6f5483fdad6c7542efb4bf6c9facfcfe5e588 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 7 Jun 2015 23:16:00 -0400 Subject: [PATCH] Base std_cxx11::unique_ptr on boost::scoped_ptr. Previously this class was a wrapper around boost::shared_ptr, which requires one more memory allocation than boost::scoped_ptr. The scoped_ptr class is more restrictive (it cannot be copied or moved) than unique_ptr (which cannot be copied but can be moved), but non-C++11 compilers do not have move semantics anyway. --- include/deal.II/base/std_cxx11/unique_ptr.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/include/deal.II/base/std_cxx11/unique_ptr.h b/include/deal.II/base/std_cxx11/unique_ptr.h index a3cb3e3347..5476ec6879 100644 --- a/include/deal.II/base/std_cxx11/unique_ptr.h +++ b/include/deal.II/base/std_cxx11/unique_ptr.h @@ -31,7 +31,8 @@ DEAL_II_NAMESPACE_CLOSE #else -#include +#include + DEAL_II_NAMESPACE_OPEN namespace std_cxx11 { @@ -43,19 +44,17 @@ namespace std_cxx11 * compiler -- in which case you also have std::unique_ptr; see for example * http://stackoverflow.com/questions/2953530/unique-ptr-boost-equivalent) * - * Consequently, we emulate the class by just wrapping a boost::shared_ptr + * Consequently, we emulate the class by just wrapping a boost::scoped_ptr * in the cheapest possible way -- by just deriving from it and repeating - * the basic constructors. Everything else is inherited from the shared_ptr + * the basic constructors. Everything else is inherited from the scoped_ptr * class. * - * This replacement comes with a certain overhead: doing reference counting - * instead of just passing ownership of pointers has a cost. But we don't - * use unique_ptrs in expensive places, and it is also a cost that will - * disappear once we require C++11 (and the cost of course does not apply if - * your compiler already supports C++11 and deal.II uses it). + * There is no overhead to this approach: scoped_ptr cannot be copied or + * moved. Instances of unique_ptr cannot be copied, and if you do not have a + * C++11 compiler, then you cannot move anything anyway. */ template - class unique_ptr : public boost::shared_ptr + class unique_ptr : public boost::scoped_ptr { public: unique_ptr () {} @@ -63,7 +62,7 @@ namespace std_cxx11 template explicit unique_ptr (Y *p) : - boost::shared_ptr(p) + boost::scoped_ptr(p) {} }; -- 2.39.5