Compare commits

..

26 Commits

Author SHA1 Message Date
nobody
552eed7027 This commit was manufactured by cvs2svn to create tag
'Version_1_31_0'.

[SVN r22162]
2004-02-04 15:24:32 +00:00
nobody
cf612d7b95 This commit was manufactured by cvs2svn to create branch 'RC_1_31_0'.
[SVN r21427]
2003-12-30 12:10:04 +00:00
Beman Dawes
7fb399b3bb index.htm renamed index.html
[SVN r21231]
2003-12-11 23:31:15 +00:00
Peter Dimov
93d69af60a _MSC_VER use clarified.
[SVN r20992]
2003-11-28 15:35:21 +00:00
Peter Dimov
09c8685181 Fixed a VC7 'regression' (pointers to volatile cannot be deleted)
[SVN r20977]
2003-11-27 16:58:23 +00:00
Dave Abrahams
15d6b2aace CWPro8 workaround
[SVN r20323]
2003-10-09 14:14:26 +00:00
Dave Abrahams
feff6e40ea Use conforming is_class for EDG compilers
Make is_enum work for class types which are convertible to anything at
all (on many compilers).

smart_ptr library workarounds for __MWERKS__ (must use member function
pointer for unspecified_bool_type).


[SVN r20244]
2003-10-02 17:49:06 +00:00
Peter Dimov
26a93f224e Changed index.htm to redirect to smart_ptr.htm
[SVN r20239]
2003-10-01 11:13:04 +00:00
Peter Dimov
96f572b19b Switched unspecified_bool_type to data member pointer.
[SVN r20238]
2003-10-01 11:12:15 +00:00
Vladimir Prus
d6c4633e89 Add V2 Jamfile
[SVN r20223]
2003-09-30 07:42:34 +00:00
Beman Dawes
106a6d58d4 Change license message to reference Boost Software License
[SVN r20038]
2003-09-12 17:09:29 +00:00
Dave Abrahams
debd953d8f Use the import rule
[SVN r19968]
2003-09-08 17:38:49 +00:00
Peter Dimov
f2c5439644 'volatile' fixes.
[SVN r19961]
2003-09-08 12:26:02 +00:00
Peter Dimov
b4ec0e90fb Switched weak_count_ from #shared+#weak to #weak+(#shared != 0); thanks to Alexander Terekhov and Ben Hutchings
[SVN r19246]
2003-07-21 14:17:03 +00:00
Peter Dimov
2d4eb92401 get_deleter fix for EDG 2.38
[SVN r19148]
2003-07-16 11:54:49 +00:00
Peter Dimov
192970b3b8 const_pointer_cast added.
[SVN r19147]
2003-07-16 11:51:12 +00:00
Peter Dimov
7c36a640ae add_ref split to add_ref_copy and add_ref_lock to eliminate the redundant use_count_ == 0 check.
[SVN r19126]
2003-07-15 12:18:40 +00:00
Peter Dimov
794de98cd1 #include <boost/config.hpp> added.
[SVN r19065]
2003-07-11 17:03:56 +00:00
Peter Dimov
dcdbaf1e57 A binary compatible 'null' lightweight_mutex for Win32 added.
[SVN r18916]
2003-07-02 11:54:40 +00:00
Peter Dimov
6dbec7621d Detect the VC6 STL, not VC6 itself (for Intel)
[SVN r18837]
2003-06-18 16:03:09 +00:00
Peter Dimov
889cb6bee6 -Wundef fixes.
[SVN r18788]
2003-06-12 17:09:24 +00:00
Peter Dimov
11cddbbb45 Minor fix, scoped_ptr in the intro should've been shared_ptr.
[SVN r18745]
2003-06-09 18:25:41 +00:00
Peter Dimov
77c629b6e4 smart_ptr.hpp now includes all smart pointer headers for convenience.
[SVN r18588]
2003-05-28 13:51:35 +00:00
Peter Dimov
d091ee85c0 Turns out Sun CC doesn't like operator int().
[SVN r18512]
2003-05-23 13:46:07 +00:00
Peter Dimov
bc00d5fa1a Fixed bool conversions for Sun 5.3
[SVN r18419]
2003-05-16 12:11:17 +00:00
Peter Dimov
e760759414 Fixed a copy/assignment issue.
[SVN r18122]
2003-03-28 12:27:55 +00:00
40 changed files with 606 additions and 200 deletions

View File

@@ -1,12 +1,9 @@
// Boost scoped_ptr_example implementation file -----------------------------//
// (C) Copyright Beman Dawes 2001. 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.
// Copyright Beman Dawes 2001.
// See accompanying license for terms and conditions of use.
// See http://www.boost.org for most recent version including documentation.
// See http://www.boost.org/libs/smart_ptr for documentation.
#include "scoped_ptr_example.hpp"
#include <iostream>

View File

