changeset 3711:14b363d972a8 storage-commitment

experimenting boost::movelib::unique_ptr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Mar 2020 10:13:34 +0100
parents 1c69af37d8ae
children 56f2397f027a
files UnitTestsSources/ToolboxTests.cpp
diffstat 1 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/UnitTestsSources/ToolboxTests.cpp	Fri Feb 28 13:27:16 2020 +0100
+++ b/UnitTestsSources/ToolboxTests.cpp	Mon Mar 02 10:13:34 2020 +0100
@@ -157,3 +157,42 @@
   std::string s = Toolbox::GenerateDicomPrivateUniqueIdentifier();
   ASSERT_EQ("2.25.", s.substr(0, 5));
 }
+
+
+
+#include "../Core/IDynamicObject.h"
+
+#if __cplusplus < 201103L
+/**
+ * "std::unique_ptr" was introduced in C++11. We emulate it using
+ * boost. "The smart pointer unique_ptr [is] a drop-in replacement for
+ * std::unique_ptr, usable also from C++03 compilers." This is only
+ * available on Boost >= 1.57.0 (from November 2014).
+ * https://www.boost.org/doc/libs/1_57_0/doc/html/move/reference.html#header.boost.move.unique_ptr_hpp
+ **/
+
+#include <boost/move/unique_ptr.hpp>
+
+namespace std
+{
+  template <typename T>
+  class unique_ptr : public boost::movelib::unique_ptr<T>
+  {
+  public:
+    unique_ptr(T* p) :
+      boost::movelib::unique_ptr<T>(p)
+    {
+    }      
+  };
+}
+
+#endif
+
+TEST(Toolbox, UniquePtr)
+{
+  std::unique_ptr<int> i(new int(42));
+  ASSERT_EQ(42, *i);
+
+  std::unique_ptr<SingleValueObject<int> > j(new SingleValueObject<int>(42));
+  ASSERT_EQ(42, j->GetValue());
+}