From 0fdf19714613a82a184f4f6e75fb9a4f9b62f18a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 19 Jan 2014 10:05:08 +0200 Subject: Use std::unique_ptr instead of std::auto_ptr in C++11 mode --- libxsd/xsd/cxx/auto-array.hxx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'libxsd/xsd/cxx/auto-array.hxx') diff --git a/libxsd/xsd/cxx/auto-array.hxx b/libxsd/xsd/cxx/auto-array.hxx index e309603..64c454a 100644 --- a/libxsd/xsd/cxx/auto-array.hxx +++ b/libxsd/xsd/cxx/auto-array.hxx @@ -6,6 +6,12 @@ #ifndef XSD_CXX_AUTO_ARRAY_HXX #define XSD_CXX_AUTO_ARRAY_HXX +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# error use std::unique_ptr instead of non-standard auto_array +#endif + #include // std::size_t namespace xsd @@ -13,20 +19,20 @@ namespace xsd namespace cxx { template - struct std_deallocator + struct std_array_deleter { void - deallocate (T* p) + operator() (T* p) const { delete[] p; } }; // Simple automatic array. The second template parameter is - // an optional deallocator type. If not specified, delete[] + // an optional deleter type. If not specified, delete[] // is used. // - template > + template > struct auto_array { auto_array (T a[]) @@ -34,7 +40,7 @@ namespace xsd { } - auto_array (T a[], D& d) + auto_array (T a[], const D& d) : a_ (a), d_ (&d) { } @@ -42,7 +48,7 @@ namespace xsd ~auto_array () { if (d_ != 0) - d_->deallocate (a_); + (*d_) (a_); else delete[] a_; } @@ -73,7 +79,7 @@ namespace xsd if (a_ != a) { if (d_ != 0) - d_->deallocate (a_); + (*d_) (a_); else delete[] a_; @@ -100,7 +106,7 @@ namespace xsd private: T* a_; - D* d_; + const D* d_; }; template -- cgit v1.1