@@ -1,12 +1,9 @@
// Boost scoped_ptr_example header file ------------------------------------//
// (C) Copyright Beman Dawes 2001. 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.
// Copyright Beman Dawes 2001.
// See accompanying license for terms and conditions of use.
// See http://www.boost.org for most recent version including documentation.
// See http://www.boost.org/libs/smart_ptr for documentation.
#include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp>

View File

@@ -1,12 +1,9 @@
// Boost scoped_ptr_example_test main program -------------------------------//
// (C) Copyright Beman Dawes 2001. 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.
// Copyright Beman Dawes 2001.
// See accompanying license for terms and conditions of use.
// See http://www.boost.org for most recent version including documentation.
// See http://www.boost.org/libs/smart_ptr for documentation.
#include "scoped_ptr_example.hpp"

View File

@@ -1,12 +1,9 @@
// Boost shared_ptr_example.cpp --------------------------------------------//
// (C) Copyright Beman Dawes 2001. 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.
// Copyright Beman Dawes 2001.
// See accompanying license for terms and conditions of use.
// See http://www.boost.org for most recent version including documentation.
// See http://www.boost.org/libs/smart_ptr for documentation.
// Revision History
// 21 May 01 Initial complete version (Beman Dawes)

View File

@@ -1,12 +1,9 @@
// Boost shared_ptr_example2 implementation file -----------------------------//
// (C) Copyright Beman Dawes 2001. 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.
// Copyright Beman Dawes 2001.
// See accompanying license for terms and conditions of use.
// See http://www.boost.org for most recent version including documentation.
// See http://www.boost.org/libs/smart_ptr for documentation.
#include "shared_ptr_example2.hpp"
#include <iostream>

View File

@@ -1,12 +1,9 @@
// Boost shared_ptr_example2 header file -----------------------------------//
// (C) Copyright Beman Dawes 2001. 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.
// Copyright Beman Dawes 2001.
// See accompanying license for terms and conditions of use.
// See http://www.boost.org for most recent version including documentation.
// See http://www.boost.org/libs/smart_ptr for documentation.
#include <boost/shared_ptr.hpp>

View File

@@ -1,12 +1,9 @@
// Boost shared_ptr_example2_test main program ------------------------------//
// (C) Copyright Beman Dawes 2001. 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.
// Copyright Beman Dawes 2001.
// See accompanying license for terms and conditions of use.
// See http://www.boost.org for most recent version including documentation.
// See http://www.boost.org/libs/smart_ptr for documentation.
#include "shared_ptr_example2.hpp"

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
#define BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
#define BOOST_DETAIL_ATOMIC_COUNT_WIN32_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//

View File

@@ -1,14 +1,16 @@
#ifndef BOOST_DETAIL_LIGHTWEIGHT_MUTEX_HPP_INCLUDED
#define BOOST_DETAIL_LIGHTWEIGHT_MUTEX_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//
// boost/detail/lightweight_mutex.hpp - lightweight mutex
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2002, 2003 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
@@ -64,15 +66,23 @@
// shared_ptr_timing_test.cpp will compile succesfully with a stub do-nothing
// pthreads library, since it doesn't create any threads.
#ifndef BOOST_HAS_THREADS
# include <boost/detail/lwm_nop.hpp>
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__)) && !defined(BOOST_LWM_USE_CRITICAL_SECTION) && !defined(BOOST_LWM_USE_PTHREADS)
# define BOOST_LWM_WIN32
#endif
#if !defined(BOOST_HAS_THREADS)
# if defined(BOOST_LWM_WIN32)
# include <boost/detail/lwm_win32_nt.hpp>
# else
# include <boost/detail/lwm_nop.hpp>
# endif
#elif defined(BOOST_LWM_USE_SPINLOCK) && defined(BOOST_USE_ASM_ATOMIC_H)
# include <boost/detail/lwm_linux.hpp>
#elif defined(BOOST_LWM_USE_CRITICAL_SECTION)
# include <boost/detail/lwm_win32_cs.hpp>
#elif defined(BOOST_LWM_USE_PTHREADS)
# include <boost/detail/lwm_pthreads.hpp>
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#elif defined(BOOST_LWM_WIN32)
# include <boost/detail/lwm_win32.hpp>
#elif defined(BOOST_LWM_USE_SPINLOCK) && defined(__sgi)
# include <boost/detail/lwm_irix.hpp>

View File

@@ -1,10 +1,6 @@
#ifndef BOOST_DETAIL_LWM_IRIX_HPP_INCLUDED
#define BOOST_DETAIL_LWM_IRIX_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
#endif
//
// boost/detail/lwm_irix.hpp
//

View File

@@ -1,10 +1,6 @@
#ifndef BOOST_DETAIL_LWM_LINUX_HPP_INCLUDED
#define BOOST_DETAIL_LWM_LINUX_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
#endif
//
// boost/detail/lwm_linux.hpp
//

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_DETAIL_LWM_NOP_HPP_INCLUDED
#define BOOST_DETAIL_LWM_NOP_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED
#define BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_DETAIL_LWM_WIN32_HPP_INCLUDED
#define BOOST_DETAIL_LWM_WIN32_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
#define BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//

