some new boost files that we now use

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2080 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-06-01 11:56:18 +00:00
parent 07ea5f51f0
commit b9a9f9fca1
9 changed files with 1660 additions and 45 deletions

View File

@ -1,3 +1,15 @@
2001-06-01 Lars Gullik Bjønnes <larsbj@birdstep.com>
* boost/utility.hpp: update
* boost/static_assert.hpp: update
* boost/smart_ptr.hpp: update
* boost/config.hpp: update
* boost/detail/limits.hpp: new file
* boost/limits.hpp: new file
* boost/integer.hpp: new file
* boost/crc.hpp: new file
2001-05-31 Lars Gullik Bjønnes <larsbj@birdstep.com>
* boost/re_detail/regex_synch.hpp: delete file

View File

@ -11,6 +11,7 @@
// http://www.boost.org/libs/config
// Revision History (excluding minor changes for specific compilers)
// 29 Mar 01 BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS (Daryle Walker)
// 16 Mar 01 Added BOOST_VERSION (Jens Maurer)
// 06 Mar 01 Refactored EDG checks for Intel C++ (Dave Abrahams)
// 04 Mar 01 Factored EDG checks, added BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
@ -87,6 +88,9 @@
// parameters cannot have a dependent type, for example
// "template<class T, typename T::type value> class X { ... };"
// BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS: Can only use deduced
// template arguments when calling function template instantiations.
// BOOST_NO_INCLASS_MEMBER_INITIALIZATION: Compiler violates std::9.4.2/4.
// BOOST_NO_INT64_T: <boost/cstdint.hpp> does not support 64-bit integer
@ -371,7 +375,7 @@
# if __MWERKS__ <= 0x2401 // 6.2
# define BOOST_NO_MEMBER_TEMPLATE_FRIENDS
# endif
# if __MWERKS__ <= 0x2301 // 5.3?
# if __MWERKS__ <= 0x2301 // 5.3
# define BOOST_NO_POINTER_TO_MEMBER_CONST
# define BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
# endif
@ -441,6 +445,7 @@
# define BOOST_NO_INCLASS_MEMBER_INITIALIZATION
# define BOOST_NO_PRIVATE_IN_AGGREGATE
# define BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
# define BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS
# define BOOST_NO_INTEGRAL_INT64_T
# define BOOST_NO_INTRINSIC_WCHAR_T

