epoc32/include/stdapis/boost/cast.hpp
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
     1.1 --- a/epoc32/include/stdapis/boost/cast.hpp	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/stdapis/boost/cast.hpp	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -1,51 +1,107 @@
     1.4 -//  © Copyright Fernando Luis Cacciola Carballal 2000-2004
     1.5 -//  Use, modification, and distribution is subject to the Boost Software
     1.6 -//  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
     1.7 -//  http://www.boost.org/LICENSE_1_0.txt)
     1.8 +//  boost cast.hpp header file  ----------------------------------------------//
     1.9  
    1.10 -//  See library home page at http://www.boost.org/libs/numeric/conversion
    1.11 +//  (C) Copyright Kevlin Henney and Dave Abrahams 1999.
    1.12 +//  Distributed under the Boost
    1.13 +//  Software License, Version 1.0. (See accompanying file
    1.14 +//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
    1.15 +
    1.16 +//  See http://www.boost.org/libs/conversion for Documentation.
    1.17 +
    1.18 +//  Revision History
    1.19 +//  23 JUn 05  numeric_cast removed and redirected to the new verion (Fernando Cacciola)
    1.20 +//  02 Apr 01  Removed BOOST_NO_LIMITS workarounds and included
    1.21 +//             <boost/limits.hpp> instead (the workaround did not
    1.22 +//             actually compile when BOOST_NO_LIMITS was defined in
    1.23 +//             any case, so we loose nothing). (John Maddock)
    1.24 +//  21 Jan 01  Undid a bug I introduced yesterday. numeric_cast<> never
    1.25 +//             worked with stock GCC; trying to get it to do that broke
    1.26 +//             vc-stlport.
    1.27 +//  20 Jan 01  Moved BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS to config.hpp.
    1.28 +//             Removed unused BOOST_EXPLICIT_TARGET macro. Moved
    1.29 +//             boost::detail::type to boost/type.hpp. Made it compile with
    1.30 +//             stock gcc again (Dave Abrahams)
    1.31 +//  29 Nov 00  Remove nested namespace cast, cleanup spacing before Formal
    1.32 +//             Review (Beman Dawes)
    1.33 +//  19 Oct 00  Fix numeric_cast for floating-point types (Dave Abrahams)
    1.34 +//  15 Jul 00  Suppress numeric_cast warnings for GCC, Borland and MSVC
    1.35 +//             (Dave Abrahams)
    1.36 +//  30 Jun 00  More MSVC6 wordarounds.  See comments below.  (Dave Abrahams)
    1.37 +//  28 Jun 00  Removed implicit_cast<>.  See comment below. (Beman Dawes)
    1.38 +//  27 Jun 00  More MSVC6 workarounds
    1.39 +//  15 Jun 00  Add workarounds for MSVC6
    1.40 +//   2 Feb 00  Remove bad_numeric_cast ";" syntax error (Doncho Angelov)
    1.41 +//  26 Jan 00  Add missing throw() to bad_numeric_cast::what(0 (Adam Levar)
    1.42 +//  29 Dec 99  Change using declarations so usages in other namespaces work
    1.43 +//             correctly (Dave Abrahams)
    1.44 +//  23 Sep 99  Change polymorphic_downcast assert to also detect M.I. errors
    1.45 +//             as suggested Darin Adler and improved by Valentin Bonnard.
    1.46 +//   2 Sep 99  Remove controversial asserts, simplify, rename.
    1.47 +//  30 Aug 99  Move to cast.hpp, replace value_cast with numeric_cast,
    1.48 +//             place in nested namespace.
    1.49 +//   3 Aug 99  Initial version
    1.50 +
    1.51 +#ifndef BOOST_CAST_HPP
    1.52 +#define BOOST_CAST_HPP
    1.53 +
    1.54 +# include <boost/config.hpp>
    1.55 +# include <boost/assert.hpp>
    1.56 +# include <typeinfo>
    1.57 +# include <boost/type.hpp>
    1.58 +# include <boost/limits.hpp>
    1.59 +# include <boost/detail/select_type.hpp>
    1.60 +
    1.61 +//  It has been demonstrated numerous times that MSVC 6.0 fails silently at link
    1.62 +//  time if you use a template function which has template parameters that don't
    1.63 +//  appear in the function's argument list.
    1.64  //
    1.65 -// Contact the author at: fernando_cacciola@hotmail.com
    1.66 -//
    1.67 -//
    1.68 -//  Revision History
    1.69 -//
    1.70 -//    19 Nov 2001 Syntatic changes as suggested by Darin Adler (Fernando Cacciola)
    1.71 -//    08 Nov 2001 Fixes to accommodate MSVC (Fernando Cacciola)
    1.72 -//    04 Nov 2001 Fixes to accommodate gcc2.92 (Fernando Cacciola)
    1.73 -//    30 Oct 2001 Some fixes suggested by Daryle Walker (Fernando Cacciola)
    1.74 -//    25 Oct 2001 Initial boostification (Fernando Cacciola)
    1.75 -//    23 Jan 2004 Inital add to cvs (post review)s
    1.76 -//
    1.77 -#ifndef BOOST_NUMERIC_CONVERSION_CAST_25OCT2001_HPP
    1.78 -#define BOOST_NUMERIC_CONVERSION_CAST_25OCT2001_HPP
    1.79 -
    1.80 -#include <boost/detail/workaround.hpp>
    1.81 -
    1.82 -#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
    1.83 -
    1.84 -#  include<boost/numeric/conversion/detail/old_numeric_cast.hpp>
    1.85 -
    1.86 -#else
    1.87 -
    1.88 -#include <boost/type.hpp>
    1.89 -#include <boost/numeric/conversion/converter.hpp>
    1.90 +//  TODO: Add this to config.hpp?
    1.91 +# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
    1.92 +#  define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
    1.93 +# else
    1.94 +#  define BOOST_EXPLICIT_DEFAULT_TARGET
    1.95 +# endif
    1.96  
    1.97  namespace boost
    1.98  {
    1.99 -  template<typename Target, typename Source>
   1.100 -  inline
   1.101 -  Target numeric_cast ( Source arg )
   1.102 -  {
   1.103 -    typedef boost::numeric::converter<Target,Source> Converter ;
   1.104 -    return Converter::convert(arg);
   1.105 -  }
   1.106 +//  See the documentation for descriptions of how to choose between
   1.107 +//  static_cast<>, dynamic_cast<>, polymorphic_cast<> and polymorphic_downcast<>
   1.108  
   1.109 -  using numeric::bad_numeric_cast;
   1.110 +//  polymorphic_cast  --------------------------------------------------------//
   1.111 +
   1.112 +    //  Runtime checked polymorphic downcasts and crosscasts.
   1.113 +    //  Suggested in The C++ Programming Language, 3rd Ed, Bjarne Stroustrup,
   1.114 +    //  section 15.8 exercise 1, page 425.
   1.115 +
   1.116 +    template <class Target, class Source>
   1.117 +    inline Target polymorphic_cast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
   1.118 +    {
   1.119 +        Target tmp = dynamic_cast<Target>(x);
   1.120 +        if ( tmp == 0 ) throw std::bad_cast();
   1.121 +        return tmp;
   1.122 +    }
   1.123 +
   1.124 +//  polymorphic_downcast  ----------------------------------------------------//
   1.125 +
   1.126 +    //  BOOST_ASSERT() checked polymorphic downcast.  Crosscasts prohibited.
   1.127 +
   1.128 +    //  WARNING: Because this cast uses BOOST_ASSERT(), it violates
   1.129 +    //  the One Definition Rule if used in multiple translation units
   1.130 +    //  where BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER
   1.131 +    //  NDEBUG are defined inconsistently.
   1.132 +
   1.133 +    //  Contributed by Dave Abrahams
   1.134 +
   1.135 +    template <class Target, class Source>
   1.136 +    inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
   1.137 +    {
   1.138 +        BOOST_ASSERT( dynamic_cast<Target>(x) == x );  // detect logic error
   1.139 +        return static_cast<Target>(x);
   1.140 +    }
   1.141 +
   1.142 +#  undef BOOST_EXPLICIT_DEFAULT_TARGET
   1.143  
   1.144  } // namespace boost
   1.145  
   1.146 -#endif
   1.147 +# include <boost/numeric/conversion/cast.hpp>
   1.148  
   1.149 -
   1.150 -#endif
   1.151 +#endif  // BOOST_CAST_HPP