diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-01-19 10:05:08 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-01-19 10:06:32 +0200 |
commit | 0fdf19714613a82a184f4f6e75fb9a4f9b62f18a (patch) | |
tree | 93bb2df0f9d9eab44d36dedf29d4df500ecefcbc /libxsd/xsd/cxx/auto-array.hxx | |
parent | 45db924dfc19b49b7930522dbddd123fb9575e32 (diff) |
Use std::unique_ptr instead of std::auto_ptr in C++11 mode
Diffstat (limited to 'libxsd/xsd/cxx/auto-array.hxx')
-rw-r--r-- | libxsd/xsd/cxx/auto-array.hxx | 22 |
1 files changed, 14 insertions, 8 deletions
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/cxx/config.hxx> // XSD_CXX11 + +#ifdef XSD_CXX11 +# error use std::unique_ptr instead of non-standard auto_array +#endif + #include <cstddef> // std::size_t namespace xsd @@ -13,20 +19,20 @@ namespace xsd namespace cxx { template <typename T> - 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 <typename T, typename D = std_deallocator<T> > + template <typename T, typename D = std_array_deleter<T> > 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 <typename T, typename D> |