Compare commits

..

16 Commits

Author SHA1 Message Date
nobody c35f326490 This commit was manufactured by cvs2svn to create tag
'Version_1_28_0'.

[SVN r13949]
2002-05-16 13:26:18 +00:00
nobody 175c00ea3e This commit was manufactured by cvs2svn to create branch 'RC_1_28_0'.
[SVN r13795]
2002-05-10 04:34:27 +00:00
Darin Adler 23e5f7cca3 New casts for smart pointers.
[SVN r12743]
2002-02-06 19:42:04 +00:00
Dave Abrahams 0a560dd543 Suppress warnings for MinGW
[SVN r12588]
2002-01-30 20:02:11 +00:00
Beman Dawes 8cbbd7c551 Fix sstream config issue plus update license
[SVN r12378]
2002-01-20 20:08:46 +00:00
Beman Dawes 805d5df9cb remove tabs
[SVN r12357]
2002-01-19 15:49:53 +00:00
Jeremy Siek bd16c171e6 fixed lexical cast g++ sstream problem
[SVN r11592]
2001-11-05 16:43:43 +00:00
Beman Dawes 66235f4b9d Fix minor non-std HTML </a> nesting
[SVN r11589]
2001-11-05 16:32:27 +00:00
Beman Dawes 8c18776800 #include <cfloat> (Peter Schmid)
[SVN r10905]
2001-08-21 01:47:04 +00:00
John Maddock 6a9f713309 Fixed <limits> problem
[SVN r9693]
2001-04-02 11:52:42 +00:00
Beman Dawes 27028a7d32 All final 1.20.2 changes, including fixing broken hyperlinks
[SVN r9071]
2001-02-10 14:42:14 +00:00
Dave Abrahams bc9129719e Undid a bug I introduced yesterday. numeric_cast<> never
worked with stock GCC; trying to get it to do that broke
vc-stlport.


[SVN r8703]
2001-01-22 04:27:00 +00:00
Dave Abrahams 3cc0db15d1 removed use of <limits> for portability to raw GCC
[SVN r8670]
2001-01-21 05:37:41 +00:00
Dave Abrahams c66f9eb92c Fixed a warning for MSVC
Added changelog


[SVN r8669]
2001-01-21 05:35:13 +00:00
Dave Abrahams e923c638b4 BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS to config.hpp.
Removed unused BOOST_EXPLICIT_TARGET macro.
Moved boost::detail::type to boost/type.hpp.
Made it compile with stock gcc again