1061
boost/boost/crc.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,443 @@
/*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/* NOTE: This is not portable code. Parts of numeric_limits<> are
* inherently machine-dependent, and this file is written for the MIPS
* architecture and the SGI MIPSpro C++ compiler. Parts of it (in
* particular, some of the characteristics of floating-point types)
* are almost certainly incorrect for any other platform.
*/
/*
* Revision history:
* 13 Apr 2001:
* Added powerpc to the big endian family. (Jeremy Siek)
* 5 Apr 2001:
* Added sparc (big endian) processor support (John Maddock).
* Initial sub:
* Modified by Jens Maurer for gcc 2.95 on x86.
*/
#ifndef BOOST_SGI_CPP_LIMITS
#define BOOST_SGI_CPP_LIMITS
#include <climits>
#include <cfloat>
#include <boost/config.hpp>
#if defined(__sparc) || defined(__sparc__) || defined(__powerpc__) || defined(__hppa)
#define BOOST_BIG_ENDIAN
#elif !defined(__i386__)
#error The file boost/detail/limits.hpp needs to be set up for your CPU type.
#endif
namespace std {
enum float_round_style {
round_indeterminate = -1,
round_toward_zero = 0,
round_to_nearest = 1,
round_toward_infinity = 2,
round_toward_neg_infinity = 3
};
enum float_denorm_style {
denorm_indeterminate = -1,
denorm_absent = 0,
denorm_present = 1
};
// The C++ standard (section 18.2.1) requires that some of the members of
// numeric_limits be static const data members that are given constant-
// initializers within the class declaration. On compilers where the
// BOOST_NO_INCLASS_MEMBER_INITIALIZATION macro is defined, it is impossible to write
// a standard-conforming numeric_limits class.
//
// There are two possible workarounds: either initialize the data
// members outside the class, or change them from data members to
// enums. Neither workaround is satisfactory: the former makes it
// impossible to use the data members in constant-expressions, and the
// latter means they have the wrong type and that it is impossible to
// take their addresses. We choose the former workaround.
#ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
# define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
enum { __mem_name = __mem_value }
#else /* BOOST_NO_INCLASS_MEMBER_INITIALIZATION */
# define BOOST_STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
static const __mem_type __mem_name = __mem_value
#endif /* BOOST_NO_INCLASS_MEMBER_INITIALIZATION */
// Base class for all specializations of numeric_limits.
template <class __number>
class _Numeric_limits_base {
public:
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, false);
static __number min() throw() { return __number(); }
static __number max() throw() { return __number(); }
BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, 0);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, 0);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 0);
static __number epsilon() throw() { return __number(); }
static __number round_error() throw() { return __number(); }
BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, 0);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, 0);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, 0);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, 0);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
has_denorm,
denorm_absent);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
static __number infinity() throw() { return __number(); }
static __number quiet_NaN() throw() { return __number(); }
static __number signaling_NaN() throw() { return __number(); }
static __number denorm_min() throw() { return __number(); }
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style,
round_style,
round_toward_zero);
};
// Base class for integers.
template <class _Int,
_Int __imin,
_Int __imax,
int __idigits = -1>
class _Integer_limits : public _Numeric_limits_base<_Int>
{
public:
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
static _Int min() throw() { return __imin; }
static _Int max() throw() { return __imax; }
BOOST_STL_DECLARE_LIMITS_MEMBER(int,
digits,
(__idigits < 0) ? (int)(sizeof(_Int) * CHAR_BIT)
- (__imin == 0 ? 0 : 1)
: __idigits);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, (digits * 301) / 1000);
// log 2 = 0.301029995664...
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, __imin != 0);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_integer, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_exact, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, true);
};
#if defined(BOOST_BIG_ENDIAN)
template<class Number, unsigned int Word>
struct float_helper{
static Number get_word() throw() {
// sizeof(long double) == 16
const unsigned int _S_word[4] = { Word, 0, 0, 0 };
return *reinterpret_cast<const Number*>(&_S_word);
}
};
#else
template<class Number, unsigned int Word>
struct float_helper{
static Number get_word() throw() {
// sizeof(long double) == 12, but only 10 bytes significant
const unsigned int _S_word[4] = { 0, 0, 0, Word };
return *reinterpret_cast<const Number*>(
reinterpret_cast<const char *>(&_S_word)+16-
(sizeof(Number) == 12 ? 10 : sizeof(Number)));
}
};
#endif
// Base class for floating-point numbers.
template <class __number,
int __Digits, int __Digits10,
int __MinExp, int __MaxExp,
int __MinExp10, int __MaxExp10,
unsigned int __InfinityWord,
unsigned int __QNaNWord, unsigned int __SNaNWord,
bool __IsIEC559,
float_round_style __RoundStyle>
class _Floating_limits : public _Numeric_limits_base<__number>
{
public:
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, __Digits);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, __Digits10);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_signed, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent, __MinExp);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent, __MaxExp);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, __MinExp10);
BOOST_STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, __MaxExp10);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
has_denorm,
denorm_indeterminate);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
static __number infinity() throw() {
return float_helper<__number, __InfinityWord>::get_word();
}
static __number quiet_NaN() throw() {
return float_helper<__number,__QNaNWord>::get_word();
}
static __number signaling_NaN() throw() {
return float_helper<__number,__SNaNWord>::get_word();
}
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, __IsIEC559);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, traps, false /* was: true */ );
BOOST_STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
BOOST_STL_DECLARE_LIMITS_MEMBER(float_round_style, round_style, __RoundStyle);
};
// Class numeric_limits
// The unspecialized class.
template<class T>
class numeric_limits : public _Numeric_limits_base<T> {};
// Specializations for all built-in integral types.
template<>
class numeric_limits<bool>
: public _Integer_limits<bool, false, true, 0>
{};
template<>
class numeric_limits<char>
: public _Integer_limits<char, CHAR_MIN, CHAR_MAX>
{};
template<>
class numeric_limits<signed char>
: public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX>
{};
template<>
class numeric_limits<unsigned char>
: public _Integer_limits<unsigned char, 0, UCHAR_MAX>
{};
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
#if !defined(WCHAR_MAX) || !defined(WCHAR_MIN)
#if !defined(_WIN32) && !defined(__CYGWIN__)
template<>
class numeric_limits<wchar_t>
: public _Integer_limits<wchar_t, INT_MIN, INT_MAX>
{};
#else
template<>
class numeric_limits<wchar_t>
: public _Integer_limits<wchar_t, 0, USHRT_MAX>
{};
#endif
#else
template<>
class numeric_limits<wchar_t>
: public _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX>
{};
#endif
#endif
template<>
class numeric_limits<short>
: public _Integer_limits<short, SHRT_MIN, SHRT_MAX>
{};
template<>
class numeric_limits<unsigned short>
: public _Integer_limits<unsigned short, 0, USHRT_MAX>
{};
template<>
class numeric_limits<int>
: public _Integer_limits<int, INT_MIN, INT_MAX>
{};
template<>
class numeric_limits<unsigned int>
: public _Integer_limits<unsigned int, 0, UINT_MAX>
{};
template<>
class numeric_limits<long>
: public _Integer_limits<long, LONG_MIN, LONG_MAX>
{};
template<>
class numeric_limits<unsigned long>
: public _Integer_limits<unsigned long, 0, ULONG_MAX>
{};
#ifdef __GNUC__
// Some compilers have long long, but don't define the
// LONGLONG_MIN and LONGLONG_MAX macros in limits.h. This
// assumes that long long is 64 bits.
#if !defined(LONGLONG_MIN) && !defined(LONGLONG_MAX) \
&& !defined(ULONGLONG_MAX)
#define ULONGLONG_MAX 0xffffffffffffffffLLU
#define LONGLONG_MAX 0x7fffffffffffffffLL
#define LONGLONG_MIN (-LONGLONG_MAX - 1)
#endif
template<>
class numeric_limits<long long>
: public _Integer_limits<long long, LONGLONG_MIN, LONGLONG_MAX>
{};
template<>
class numeric_limits<unsigned long long>
: public _Integer_limits<unsigned long long, 0, ULONGLONG_MAX>
{};
#endif /* __GNUC__ */
// Specializations for all built-in floating-point type.
template<> class numeric_limits<float>
: public _Floating_limits<float,
FLT_MANT_DIG, // Binary digits of precision
FLT_DIG, // Decimal digits of precision
FLT_MIN_EXP, // Minimum exponent
FLT_MAX_EXP, // Maximum exponent
FLT_MIN_10_EXP, // Minimum base 10 exponent
FLT_MAX_10_EXP, // Maximum base 10 exponent
#if defined(BOOST_BIG_ENDIAN)
0x7f80 << (sizeof(int)*CHAR_BIT-16), // Last word of +infinity
0x7f81 << (sizeof(int)*CHAR_BIT-16), // Last word of quiet NaN
0x7fc1 << (sizeof(int)*CHAR_BIT-16), // Last word of signaling NaN
#else
0x7f800000u, // Last word of +infinity
0x7f810000u, // Last word of quiet NaN
0x7fc10000u, // Last word of signaling NaN
#endif
true, // conforms to iec559
round_to_nearest>
{
public:
static float min() throw() { return FLT_MIN; }
static float denorm_min() throw() { return FLT_MIN; }
static float max() throw() { return FLT_MAX; }
static float epsilon() throw() { return FLT_EPSILON; }
static float round_error() throw() { return 0.5f; } // Units: ulps.
};
template<> class numeric_limits<double>
: public _Floating_limits<double,
DBL_MANT_DIG, // Binary digits of precision
DBL_DIG, // Decimal digits of precision
DBL_MIN_EXP, // Minimum exponent
DBL_MAX_EXP, // Maximum exponent
DBL_MIN_10_EXP, // Minimum base 10 exponent
DBL_MAX_10_EXP, // Maximum base 10 exponent
#if defined(BOOST_BIG_ENDIAN)
0x7ff0 << (sizeof(int)*CHAR_BIT-16), // Last word of +infinity
0x7ff1 << (sizeof(int)*CHAR_BIT-16), // Last word of quiet NaN
0x7ff9 << (sizeof(int)*CHAR_BIT-16), // Last word of signaling NaN
#else
0x7ff00000u, // Last word of +infinity
0x7ff10000u, // Last word of quiet NaN
0x7ff90000u, // Last word of signaling NaN
#endif
true, // conforms to iec559
round_to_nearest>
{
public:
static double min() throw() { return DBL_MIN; }
static double denorm_min() throw() { return DBL_MIN; }
static double max() throw() { return DBL_MAX; }
static double epsilon() throw() { return DBL_EPSILON; }
static double round_error() throw() { return 0.5; } // Units: ulps.
};
template<> class numeric_limits<long double>
: public _Floating_limits<long double,
LDBL_MANT_DIG, // Binary digits of precision
LDBL_DIG, // Decimal digits of precision
LDBL_MIN_EXP, // Minimum exponent
LDBL_MAX_EXP, // Maximum exponent
LDBL_MIN_10_EXP,// Minimum base 10 exponent
LDBL_MAX_10_EXP,// Maximum base 10 exponent
#if defined(BOOST_BIG_ENDIAN)
0x7ff0 << (sizeof(int)*CHAR_BIT-16), // Last word of +infinity
0x7ff1 << (sizeof(int)*CHAR_BIT-16), // Last word of quiet NaN
0x7ff9 << (sizeof(int)*CHAR_BIT-16), // Last word of signaling NaN
#else
0x7fff8000u, // Last word of +infinity
0x7fffc000u, // Last word of quiet NaN
0x7fff9000u, // Last word of signaling NaN
#endif
false, // Doesn't conform to iec559
round_to_nearest>
{
public:
static long double min() throw() { return LDBL_MIN; }
static long double denorm_min() throw() { return LDBL_MIN; }
static long double max() throw() { return LDBL_MAX; }
static long double epsilon() throw() { return LDBL_EPSILON; }
static long double round_error() throw() { return 4; } // Units: ulps.
};
} // namespace std
#endif /* BOOST_SGI_CPP_LIMITS */
// Local Variables:
// mode:C++
// End:

