// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
// Copyright (c) 2001, 2002 Peter Dimov
//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.
//
#include <boost/assert.hpp>
#include <boost/checked_delete.hpp>
+#include <boost/throw_exception.hpp>
#include <boost/detail/atomic_count.hpp>
#ifndef BOOST_NO_AUTO_PTR
-#include <memory> // for std::auto_ptr
+# include <memory> // for std::auto_ptr
#endif
-#include <algorithm> // for std::swap
-#include <functional> // for std::less
+#include <algorithm> // for std::swap
+#include <functional> // for std::less
+#include <new> // for std::bad_alloc
namespace boost
{
public:
typedef T element_type;
+ typedef T value_type;
explicit shared_ptr(T * p = 0): px(p)
{
+#ifndef BOOST_NO_EXCEPTIONS
+
try // prevent leak if new throws
{
pn = new count_type(1);
}
catch(...)
{
- checked_delete(p);
+ boost::checked_delete(p);
throw;
- }
+ }
+
+#else
+
+ pn = new count_type(1);
+
+ if(pn == 0)
+ {
+ boost::checked_delete(p);
+ boost::throw_exception(std::bad_alloc());
+ }
+
+#endif
}
~shared_ptr()
{
if(--*pn == 0)
{
- checked_delete(px);
+ boost::checked_delete(px);
delete pn;
}
}