[SVN r8663]
2001-01-21 05:07:11 +00:00
Jens Maurer ed636dd362 bugfix: added destructor definition with empty exception specification
[SVN r8651]
2001-01-20 00:09:14 +00:00
6 changed files with 87 additions and 67 deletions
+17 -12
View File
@@ -1,3 +1,5 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
@@ -9,46 +11,49 @@
<body bgcolor="#FFFFFF" text="#000000">
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Header
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="middle" width="277" height="86">Header
<a href="../../boost/cast.hpp">boost/cast.hpp</a></h1>
<h2><a name="Cast Functions">Cast Functions</a></h2>
<p>The <code>header <a href="../../boost/cast.hpp">boost/cast.hpp</a></code>
<p>The header <a href="../../boost/cast.hpp">boost/cast.hpp</a>
provides <a href="#Polymorphic_cast"><b>polymorphic_cast</b></a>, <a href="#Polymorphic_cast"><b>polymorphic_downcast</b></a>,
and <a href="#numeric_cast"><b>numeric_cast</b></a> function templates designed
to complement the C++ built-in casts.</p>
<p>The program&nbsp;<a href="cast_test.cpp">cast_test.cpp</a> can be used to
<p>The program <a href="cast_test.cpp">cast_test.cpp</a> can be used to
verify these function templates work as expected.</p>
<h3><a name="Polymorphic_cast">Polymorphic casts</a></h3>
<p>Pointers to polymorphic objects (objects of classes which define at least one
virtual function) are sometimes downcast or crosscast.&nbsp; Downcasting means
casting from a base class to a derived class.&nbsp; Crosscasting means casting
virtual function) are sometimes downcast or crosscast. Downcasting means
casting from a base class to a derived class. Crosscasting means casting
across an inheritance hierarchy diagram, such as from one base to the other in a
<b>Y</b> diagram hierarchy.</p>
<p>Such casts can be done with old-style casts, but this approach is never to be
recommended.&nbsp; Old-style casts are sorely lacking in type safety, suffer
recommended. Old-style casts are sorely lacking in type safety, suffer
poor readability, and are difficult to locate with search tools.</p>
<p>The C++ built-in <b>static_cast</b> can be used for efficiently downcasting
pointers to polymorphic objects, but provides no error detection for the case
where the pointer being cast actually points to the wrong derived class. The <b>polymorphic_downcast</b>
template retains the efficiency of <b>static_cast</b> for non-debug
compilations, but for debug compilations adds safety via an assert() that a <b>dynamic_cast</b>
succeeds.&nbsp;<b>&nbsp;</b></p>
succeeds.</p>
<p>The C++ built-in <b>dynamic_cast</b> can be used for downcasts and crosscasts
of pointers to polymorphic objects, but error notification in the form of a
returned value of 0 is inconvenient to test, or worse yet, easy to forget to
test.&nbsp; The <b>polymorphic_cast</b> template performs a <b>dynamic_cast</b>,
test. The <b>polymorphic_cast</b> template performs a <b>dynamic_cast</b>,
and throws an exception if the <b>dynamic_cast</b> returns 0.</p>
<p>A <b>polymorphic_downcast</b> is preferred when debug-mode tests will cover
100% of the object types possibly cast and when non-debug-mode efficiency is an
issue. If these two conditions are not present, <b>polymorphic_cast</b> is
preferred.&nbsp; It must also be used for crosscasts.&nbsp; It does an assert(
preferred. It must also be used for crosscasts. It does an assert(
dynamic_cast&lt;Derived&gt;(x) == x ) where x is the base pointer, ensuring that
not only is a non-zero pointer returned, but also that it correct in the
presence of multiple inheritance.<b> Warning:</b>: Because <b>polymorphic_downcast</b>
uses assert(), it violates the one definition rule (ODR) if NDEBUG is inconsistently
defined across translation units.&nbsp; [See ISO Std 3.2]</p>
defined across translation units. [See ISO Std 3.2]</p>
<p>The C++ built-in <b>dynamic_cast</b> must be used to cast references rather
than pointers.&nbsp; It is also the only cast that can be used to check whether
than pointers. It is also the only cast that can be used to check whether
a given interface is supported; in that case a return of 0 isn't an error
condition.</p>
<h3>polymorphic_cast and polymorphic_downcast synopsis</h3>
@@ -132,7 +137,7 @@ Abrahams</a>.<b><br>
numeric_cast</b> was contributed by <a href="../../people/kevlin_henney.htm">Kevlin
Henney</a>.</p>
<hr>
<p>Revised&nbsp; <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan
-->06 January, 2001<!--webbot bot="Timestamp" endspan i-checksum="38320"
--></p>
<p>© Copyright boost.org 1999. Permission to copy, use, modify, sell and
+5 -4
View File
@@ -9,13 +9,14 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 20 Jan 01 removed use of <limits> for portability to raw GCC (David Abrahams)
// 28 Jun 00 implicit_cast removed (Beman Dawes)
// 30 Aug 99 value_cast replaced by numeric_cast
// 3 Aug 99 Initial Version
#include <iostream>
#include <climits>
#include <limits>
#include <cfloat> // for DBL_MAX (Peter Schmid)
#include <boost/cast.hpp>
# if SCHAR_MAX == LONG_MAX
@@ -95,8 +96,8 @@ int main( int argc, char * argv[] )
// tests which should succeed
long small_value = 1;
long small_negative_value = -1;
long large_value = std::numeric_limits<long>::max();
long large_negative_value = std::numeric_limits<long>::min();
long large_value = LONG_MAX;
long large_negative_value = LONG_MIN;
signed char c = 0;
c = large_value; // see if compiler generates warning
@@ -142,7 +143,7 @@ int main( int argc, char * argv[] )
if ( !caught_exception ) ++err_count;
caught_exception = false;
try { numeric_cast<int>( std::numeric_limits<double>::max() ); }
try { numeric_cast<int>( DBL_MAX ); }
catch (bad_numeric_cast)
{ cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
if ( !caught_exception ) ++err_count;
+24 -29
View File
@@ -9,6 +9,17 @@
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 02 Apr 01 Removed BOOST_NO_LIMITS workarounds and included
// <boost/limits.hpp> instead (the workaround did not
// actually compile when BOOST_NO_LIMITS was defined in
// any case, so we loose nothing). (John Maddock)
// 21 Jan 01 Undid a bug I introduced yesterday. numeric_cast<> never
// worked with stock GCC; trying to get it to do that broke
// vc-stlport.
// 20 Jan 01 Moved BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS to config.hpp.
// Removed unused BOOST_EXPLICIT_TARGET macro. Moved
// boost::detail::type to boost/type.hpp. Made it compile with
// stock gcc again (Dave Abrahams)
// 29 Nov 00 Remove nested namespace cast, cleanup spacing before Formal
// Review (Beman Dawes)
// 19 Oct 00 Fix numeric_cast for floating-point types (Dave Abrahams)
@@ -34,8 +45,9 @@
# include <boost/config.hpp>
# include <cassert>
# include <typeinfo>
# include <limits>
# include <typeinfo>
# include <boost/type.hpp>
# include <boost/limits.hpp>
// It has been demonstrated numerous times that MSVC 6.0 fails silently at link
// time if you use a template function which has template parameters that don't
@@ -43,20 +55,13 @@
//
// TODO: Add this to config.hpp?
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1200 // 1200 = VC6
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::detail::type_wrapper<Target>* = 0
# define BOOST_EXPLICIT_TARGET ,::boost::detail::type_wrapper<Target>*
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
# else
# define BOOST_EXPLICIT_DEFAULT_TARGET
# define BOOST_EXPLICIT_TARGET
# endif
namespace boost
{
namespace detail
{
template <class T> struct type_wrapper {};
}
// See the documentation for descriptions of how to choose between
// static_cast<>, dynamic_cast<>, polymorphic_cast<> and polymorphic_downcast<>
@@ -116,18 +121,7 @@ namespace boost
// numeric_cast ------------------------------------------------------------//
// Move to config.hpp?
#if defined(_RWSTD_VER) || (defined(__SGI_STL_PORT) && __SGI_STL_PORT <= 0x400 && __STL_STATIC_CONST_INIT_BUG)
// STLPort 4.0 doesn't define the static constants in numeric_limits<> so that they
// can be used at compile time if the compiler bug indicated by
// __STL_STATIC_CONST_INIT_BUG is present.
// Rogue wave STL (C++ Builder) also has broken numeric_limits
// with default template defining members out of line.
# define BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
#endif
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || defined(BOOST_SGI_CPP_LIMITS)
namespace detail
{
@@ -139,7 +133,7 @@ namespace boost
template <class T>
struct limits : std::numeric_limits<T>
{
static inline T min()
static inline T min()
# ifndef __GNUC__ // bug workaround courtesy Jens Maurer
{
return std::numeric_limits<T>::min() >= 0
@@ -150,7 +144,7 @@ namespace boost
# else
;
# endif
};
};
};
# ifdef __GNUC__ // bug workaround courtesy Jens Maurer
@@ -271,8 +265,9 @@ namespace boost
# pragma warning(disable : 4018)
# pragma warning(disable : 4146)
#elif defined(__BORLANDC__)
#pragma option push -w-8041
# pragma option push -w-8041
# endif
// Move to namespace boost in utility.hpp?
template <class T>
struct fixed_numeric_limits : public std::numeric_limits<T>
@@ -283,10 +278,11 @@ namespace boost
? T(-std::numeric_limits<T>::max()) : std::numeric_limits<T>::min();
}
};
# if BOOST_MSVC
# pragma warning(pop)
#elif defined(__BORLANDC__)
#pragma option pop
# pragma option pop
# endif
} // namespace detail
@@ -298,8 +294,8 @@ namespace boost
// typedefs abbreviating respective trait classes
typedef std::numeric_limits<Source> arg_traits;
typedef detail::fixed_numeric_limits<Target> result_traits;
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || defined(BOOST_SGI_CPP_LIMITS)
// typedefs that act as compile time assertions
// (to be replaced by boost compile time assertions
// as and when they become available and are stable)
@@ -338,7 +334,6 @@ namespace boost
} // numeric_cast
# undef BOOST_EXPLICIT_DEFAULT_TARGET
# undef BOOST_EXPLICIT_TARGET
} // namespace boost
+20 -11
View File
@@ -13,11 +13,18 @@
// where: tested with MSVC 6.0, BCC 5.5, and g++ 2.91
#include <boost/config.hpp>
# ifndef BOOST_NO_STRINGSTREAM
# include <sstream>
# else
# include <strstream>
// Some sstream implementations are broken for the purposes of lexical cast.
# if defined(BOOST_NO_STRINGSTREAM)
# define BOOST_LEXICAL_CAST_USE_STRSTREAM
# endif
#ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM
# include <strstream>
#else
# include <sstream>
#endif
#include <typeinfo>
namespace boost
@@ -39,10 +46,10 @@ namespace boost
template<typename Target, typename Source>
Target lexical_cast(Source arg)
{
# ifndef BOOST_NO_STRINGSTREAM
std::stringstream interpreter;
# else
# ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM
std::strstream interpreter; // for out-of-the-box g++ 2.95.2
# else
std::stringstream interpreter;
# endif
Target result;
@@ -54,14 +61,16 @@ namespace boost
}
}
// Copyright Kevlin Henney, 2000. All rights reserved.
// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose is hereby granted without fee, provided that this copyright and
// permissions notice appear in all copies and derivatives, and that no
// charge may be made for the software and its documentation except to cover
// cost of distribution.
// permissions notice appear in all copies and derivatives.
//
// This software is provided "as is" without express or implied warranty.
#ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM
# undef BOOST_LEXICAL_CAST_USE_STRSTREAM
#endif
#endif
+8 -8
View File
@@ -12,13 +12,13 @@
<a href="../../boost/lexical_cast.hpp">boost/lexical_cast.hpp</a></h1>
<ul>
<li><a href="#motivation">Motivation</li>
<li></a><a href="#examples">Examples</li>
<li></a><a href="#synopsis">Synopsis</li>
<li></a><a href="#lexical_cast"><code>lexical_cast</code></li>
<li></a><a href="#bad_lexical_cast"><code>bad_lexical_cast</code></li>
<li></a><a href="#portability">Portability</li>
<li></a><a href="#future">Future directions</li>
<li><a href="#motivation">Motivation</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#synopsis">Synopsis</a></li>
<li><a href="#lexical_cast"><code>lexical_cast</code></a></li>
<li><a href="#bad_lexical_cast"><code>bad_lexical_cast</code></a></li>
<li><a href="#portability">Portability</a></li>
<li><a href="#future">Future directions</a></li>
</ul>
<hr>
@@ -127,7 +127,7 @@ void log_errno(int yoko)
<hr>
<h2><a name="synopsis">Synopsis</a></h2>
Library features defined in <a href="lexical_cast.hpp"><code>&quot;boost/lexical_cast.hpp&quot;</code></a>:
Library features defined in <a href="../../boost/lexical_cast.hpp"><code>&quot;boost/lexical_cast.hpp&quot;</code></a>:
<blockquote>
<pre>
+13 -3
View File
@@ -2,6 +2,9 @@
// who: developed by Kevlin Henney
// when: November 2000
// where: tested with BCC 5.5, MSVC 6.0, and g++ 2.91
//
// ChangeLog:
// 20 Jan 2001 - Fixed a warning for MSVC (Dave Abrahams)
#ifndef TEST_INCLUDED
#define TEST_INCLUDED
@@ -40,6 +43,13 @@ namespace test // failure exception used to indicate checked test failures
{
}
// std::~string has no exception-specification (could throw anything),
// but we need to be compatible with std::~exception's empty one
// see std::15.4p13 and std::15.4p3
~failure() throw()
{
}
public: // usage
virtual const char * what() const throw()
@@ -104,14 +114,14 @@ namespace test // test utilities
check(lhs != rhs, "expected unequal values: " + description);
}
inline void check_null(const void * ptr, const std::string & description)
inline void check_null(const void* ptr, const std::string & description)
{
check(!ptr, "expected null pointer: " + description);
}
inline void check_non_null(const void * ptr, const std::string & description)
inline void check_non_null(const void* ptr, const std::string & description)
{
check(ptr, "expected non-null pointer: " + description);
check(ptr != 0, "expected non-null pointer: " + description);
}
}