View File

@@ -0,0 +1,64 @@
#ifndef BOOST_DETAIL_LWM_WIN32_NT_HPP_INCLUDED
#define BOOST_DETAIL_LWM_WIN32_NT_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//
// boost/detail/lwm_win32_nt.hpp
//
// Copyright (c) 2002, 2003 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.
//
// "No threads" version of lwm_win32.hpp; binary compatible but no-op.
//
namespace boost
{
namespace detail
{
class lightweight_mutex
{
private:
long l_;
lightweight_mutex(lightweight_mutex const &);
lightweight_mutex & operator=(lightweight_mutex const &);
public:
lightweight_mutex(): l_(0)
{
}
class scoped_lock;
friend class scoped_lock;
class scoped_lock
{
private:
scoped_lock(scoped_lock const &);
scoped_lock & operator=(scoped_lock const &);
public:
explicit scoped_lock(lightweight_mutex &)
{
}
};
};
} // namespace detail
} // namespace boost
#endif // #ifndef BOOST_DETAIL_LWM_WIN32_NT_HPP_INCLUDED

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_DETAIL_SHARED_COUNT_HPP_INCLUDED
#define BOOST_DETAIL_SHARED_COUNT_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//
@@ -115,14 +117,21 @@ public:
virtual void * get_deleter(std::type_info const & ti) = 0;
void add_ref()
void add_ref_copy()
{
#if defined(BOOST_HAS_THREADS)
mutex_type::scoped_lock lock(mtx_);
#endif
if(use_count_ == 0 && weak_count_ != 0) boost::throw_exception(boost::bad_weak_ptr());
++use_count_;
++weak_count_;
}
void add_ref_lock()
{
#if defined(BOOST_HAS_THREADS)
mutex_type::scoped_lock lock(mtx_);
#endif
if(use_count_ == 0) boost::throw_exception(boost::bad_weak_ptr());
++use_count_;
}
void release() // nothrow
@@ -133,11 +142,7 @@ public:
#endif
long new_use_count = --use_count_;
if(new_use_count != 0)
{
--weak_count_;
return;
}
if(new_use_count != 0) return;
}
dispose();
@@ -182,12 +187,10 @@ private:
sp_counted_base(sp_counted_base const &);
sp_counted_base & operator= (sp_counted_base const &);
// inv: use_count_ <= weak_count_
long use_count_; // #shared
long weak_count_; // #weak + (#shared != 0)
long use_count_;
long weak_count_;
#if defined(BOOST_HAS_THREADS)
#if defined(BOOST_HAS_THREADS) || defined(BOOST_LWM_WIN32)
mutable mutex_type mtx_;
#endif
};
@@ -384,7 +387,7 @@ public:
, id_(shared_count_id)
#endif
{
if(pi_ != 0) pi_->add_ref();
if(pi_ != 0) pi_->add_ref_copy();
}
explicit shared_count(weak_count const & r); // throws bad_weak_ptr when r.use_count() == 0
@@ -392,7 +395,7 @@ public:
shared_count & operator= (shared_count const & r) // nothrow
{
sp_counted_base * tmp = r.pi_;
if(tmp != 0) tmp->add_ref();
if(tmp != 0) tmp->add_ref_copy();
if(pi_ != 0) pi_->release();
pi_ = tmp;
@@ -532,7 +535,7 @@ inline shared_count::shared_count(weak_count const & r): pi_(r.pi_)
{
if(pi_ != 0)
{
pi_->add_ref();
pi_->add_ref_lock();
}
else
{

View File

@@ -24,6 +24,25 @@ namespace boost
template<class T> class enable_shared_from_this
{
protected:
enable_shared_from_this()
{
}
enable_shared_from_this(enable_shared_from_this const &)
{
}
enable_shared_from_this & operator=(enable_shared_from_this const &)
{
return *this;
}
~enable_shared_from_this()
{
}
public:
shared_ptr<T> shared_from_this()

View File

@@ -14,6 +14,8 @@
// See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation.
//
#include <boost/config.hpp>
#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
# pragma warning(push)
# pragma warning(disable:4284) // odd return type for operator->
@@ -119,13 +121,32 @@ public:
return p_;
}
typedef T * (intrusive_ptr::*unspecified_bool_type) () const;
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
operator bool () const
{
return p_ != 0;
}
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return p_ == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type () const
{
return p_ == 0? 0: &intrusive_ptr::get;
return p_ == 0? 0: &this_type::p_;
}
#endif
// operator! is a Borland-specific workaround
bool operator! () const
{
@@ -207,6 +228,11 @@ template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U>
return static_cast<T *>(p.get());
}
template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p)
{
return const_cast<T *>(p.get());
}
template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
{
return dynamic_cast<T *>(p.get());
@@ -224,7 +250,7 @@ template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y>
#else
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200 && __SGI_STL_PORT)
# if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, <= 1200 && __SGI_STL_PORT)
// MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
using std::basic_ostream;
template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)

View File

@@ -15,6 +15,9 @@
#include <boost/assert.hpp>
#include <boost/checked_delete.hpp>
#include <boost/config.hpp> // in case ptrdiff_t not in std
#include <boost/detail/workaround.hpp>
#include <cstddef> // for std::ptrdiff_t
namespace boost
@@ -83,13 +86,32 @@ public:
// implicit conversion to "bool"
typedef T * (this_type::*unspecified_bool_type)() const;
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
operator bool () const
{
return ptr != 0;
}
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return ptr == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return ptr == 0? 0: &this_type::ptr;
}
#endif
bool operator! () const // never throws
{
return ptr == 0;

View File

@@ -14,6 +14,7 @@
#include <boost/assert.hpp>
#include <boost/checked_delete.hpp>
#include <boost/detail/workaround.hpp>
#ifndef BOOST_NO_AUTO_PTR
# include <memory> // for std::auto_ptr
@@ -102,13 +103,31 @@ public:
// implicit conversion to "bool"
typedef T * (this_type::*unspecified_bool_type)() const;
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
operator bool () const
{
return ptr != 0;
}
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return ptr == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return ptr == 0? 0: &this_type::ptr;
}
#endif
bool operator! () const // never throws
{
return ptr == 0;

View File

@@ -25,6 +25,7 @@
#include <boost/checked_delete.hpp>
#include <boost/detail/shared_count.hpp>
#include <boost/detail/workaround.hpp>
#include <cstddef> // for std::ptrdiff_t
#include <algorithm> // for std::swap
@@ -94,13 +95,32 @@ public:
// implicit conversion to "bool"
typedef T * (this_type::*unspecified_bool_type)() const;
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
operator bool () const
{
return px != 0;
}
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::px;
}
#endif
bool operator! () const // never throws
{
return px == 0;

View File

@@ -48,6 +48,7 @@ namespace detail
{
struct static_cast_tag {};
struct const_cast_tag {};
struct dynamic_cast_tag {};
struct polymorphic_cast_tag {};
@@ -68,6 +69,16 @@ template<> struct shared_ptr_traits<void const>
typedef void reference;
};
template<> struct shared_ptr_traits<void volatile>
{
typedef void reference;
};
template<> struct shared_ptr_traits<void const volatile>
{
typedef void reference;
};
#endif
// enable_shared_from_this support
@@ -77,7 +88,7 @@ template<class T, class Y> void sp_enable_shared_from_this(boost::enable_shared_
if(pe != 0) pe->_internal_weak_this._internal_assign(px, pn);
}
inline void sp_enable_shared_from_this(void const *, void const *, shared_count const &)
inline void sp_enable_shared_from_this(void const volatile *, void const volatile *, shared_count const &)
{
}
@@ -158,6 +169,11 @@ public:
{
}
template<class Y>
shared_ptr(shared_ptr<Y> const & r, detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
{
}
template<class Y>
shared_ptr(shared_ptr<Y> const & r, detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
{
@@ -246,13 +262,32 @@ public:
// implicit conversion to "bool"
typedef T * (this_type::*unspecified_bool_type)() const;
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
operator bool () const
{
return px != 0;
}
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::px;
}
#endif
// operator! is redundant, but some compilers need it
bool operator! () const // never throws
@@ -340,6 +375,11 @@ template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const
return shared_ptr<T>(r, detail::static_cast_tag());
}
template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r)
{
return shared_ptr<T>(r, detail::const_cast_tag());
}
template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)
{
return shared_ptr<T>(r, detail::dynamic_cast_tag());
@@ -387,7 +427,7 @@ template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> co
#else
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200 && __SGI_STL_PORT)
# if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, <= 1200 && __SGI_STL_PORT)
// MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
using std::basic_ostream;
template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p)
@@ -403,9 +443,10 @@ template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::
// get_deleter (experimental)
#if defined(__GNUC__) && (__GNUC__ < 3)
#if (defined(__GNUC__) && (__GNUC__ < 3)) || (defined(__EDG_VERSION__) && (__EDG_VERSION__ <= 238))
// g++ 2.9x doesn't allow static_cast<X const *>(void *)
// apparently EDG 2.38 also doesn't accept it
template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
{

View File

@@ -1,10 +1,11 @@
//
// smart_ptr.hpp
//
// For compatibility, this header includes the headers for the four "classic"
// smart pointer class templates.
// For convenience, this header includes the rest of the smart
// pointer library headers.
//
// Copyright (c) 1998-2002 boost.org
// Copyright (c) 2003 Peter Dimov
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
@@ -14,7 +15,15 @@
// http://www.boost.org/libs/smart_ptr/smart_ptr.htm
//
#include <boost/scoped_ptr.hpp>
#include <boost/config.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/shared_array.hpp>
#if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
# include <boost/weak_ptr.hpp>
# include <boost/intrusive_ptr.hpp>
# include <boost/enable_shared_from_this.hpp>
#endif

View File

@@ -1,51 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Boost Smart Pointer Library</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table border="1" bgcolor="#007F7F" cellpadding="2">
<tr>
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home</big></font></a></td>
<td><a href="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td>
<td><a href="../../people/people.htm"><font face="Arial" color="#FFFFFF"><big>People</big></font></a></td>
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ</big></font></a></td>
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More</big></font></a></td>
</tr>
</table>
<h1>Smart Pointer Library</h1>
<p>The smart pointer library includes five smart pointer class templates. Smart
pointers ease the management of memory dynamically allocated with C++ <b>new</b>
expressions. In addition, <b>scoped_ptr</b> can ease the management of memory
dynamically allocated in other ways.</p>
<ul>
<li>
<a href="smart_ptr.htm">Documentation</a> (HTML).</li>
<li>
Header <a href="../../boost/scoped_ptr.hpp">scoped_ptr.hpp</a>.</li>
<li>
Header <a href="../../boost/scoped_array.hpp">scoped_array.hpp</a>.</li>
<li>
Header <a href="../../boost/shared_ptr.hpp">shared_ptr.hpp</a>.</li>
<li>
Header <a href="../../boost/shared_array.hpp">shared_array.hpp</a>.</li>
<li>
Header <a href="../../boost/weak_ptr.hpp">weak_ptr.hpp</a>.</li>
<li>
Header <a href="../../boost/enable_shared_from_this.hpp">enable_shared_from_this.hpp</a>.</li>
<li>
Header <a href="../../boost/intrusive_ptr.hpp">intrusive_ptr.hpp</a>.</li>
<li>
Test program <a href="test/smart_ptr_test.cpp">smart_ptr_test.cpp</a>.</li>
<li>
Originally submitted by <a href="../../people/greg_colvin.htm">Greg Colvin</a> and
<a href="../../people/beman_dawes.html">Beman Dawes</a>, currently maintained
by <a href="../../people/peter_dimov.htm">Peter Dimov</a> and <a href="../../people/darin_adler.htm">
Darin Adler</a>.</li>
</ul>
<hr>
<p>$Date$</p>
</body>
</html>

9
index.html Normal file
View File

@@ -0,0 +1,9 @@
<html>
<head>
<meta http-equiv="refresh" content="0; URL=smart_ptr.htm">
</head>
<body>
Automatic redirection failed, please go to
<a href="smart_ptr.htm">smart_ptr.htm</a>.
</body>
</html>

View File

@@ -100,6 +100,9 @@
template&lt;class T, class U&gt;
intrusive_ptr&lt;T&gt; <A href="#static_pointer_cast" >static_pointer_cast</A>(intrusive_ptr&lt;U&gt; const &amp; r); // never throws
template&lt;class T, class U&gt;
intrusive_ptr&lt;T&gt; <A href="#const_pointer_cast" >const_pointer_cast</A>(intrusive_ptr&lt;U&gt; const &amp; r); // never throws
template&lt;class T, class U&gt;
intrusive_ptr&lt;T&gt; <A href="#dynamic_pointer_cast" >dynamic_pointer_cast</A>(intrusive_ptr&lt;U&gt; const &amp; r); // never throws
@@ -250,6 +253,13 @@ intrusive_ptr &amp; operator=(T * r);</pre>
<P><B>Returns:</B> <code>intrusive_ptr&lt;T&gt;(static_cast&lt;T*&gt;(r.get()))</code>.</P>
<P><B>Throws:</B> nothing.</P>
</BLOCKQUOTE>
<h3><a name="const_pointer_cast">const_pointer_cast</a></h3>
<pre>template&lt;class T, class U&gt;
intrusive_ptr&lt;T&gt; const_pointer_cast(intrusive_ptr&lt;U&gt; const &amp; r); // never throws</pre>
<BLOCKQUOTE>
<P><B>Returns:</B> <code>intrusive_ptr&lt;T&gt;(const_cast&lt;T*&gt;(r.get()))</code>.</P>
<P><B>Throws:</B> nothing.</P>
</BLOCKQUOTE>
<h3><a name="dynamic_pointer_cast">dynamic_pointer_cast</a></h3>
<pre>template&lt;class T, class U&gt;
intrusive_ptr&lt;T&gt; dynamic_pointer_cast(intrusive_ptr&lt;U&gt; const &amp; r);</pre>

View File

@@ -142,6 +142,9 @@ void bad()
template&lt;class T, class U&gt;
shared_ptr&lt;T&gt; <A href="#static_pointer_cast" >static_pointer_cast</A>(shared_ptr&lt;U&gt; const &amp; r); // never throws
template&lt;class T, class U&gt;
shared_ptr&lt;T&gt; <A href="#const_pointer_cast" >const_pointer_cast</A>(shared_ptr&lt;U&gt; const &amp; r); // never throws
template&lt;class T, class U&gt;
shared_ptr&lt;T&gt; <A href="#dynamic_pointer_cast" >dynamic_pointer_cast</A>(shared_ptr&lt;U&gt; const &amp; r); // never throws
@@ -473,6 +476,21 @@ q = p;
<p>will eventually result in undefined behavior, attempting to delete the same
object twice.</p>
</BLOCKQUOTE>
<h3><a name="const_pointer_cast">const_pointer_cast</a></h3>
<pre>template&lt;class T, class U&gt;
shared_ptr&lt;T&gt; const_pointer_cast(shared_ptr&lt;U&gt; const &amp; r); // never throws</pre>
<BLOCKQUOTE>
<P><STRONG>Requires:</STRONG> The expression <code>const_cast&lt;T*&gt;(r.get())</code>
must be well-formed.</P>
<P><B>Returns:</B> If <b>r</b> is <i>empty</i>, an <i>empty</i> <b>shared_ptr&lt;T&gt;</b>;
otherwise, a <STRONG>shared_ptr&lt;T&gt;</STRONG> object that stores a copy of <code>
const_cast&lt;T*&gt;(r.get())</code> and <i>shares ownership</i> with <b>r</b>.</P>
<P><B>Throws:</B> nothing.</P>
<P><B>Notes:</B> the seemingly equivalent expression</P>
<p><code>shared_ptr&lt;T&gt;(const_cast&lt;T*&gt;(r.get()))</code></p>
<p>will eventually result in undefined behavior, attempting to delete the same
object twice.</p>
</BLOCKQUOTE>
<h3><a name="dynamic_pointer_cast">dynamic_pointer_cast</a></h3>
<pre>template&lt;class T, class U&gt;
shared_ptr&lt;T&gt; dynamic_pointer_cast(shared_ptr&lt;U&gt; const &amp; r);</pre>

View File

@@ -11,8 +11,7 @@
subproject libs/smart_ptr/test ;
# bring in rules for testing
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
include testing.jam ;
import testing ;
# Make tests run by default.
DEPENDS all : smart_ptr ;

36
test/Jamfile.v2 Normal file
View File

@@ -0,0 +1,36 @@
# Boost.SmartPtr Library test Jamfile
#
# Copyright (c) 2003 Peter Dimov
# Copyright (c) 2003 Dave Abrahams
#
# 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.
# bring in rules for testing
import testing ;
{
test-suite "smart_ptr"
: [ run smart_ptr_test.cpp ]
[ run shared_ptr_basic_test.cpp : : : <toolset><gcc>:<cxxflags>-Wno-non-virtual-dtor ]
[ run shared_ptr_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-non-virtual-dtor ]
[ run weak_ptr_test.cpp ]
[ run shared_from_this_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-non-virtual-dtor ]
[ run get_deleter_test.cpp ]
[ run intrusive_ptr_test.cpp ]
[ compile-fail shared_ptr_assign_fail.cpp ]
;
# this one is too slow to run unless explicitly requested, and ALL
# tests are run by default when this file is subincluded from
# boost/status, so it's guarded from that case. It will only be
# built from this directory when the targets "test" (all tests) or
# "shared_ptr_alloc_test" are requested.
#!!!
#if [ in-invocation-subdir ]
#{
# run shared_ptr_alloc_test.cpp ;
#}
}

View File

@@ -1,4 +1,7 @@
#if defined(_MSC_VER) && !defined(__ICL) && !defined(__COMO__)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -6,6 +9,11 @@
#pragma warning(disable: 4355) // 'this' : used in base member initializer list
#pragma warning(disable: 4511) // copy constructor could not be generated
#pragma warning(disable: 4512) // assignment operator could not be generated
#if (BOOST_MSVC >= 1310)
#pragma warning(disable: 4675) // resolved overload found with Koenig lookup
#endif
#endif
//

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL) && !defined(__COMO__)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -67,18 +69,20 @@ void test()
}
void test2();
void test3();
int main()
{
test();
test2();
test3();
return boost::report_errors();
}
// virtual inheritance from Y to stress the implementation
// (prevents Y* -> impl* casts)
// virtual inheritance to stress the implementation
// (prevents Y* -> impl*, enable_shared_from_this<impl>* -> impl* casts)
class impl: public X, public virtual Y, public boost::enable_shared_from_this<impl>
class impl: public X, public virtual Y, public virtual boost::enable_shared_from_this<impl>
{
public:
@@ -110,3 +114,41 @@ void test2()
{
boost::shared_ptr<Y> pi(static_cast<impl2*>(0));
}
//
struct V: public boost::enable_shared_from_this<V>
{
};
void test3()
{
boost::shared_ptr<V> p(new V);
boost::shared_ptr<V> q = p->shared_from_this();
BOOST_TEST(p == q);
BOOST_TEST(!(p < q) && !(q < p));
V v2(*p);
try
{
boost::shared_ptr<V> r = v2.shared_from_this();
BOOST_ERROR("v2.shared_from_this() failed to throw");
}
catch(boost::bad_weak_ptr const &)
{
}
try
{
*p = V();
boost::shared_ptr<V> r = p->shared_from_this();
BOOST_TEST(p == r);
BOOST_TEST(!(p < r) && !(r < p));
}
catch(boost::bad_weak_ptr const &)
{
BOOST_ERROR("p->shared_from_this() threw bad_weak_ptr after *p = V()");
}
}

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion

View File

@@ -1,3 +1,19 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#pragma warning(disable: 4355) // 'this' : used in base member initializer list
#if (BOOST_MSVC >= 1310)
#pragma warning(disable: 4675) // resolved overload found with Koenig lookup
#endif
#endif
//
// shared_ptr_basic_test.cpp
//

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL) && !defined(__COMO__)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion

View File

@@ -1,9 +1,17 @@
#if defined(_MSC_VER) && !defined(__ICL) && !defined(__COMO__)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#pragma warning(disable: 4355) // 'this' : used in base member initializer list
#if (BOOST_MSVC >= 1310)
#pragma warning(disable: 4675) // resolved overload found with Koenig lookup
#endif
#endif
//
@@ -123,10 +131,31 @@ private:
long Y::instances = 0;
template<class T> void pc0_test(T * p)
{
BOOST_TEST(p == 0);
boost::shared_ptr<T> pt(p);
BOOST_TEST(pt? false: true);
BOOST_TEST(!pt);
BOOST_TEST(pt.get() == 0);
BOOST_TEST(pt.use_count() == 1);
BOOST_TEST(pt.unique());
}
void pointer_constructor()
{
pc0_test(static_cast<int*>(0));
#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1300)
pc0_test(static_cast<int const*>(0));
pc0_test(static_cast<int volatile*>(0));
pc0_test(static_cast<int const volatile*>(0));
#endif
{
boost::shared_ptr<int> pi(static_cast<int*>(0));
boost::shared_ptr<int const> pi(static_cast<int*>(0));
BOOST_TEST(pi? false: true);
BOOST_TEST(!pi);
BOOST_TEST(pi.get() == 0);
@@ -135,7 +164,7 @@ void pointer_constructor()
}
{
boost::shared_ptr<int const> pi(static_cast<int*>(0));
boost::shared_ptr<int volatile> pi(static_cast<int*>(0));
BOOST_TEST(pi? false: true);
BOOST_TEST(!pi);
BOOST_TEST(pi.get() == 0);
@@ -161,14 +190,10 @@ void pointer_constructor()
BOOST_TEST(pv.unique());
}
{
boost::shared_ptr<X> px(static_cast<X*>(0));
BOOST_TEST(px? false: true);
BOOST_TEST(!px);
BOOST_TEST(px.get() == 0);
BOOST_TEST(px.use_count() == 1);
BOOST_TEST(px.unique());
}
pc0_test(static_cast<X*>(0));
pc0_test(static_cast<X const*>(0));
pc0_test(static_cast<X volatile*>(0));
pc0_test(static_cast<X const volatile*>(0));
{
boost::shared_ptr<X const> px(static_cast<X*>(0));
@@ -817,6 +842,10 @@ void weak_ptr_constructor()
}
}
#if defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB < 306)
# define BOOST_OLD_AUTO_PTR
#endif
void auto_ptr_constructor()
{
{
@@ -940,7 +969,7 @@ void auto_ptr_constructor()
BOOST_TEST(pi.unique());
BOOST_TEST(*pi == 7);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -956,7 +985,7 @@ void auto_ptr_constructor()
BOOST_TEST(pi.unique());
BOOST_TEST(*pi == 7);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -971,7 +1000,7 @@ void auto_ptr_constructor()
BOOST_TEST(pv.use_count() == 1);
BOOST_TEST(pv.unique());
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -986,7 +1015,7 @@ void auto_ptr_constructor()
BOOST_TEST(pv.use_count() == 1);
BOOST_TEST(pv.unique());
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -1004,7 +1033,7 @@ void auto_ptr_constructor()
BOOST_TEST(px.unique());
BOOST_TEST(X::instances == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -1022,7 +1051,7 @@ void auto_ptr_constructor()
BOOST_TEST(px.unique());
BOOST_TEST(X::instances == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -1040,7 +1069,7 @@ void auto_ptr_constructor()
BOOST_TEST(pv.unique());
BOOST_TEST(X::instances == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -1058,7 +1087,7 @@ void auto_ptr_constructor()
BOOST_TEST(pv.unique());
BOOST_TEST(X::instances == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -1078,7 +1107,7 @@ void auto_ptr_constructor()
BOOST_TEST(X::instances == 1);
BOOST_TEST(Y::instances == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -1098,7 +1127,7 @@ void auto_ptr_constructor()
BOOST_TEST(X::instances == 1);
BOOST_TEST(Y::instances == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p.get() == 0);
#endif
}
@@ -1407,7 +1436,7 @@ void auto_ptr_assignment()
BOOST_TEST(p1.get() == p);
BOOST_TEST(p1.use_count() == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p3.get() == 0);
#endif
@@ -1436,7 +1465,7 @@ void auto_ptr_assignment()
BOOST_TEST(p1.get() == p);
BOOST_TEST(p1.use_count() == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p3.get() == 0);
#endif
@@ -1473,7 +1502,7 @@ void auto_ptr_assignment()
BOOST_TEST(X::instances == 1);
BOOST_TEST(Y::instances == 1);
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
#if !defined(BOOST_OLD_AUTO_PTR)
BOOST_TEST(p3.get() == 0);
#endif
@@ -2371,6 +2400,57 @@ void test()
} // namespace n_static_cast
namespace n_const_cast
{
struct X;
void test()
{
{
boost::shared_ptr<void const volatile> px;
boost::shared_ptr<void> px2 = boost::const_pointer_cast<void>(px);
BOOST_TEST(px2.get() == 0);
}
{
boost::shared_ptr<int const volatile> px;
boost::shared_ptr<int> px2 = boost::const_pointer_cast<int>(px);
BOOST_TEST(px2.get() == 0);
}
{
boost::shared_ptr<X const volatile> px;
boost::shared_ptr<X> px2 = boost::const_pointer_cast<X>(px);
BOOST_TEST(px2.get() == 0);
}
{
boost::shared_ptr<void const volatile> px(new int);
boost::shared_ptr<void> px2 = boost::const_pointer_cast<void>(px);
BOOST_TEST(px.get() == px2.get());
BOOST_TEST(!(px < px2 || px2 < px));
BOOST_TEST(px.use_count() == 2);
BOOST_TEST(px2.use_count() == 2);
}
{
boost::shared_ptr<int const volatile> px(new int);
boost::shared_ptr<int> px2 = boost::const_pointer_cast<int>(px);
BOOST_TEST(px.get() == px2.get());
BOOST_TEST(!(px < px2 || px2 < px));
BOOST_TEST(px.use_count() == 2);
BOOST_TEST(px2.use_count() == 2);
}
}
} // namespace n_const_cast
namespace n_dynamic_cast
{
@@ -3137,6 +3217,7 @@ int main()
n_swap::test();
n_comparison::test();
n_static_cast::test();
n_const_cast::test();
n_dynamic_cast::test();
n_map::test();

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL) && !defined(__COMO__)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion

View File

@@ -1,20 +1,9 @@
#if defined(_MSC_VER) && !defined(__ICL) && !defined(__COMO__)
# pragma warning(disable: 4786) // identifier truncated in debug info
# pragma warning(disable: 4710) // function not inlined
# pragma warning(disable: 4711) // function selected for automatic inline expansion
# pragma warning(disable: 4514) // unreferenced inline removed
#endif
#ifdef __BORLANDC__
# pragma warn -8092 // template argument passed to 'find' is not an iterator
#endif
// smart pointer test program ----------------------------------------------//
// (C) Copyright Beman Dawes 1998, 1999. 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.
// Copyright Beman Dawes 1998, 1999.
// See accompanying license for terms and conditions of use.
// See http://www.boost.org/libs/smart_ptr for documentation.
// Revision History
// 24 May 01 use Boost test library for error detection, reporting, add tests
@@ -24,6 +13,25 @@
// 20 Jul 99 header name changed to .hpp
// 20 Apr 99 additional error tests added.
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
# pragma warning(disable: 4786) // identifier truncated in debug info
# pragma warning(disable: 4710) // function not inlined
# pragma warning(disable: 4711) // function selected for automatic inline expansion
# pragma warning(disable: 4514) // unreferenced inline removed
#if (BOOST_MSVC >= 1310)
# pragma warning(disable: 4675) // resolved overload found with Koenig lookup
#endif
#endif
#ifdef __BORLANDC__
# pragma warn -8092 // template argument passed to 'find' is not an iterator
#endif
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
#include <boost/shared_ptr.hpp>

View File

@@ -1,9 +1,17 @@
#if defined(_MSC_VER) && !defined(__ICL) && !defined(__COMO__)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#pragma warning(disable: 4355) // 'this' : used in base member initializer list
#if (BOOST_MSVC >= 1310)
#pragma warning(disable: 4675) // resolved overload found with Koenig lookup
#endif
#endif
//