summaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/auto-array.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'libxsd/xsd/cxx/auto-array.hxx')
-rw-r--r--libxsd/xsd/cxx/auto-array.hxx22
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>