X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=boost%2Fboost%2Fcast.hpp;h=2615d183fad2fe288d717a462e9a41f9180c910a;hb=c48091f33a773732fa6c789927e5833e44108d9d;hp=fcbad0d98e15c76c081f74646cbc25a5e14514b7;hpb=59b6a4701a8d2b5155af08cf758b4ca120201282;p=lyx.git diff --git a/boost/boost/cast.hpp b/boost/boost/cast.hpp index fcbad0d98e..2615d183fa 100644 --- a/boost/boost/cast.hpp +++ b/boost/boost/cast.hpp @@ -1,17 +1,17 @@ // boost cast.hpp header file ----------------------------------------------// -// (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. +// (C) Copyright Kevlin Henney and Dave Abrahams 1999. +// Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// See http://www.boost.org for most recent version including documentation. +// See http://www.boost.org/libs/conversion for Documentation. // Revision History -// 02 Apr 01 Removed BOOST_NO_LIMITS workarounds and included -// instead (the workaround did not -// actually compile when BOOST_NO_LIMITS was defined in +// 23 JUn 05 numeric_cast removed and redirected to the new verion (Fernando Cacciola) +// 02 Apr 01 Removed BOOST_NO_LIMITS workarounds and included +// 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 @@ -27,14 +27,14 @@ // (Dave Abrahams) // 30 Jun 00 More MSVC6 wordarounds. See comments below. (Dave Abrahams) // 28 Jun 00 Removed implicit_cast<>. See comment below. (Beman Dawes) -// 27 Jun 00 More MSVC6 workarounds +// 27 Jun 00 More MSVC6 workarounds // 15 Jun 00 Add workarounds for MSVC6 // 2 Feb 00 Remove bad_numeric_cast ";" syntax error (Doncho Angelov) // 26 Jan 00 Add missing throw() to bad_numeric_cast::what(0 (Adam Levar) // 29 Dec 99 Change using declarations so usages in other namespaces work // correctly (Dave Abrahams) // 23 Sep 99 Change polymorphic_downcast assert to also detect M.I. errors -// as suggested Darin Adler and improved by Valentin Bonnard. +// as suggested Darin Adler and improved by Valentin Bonnard. // 2 Sep 99 Remove controversial asserts, simplify, rename. // 30 Aug 99 Move to cast.hpp, replace value_cast with numeric_cast, // place in nested namespace. @@ -44,17 +44,18 @@ #define BOOST_CAST_HPP # include -# include +# include # include # include # include +# include // 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 // appear in the function's argument list. // // TODO: Add this to config.hpp? -# if defined(BOOST_MSVC) && BOOST_MSVC <= 1200 // 1200 = VC6 +# if defined(BOOST_MSVC) && BOOST_MSVC < 1300 # define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type* = 0 # else # define BOOST_EXPLICIT_DEFAULT_TARGET @@ -68,7 +69,7 @@ namespace boost // polymorphic_cast --------------------------------------------------------// // Runtime checked polymorphic downcasts and crosscasts. - // Suggested in The C++ Programming Language, 3rd Ed, Bjarne Stroustrup, + // Suggested in The C++ Programming Language, 3rd Ed, Bjarne Stroustrup, // section 15.8 exercise 1, page 425. template @@ -81,260 +82,26 @@ namespace boost // polymorphic_downcast ----------------------------------------------------// - // assert() checked polymorphic downcast. Crosscasts prohibited. + // BOOST_ASSERT() checked polymorphic downcast. Crosscasts prohibited. - // WARNING: Because this cast uses assert(), it violates the One Definition - // Rule if NDEBUG is inconsistently defined across translation units. + // WARNING: Because this cast uses BOOST_ASSERT(), it violates + // the One Definition Rule if used in multiple translation units + // where BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER + // NDEBUG are defined inconsistently. // Contributed by Dave Abrahams template inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET) { - assert( dynamic_cast(x) == x ); // detect logic error + BOOST_ASSERT( dynamic_cast(x) == x ); // detect logic error return static_cast(x); } -// implicit_cast -----------------------------------------------------------// -// -// Removed due to uncertain purpose. Use either numeric_cast (see below) -// or static_cast according to the need. - -// numeric_cast and related exception --------------------------------------// - -// Contributed by Kevlin Henney - -// bad_numeric_cast --------------------------------------------------------// - - // exception used to indicate runtime numeric_cast failure - class bad_numeric_cast : public std::bad_cast - { - public: - // constructors, destructors and assignment operator defaulted - - // function inlined for brevity and consistency with rest of library - virtual const char *what() const throw() - { - return "bad numeric cast: loss of range in numeric_cast"; - } - }; - -// numeric_cast ------------------------------------------------------------// - -#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || defined(BOOST_SGI_CPP_LIMITS) - - namespace detail - { - template struct numeric_min_select; - - template<> - struct numeric_min_select - { - template - struct limits : std::numeric_limits - { - static inline T min() -# ifndef __GNUC__ // bug workaround courtesy Jens Maurer - { - return std::numeric_limits::min() >= 0 - // unary minus causes integral promotion, thus the static_cast<> - ? static_cast(-std::numeric_limits::max()) - : std::numeric_limits::min(); - } -# else - ; -# endif - }; - }; - -# ifdef __GNUC__ // bug workaround courtesy Jens Maurer - template<> template - inline T numeric_min_select::limits::min() - { - return std::numeric_limits::min() >= 0 - // unary minus causes integral promotion, thus the static_cast<> - ? static_cast(-std::numeric_limits::max()) - : std::numeric_limits::min(); - } -# endif - - template<> - struct numeric_min_select - { - template - struct limits : std::numeric_limits {}; - }; - - // Move to namespace boost in utility.hpp? - template - struct fixed_numeric_limits - : public numeric_min_select< - std::numeric_limits::is_signed - >::template limits - { - }; - } // namespace detail - -// less_than_type_min - - // x_is_signed should be numeric_limits::is_signed - // y_is_signed should be numeric_limits::is_signed - // y_min should be numeric_limits::min() - // - // check(x, y_min) returns true iff x < y_min without invoking comparisons - // between signed and unsigned values. - // - // "poor man's partial specialization" is in use here. - template - struct less_than_type_min - { - template - static bool check(X x, Y y_min) - { return x < y_min; } - }; - - template <> - struct less_than_type_min - { - template - static bool check(X, Y) - { return false; } - }; - - template <> - struct less_than_type_min - { - template - static bool check(X x, Y) - { return x < 0; } - }; - - // greater_than_type_max - - // same_sign should be: - // numeric_limits::is_signed == numeric_limits::is_signed - // y_max should be numeric_limits::max() - // - // check(x, y_max) returns true iff x > y_max without invoking comparisons - // between signed and unsigned values. - // - // "poor man's partial specialization" is in use here. - template - struct greater_than_type_max; - - template<> - struct greater_than_type_max - { - template - static inline bool check(X x, Y y_max) - { return x > y_max; } - }; - - template <> - struct greater_than_type_max - { - // What does the standard say about this? I think it's right, and it - // will work with every compiler I know of. - template - static inline bool check(X x, Y) - { return x >= 0 && static_cast(static_cast(x)) != x; } - }; - - template<> - struct greater_than_type_max - { - template - static inline bool check(X x, Y y_max) - { return x > y_max; } - }; - - template <> - struct greater_than_type_max - { - // What does the standard say about this? I think it's right, and it - // will work with every compiler I know of. - template - static inline bool check(X x, Y) - { return static_cast(static_cast(x)) != x; } - }; - -#else // use #pragma hacks if available - - namespace detail - { -# if BOOST_MSVC -# pragma warning(push) -# pragma warning(disable : 4018) -# pragma warning(disable : 4146) -#elif defined(__BORLANDC__) -# pragma option push -w-8041 -# endif - - // Move to namespace boost in utility.hpp? - template - struct fixed_numeric_limits : public std::numeric_limits - { - static inline T min() - { - return std::numeric_limits::is_signed && std::numeric_limits::min() >= 0 - ? T(-std::numeric_limits::max()) : std::numeric_limits::min(); - } - }; - -# if BOOST_MSVC -# pragma warning(pop) -#elif defined(__BORLANDC__) -# pragma option pop -# endif - } // namespace detail - -#endif - - template - inline Target numeric_cast(Source arg BOOST_EXPLICIT_DEFAULT_TARGET) - { - // typedefs abbreviating respective trait classes - typedef std::numeric_limits arg_traits; - typedef detail::fixed_numeric_limits result_traits; - -#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) - typedef bool argument_must_be_numeric[arg_traits::is_specialized]; - typedef bool result_must_be_numeric[result_traits::is_specialized]; - - const bool arg_is_signed = arg_traits::is_signed; - const bool result_is_signed = result_traits::is_signed; - const bool same_sign = arg_is_signed == result_is_signed; - - if (less_than_type_min::check(arg, result_traits::min()) - || greater_than_type_max::check(arg, result_traits::max()) - ) - -#else // We need to use #pragma hacks if available - -# if BOOST_MSVC -# pragma warning(push) -# pragma warning(disable : 4018) -#elif defined(__BORLANDC__) -#pragma option push -w-8012 -# endif - if ((arg < 0 && !result_traits::is_signed) // loss of negative range - || (arg_traits::is_signed && arg < result_traits::min()) // underflow - || arg > result_traits::max()) // overflow -# if BOOST_MSVC -# pragma warning(pop) -#elif defined(__BORLANDC__) -#pragma option pop -# endif -#endif - { - throw bad_numeric_cast(); - } - return static_cast(arg); - } // numeric_cast - # undef BOOST_EXPLICIT_DEFAULT_TARGET } // namespace boost +# include + #endif // BOOST_CAST_HPP