85
boost/boost/integer.hpp Normal file
View File

@ -0,0 +1,85 @@
// boost integer.hpp header file -------------------------------------------//
// (C) Copyright Beman Dawes 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.
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
// 30 Jul 00 Add typename syntax fix (Jens Maurer)
// 28 Aug 99 Initial version
#ifndef BOOST_INTEGER_HPP
#define BOOST_INTEGER_HPP
#include <boost/limits.hpp>
namespace boost
{
// Helper templates ------------------------------------------------------//
// fast integers from least integers
// int_fast_t<> works correctly for unsigned too, in spite of the name.
template< typename LeastInt >
struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
// convert category to type
template< int Category > struct int_least_helper {}; // default is empty
// specializatons: 1=long, 2=int, 3=short, 4=signed char,
// 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long
// no specializations for 0 and 5: requests for a type > long are in error
template<> struct int_least_helper<1> { typedef long least; };
template<> struct int_least_helper<2> { typedef int least; };
template<> struct int_least_helper<3> { typedef short least; };
template<> struct int_least_helper<4> { typedef signed char least; };
template<> struct int_least_helper<6> { typedef unsigned long least; };
template<> struct int_least_helper<7> { typedef unsigned int least; };
template<> struct int_least_helper<8> { typedef unsigned short least; };
template<> struct int_least_helper<9> { typedef unsigned char least; };
// integer templates specifying number of bits ---------------------------//
// signed
template< int Bits > // bits (including sign) required
struct int_t
{
typedef typename int_least_helper
<
(Bits-1 <= std::numeric_limits<long>::digits) +
(Bits-1 <= std::numeric_limits<int>::digits) +
(Bits-1 <= std::numeric_limits<short>::digits) +
(Bits-1 <= std::numeric_limits<signed char>::digits)
>::least least;
typedef typename int_fast_t<least>::fast fast;
};
// unsigned
template< int Bits > // bits required
struct uint_t
{
typedef typename int_least_helper
<
5 +
(Bits <= std::numeric_limits<unsigned long>::digits) +
(Bits <= std::numeric_limits<unsigned int>::digits) +
(Bits <= std::numeric_limits<unsigned short>::digits) +
(Bits <= std::numeric_limits<unsigned char>::digits)
>::least least;
typedef typename int_fast_t<least>::fast fast;
// int_fast_t<> works correctly for unsigned too, in spite of the name.
};
// The same dispatching technique can be used to select types based on
// values. That will be added once boost::integer_traits is available.
} // namespace boost
#endif // BOOST_INTEGER_HPP

