mirror of
https://github.com/boostorg/conversion.git
synced 2026-08-06 21:44:08 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c6b836076 |
+4
-5
@@ -9,14 +9,13 @@
|
||||
// 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 <cfloat> // for DBL_MAX (Peter Schmid)
|
||||
#include <limits>
|
||||
#include <boost/cast.hpp>
|
||||
|
||||
# if SCHAR_MAX == LONG_MAX
|
||||
@@ -96,8 +95,8 @@ int main( int argc, char * argv[] )
|
||||
// tests which should succeed
|
||||
long small_value = 1;
|
||||
long small_negative_value = -1;
|
||||
long large_value = LONG_MAX;
|
||||
long large_negative_value = LONG_MIN;
|
||||
long large_value = std::numeric_limits<long>::max();
|
||||
long large_negative_value = std::numeric_limits<long>::min();
|
||||
signed char c = 0;
|
||||
|
||||
c = large_value; // see if compiler generates warning
|
||||
@@ -143,7 +142,7 @@ int main( int argc, char * argv[] )
|
||||
if ( !caught_exception ) ++err_count;
|
||||
|
||||
caught_exception = false;
|
||||
try { numeric_cast<int>( DBL_MAX ); }
|
||||
try { numeric_cast<int>( std::numeric_limits<double>::max() ); }
|
||||
catch (bad_numeric_cast)
|
||||
{ cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
|
||||
if ( !caught_exception ) ++err_count;
|
||||
|
||||
+25
-20
@@ -9,17 +9,6 @@
|
||||
// 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)
|
||||
@@ -45,9 +34,8 @@
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <cassert>
|
||||
# include <typeinfo>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/limits.hpp>
|
||||
# include <typeinfo>
|
||||
# include <limits>
|
||||
|
||||
// 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
|
||||
@@ -55,13 +43,20 @@
|
||||
//
|
||||
// TODO: Add this to config.hpp?
|
||||
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1200 // 1200 = VC6
|
||||
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
|
||||
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::detail::type_wrapper<Target>* = 0
|
||||
# define BOOST_EXPLICIT_TARGET ,::boost::detail::type_wrapper<Target>*
|
||||
# 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<>
|
||||
|
||||
@@ -121,6 +116,17 @@ 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
|
||||
|
||||
namespace detail
|
||||
@@ -265,9 +271,8 @@ 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>
|
||||
@@ -278,11 +283,10 @@ 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
|
||||
|
||||
@@ -294,7 +298,7 @@ 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
|
||||
// typedefs that act as compile time assertions
|
||||
// (to be replaced by boost compile time assertions
|
||||
@@ -334,6 +338,7 @@ namespace boost
|
||||
} // numeric_cast
|
||||
|
||||
# undef BOOST_EXPLICIT_DEFAULT_TARGET
|
||||
# undef BOOST_EXPLICIT_TARGET
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
@@ -13,18 +13,11 @@
|
||||
// where: tested with MSVC 6.0, BCC 5.5, and g++ 2.91
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
// The GNU sstream implementation is broken for the purposes of lexical cast.
|
||||
# if defined(BOOST_NO_STRINGSTREAM) || (defined(__GNUC__) && !defined(__STL_USE_NEW_IOSTREAMS) || defined(__APPLE_CC__))
|
||||
# define BOOST_LEXICAL_CAST_USE_STRSTREAM
|
||||
# ifndef BOOST_NO_STRINGSTREAM
|
||||
# include <sstream>
|
||||
# else
|
||||
# include <strstream>
|
||||
# endif
|
||||
|
||||
#ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM
|
||||
# include <strstream>
|
||||
#else
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
namespace boost
|
||||
@@ -46,10 +39,10 @@ namespace boost
|
||||
template<typename Target, typename Source>
|
||||
Target lexical_cast(Source arg)
|
||||
{
|
||||
# ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM
|
||||
std::strstream interpreter; // for out-of-the-box g++ 2.95.2
|
||||
# else
|
||||
# ifndef BOOST_NO_STRINGSTREAM
|
||||
std::stringstream interpreter;
|
||||
# else
|
||||
std::strstream interpreter; // for out-of-the-box g++ 2.95.2
|
||||
# endif
|
||||
Target result;
|
||||
|
||||
@@ -71,8 +64,4 @@ namespace boost
|
||||
//
|
||||
// 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
@@ -12,13 +12,13 @@
|
||||
<a href="../../boost/lexical_cast.hpp">boost/lexical_cast.hpp</a></h1>
|
||||
|
||||
<ul>
|
||||
<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>
|
||||
<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>
|
||||
</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="../../boost/lexical_cast.hpp"><code>"boost/lexical_cast.hpp"</code></a>:
|
||||
Library features defined in <a href="lexical_cast.hpp"><code>"boost/lexical_cast.hpp"</code></a>:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
// 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
|
||||
@@ -43,13 +40,6 @@ 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()
|
||||
@@ -114,14 +104,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 != 0, "expected non-null pointer: " + description);
|
||||
check(ptr, "expected non-null pointer: " + description);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user