20
boost/boost/limits.hpp Normal file
View File

@ -0,0 +1,20 @@
// (C) Copyright Boost.org 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.
//
// use this header as a workaround for missing <limits>
#ifndef BOOST_LIMITS
#define BOOST_LIMITS
#include <boost/config.hpp>
#ifdef BOOST_NO_LIMITS
#include <boost/detail/limits.hpp>
#else
#include <limits>
#endif
#endif

View File

@ -95,17 +95,9 @@ template<typename T> class scoped_ptr : noncopyable {
explicit scoped_ptr( T* p=0 ) : ptr(p) {} // never throws
~scoped_ptr() { checked_delete(ptr); }
void reset( T* p=0 ) { if ( ptr != p ) { checked_delete(ptr); ptr =
p; } }
void reset( T* p=0 ) { if ( ptr != p ) { checked_delete(ptr); ptr = p; } }
T& operator*() const { return *ptr; } // never throws
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable:4284) // return type for 'identifier::operator->' is not a UDT or reference to a UDT. Will produce errors if applied using infix notation
#endif
T* operator->() const { return ptr; } // never throws
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
T* get() const { return ptr; } // never throws
#ifdef BOOST_SMART_PTR_CONVERSION
// get() is safer! Define BOOST_SMART_PTR_CONVERSION at your own risk!
@ -127,9 +119,10 @@ template<typename T> class scoped_array : noncopyable {
typedef T element_type;
explicit scoped_array( T* p=0 ) : ptr(p) {} // never throws
~scoped_array() { delete [] ptr; }
~scoped_array() { checked_array_delete(ptr); }
void reset( T* p=0 ) { if ( ptr != p ) {delete [] ptr; ptr=p;} }
void reset( T* p=0 ) { if ( ptr != p )
{checked_array_delete(ptr); ptr=p;} }
T* get() const { return ptr; } // never throws
#ifdef BOOST_SMART_PTR_CONVERSION
@ -153,7 +146,7 @@ template<typename T> class shared_ptr {
explicit shared_ptr(T* p =0) : px(p) {
#ifndef LYX_NO_EXCEPTIONS
try { pn = new long(1); } // fix: prevent leak if new throws
catch (...) { delete p; throw; }
catch (...) { checked_delete(p); throw; }
#else
pn = new long(1);
assert(pn != 0);
@ -192,7 +185,7 @@ template<typename T> class shared_ptr {
template<typename Y>
shared_ptr& operator=(std::auto_ptr<Y>& r) {
// code choice driven by guarantee of "no effect if new throws"
if (*pn == 1) { delete px; }
if (*pn == 1) { checked_delete(px); }
else { // allocate new reference counter
long * tmp = new long(1); // may throw
--*pn; // only decrement once danger of new throwing is past
@ -211,7 +204,7 @@ template<typename T> class shared_ptr {
shared_ptr& operator=(std::auto_ptr<T>& r) {
// code choice driven by guarantee of "no effect if new throws"
if (*pn == 1) { delete px; }
if (*pn == 1) { checked_delete(px); }
else { // allocate new reference counter
long * tmp = new long(1); // may throw
--*pn; // only decrement once danger of new throwing is past
@ -225,13 +218,13 @@ template<typename T> class shared_ptr {
void reset(T* p=0) {
if ( px == p ) return; // fix: self-assignment safe
if (--*pn == 0) { delete px; }
if (--*pn == 0) { checked_delete(px); }
else { // allocate new reference counter
#ifndef LYX_NO_EXCEPTIONS
try { pn = new long; } // fix: prevent leak if new throws
catch (...) {
++*pn; // undo effect of --*pn above to meet effects guarantee
delete p;
checked_delete(p);
throw;
} // catch
#else
@ -244,14 +237,7 @@ template<typename T> class shared_ptr {
} // reset
T& operator*() const { return *px; } // never throws
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable:4284) // return type for 'identifier::operator->' is not a UDT or reference to a UDT. Will produce errors if applied using infix notation
#endif
T* operator->() const { return px; } // never throws
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
T* get() const { return px; } // never throws
#ifdef BOOST_SMART_PTR_CONVERSION
// get() is safer! Define BOOST_SMART_PTR_CONVERSION at your own risk!
@ -279,13 +265,15 @@ template<typename T> class shared_ptr {
template<typename Y> friend class shared_ptr;
#endif
void dispose() { if (--*pn == 0) { delete px; delete pn; } }
void dispose() { if (--*pn == 0) { checked_delete(px); delete pn; } }
void share(T* rpx, long* rpn) {
if (pn != rpn) {
if (pn != rpn) { // Q: why not px != rpx? A: fails when both == 0
++*rpn; // done before dispose() in case rpn transitively
// dependent on *this (bug reported by Ken Johnson)
dispose();
px = rpx;
++*(pn = rpn);
pn = rpn;
}
} // share
}; // shared_ptr
@ -311,7 +299,7 @@ template<typename T> class shared_array {
explicit shared_array(T* p =0) : px(p) {
#ifndef LYX_NO_EXCEPTIONS
try { pn = new long(1); } // fix: prevent leak if new throws
catch (...) { delete [] p; throw; }
catch (...) { checked_array_delete(p); throw; }
#else
pn = new long(1);
assert(pn != 0);
@ -324,23 +312,25 @@ template<typename T> class shared_array {
~shared_array() { dispose(); }
shared_array& operator=(const shared_array& r) {
if (pn != r.pn) {
if (pn != r.pn) { // Q: why not px != r.px? A: fails when both px == 0
++*r.pn; // done before dispose() in case r.pn transitively
// dependent on *this (bug reported by Ken Johnson)
dispose();
px = r.px;
++*(pn = r.pn);
pn = r.pn;
}
return *this;
} // operator=
void reset(T* p=0) {
if ( px == p ) return; // fix: self-assignment safe
if (--*pn == 0) { delete [] px; }
if (--*pn == 0) { checked_array_delete(px); }
else { // allocate new reference counter
#ifndef LYX_NO_EXCEPTIONS
try { pn = new long; } // fix: prevent leak if new throws
catch (...) {
++*pn; // undo effect of --*pn above to meet effects guarantee
delete [] p;
checked_array_delete(p);
throw;
} // catch
#else
@ -371,7 +361,7 @@ template<typename T> class shared_array {
T* px; // contained pointer
long* pn; // ptr to reference counter
void dispose() { if (--*pn == 0) { delete [] px; delete pn; } }
void dispose() { if (--*pn == 0) { checked_array_delete(px); delete pn; } }
}; // shared_array
@ -431,6 +421,10 @@ template<typename T>
#endif // ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif // BOOST_SMART_PTR_HPP

View File

@ -53,6 +53,9 @@ template<int x> struct static_assert_test{};
// an eye catching error message. The result of the sizeof expression is either
// used as an enum initialiser, or as a template argument depending which version
// is in use...
// Note that the argument to the assert is explicitly cast to bool using old-
// style casts: too many compilers currently have problems with static_cast
// when used inside integral constant expressions.
//
#if !defined(BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS) && !defined(__MWERKS__)
#ifndef BOOST_MSVC

View File

@ -39,24 +39,16 @@ namespace boost
template< typename T >
inline void checked_delete(T * x)
{
# if !((defined(__BORLANDC__) && __BORLANDC__ <= 0x0551) || (defined(__ICL) && __ICL <= 500))
BOOST_STATIC_ASSERT( sizeof(T) ); // assert type complete at point
// of instantiation
# else
sizeof(T); // force error if type incomplete
# endif
BOOST_STATIC_ASSERT( sizeof(T) != 0 ); // assert type complete at point
// of instantiation
delete x;
}
template< typename T >
inline void checked_array_delete(T * x)
{
# if !((defined(__BORLANDC__) && __BORLANDC__ <= 0x0551) || (defined(__ICL) && __ICL <= 500))
BOOST_STATIC_ASSERT( sizeof(T) ); // assert type complete at point
// of instantiation
# else
sizeof(T); // force error if type incomplete
# endif
BOOST_STATIC_ASSERT( sizeof(T) != 0 ); // assert type complete at point
// of instantiation
delete [] x;
}