Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85482 - trunk/boost
From: antoshkka_at_[hidden]
Date: 2013-08-27 03:07:15


Author: apolukhin
Date: 2013-08-27 03:07:15 EDT (Tue, 27 Aug 2013)
New Revision: 85482
URL: http://svn.boost.org/trac/boost/changeset/85482

Log:
Improved some of the metaprogramming methods (refs #9046)

Text files modified:
   trunk/boost/lexical_cast.hpp | 51 ++++++++++++++++++---------------------
   1 files changed, 24 insertions(+), 27 deletions(-)

Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp Mon Aug 26 17:36:22 2013 (r85481)
+++ trunk/boost/lexical_cast.hpp 2013-08-27 03:07:15 EDT (Tue, 27 Aug 2013) (r85482)
@@ -2133,24 +2133,17 @@
         /*
          * is_xchar_to_xchar<Target, Source>::value is true, when
          * Target and Souce are the same char types, or when
- * Target and Souce are char types of the same size.
+ * Target and Souce are char types of the same size (signed char, unsigned char).
          */
         template<typename Target, typename Source>
         struct is_xchar_to_xchar
         {
             BOOST_STATIC_CONSTANT(bool, value =
                 (
- boost::type_traits::ice_or<
- boost::type_traits::ice_and<
- boost::is_same<Source,Target>::value,
- boost::detail::is_character<Target>::value
- >::value,
- boost::type_traits::ice_and<
- boost::type_traits::ice_eq< sizeof(char),sizeof(Target)>::value,
- boost::type_traits::ice_eq< sizeof(char),sizeof(Source)>::value,
- boost::detail::is_character<Target>::value,
- boost::detail::is_character<Source>::value
- >::value
+ boost::type_traits::ice_and<
+ boost::type_traits::ice_eq<sizeof(Source), sizeof(Target)>::value,
+ boost::detail::is_character<Target>::value,
+ boost::detail::is_character<Source>::value
>::value
                 )
             );
@@ -2321,6 +2314,7 @@
             {
                 typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
                     boost::type_traits::ice_and<
+ boost::is_unsigned<Target>::value,
                         boost::type_traits::ice_or<
                             boost::is_signed<Source>::value,
                             boost::is_float<Source>::value
@@ -2330,8 +2324,7 @@
>::value,
                         boost::type_traits::ice_not<
                             boost::is_same<Target, bool>::value
- >::value,
- boost::is_unsigned<Target>::value
+ >::value
>::value,
                     lexical_cast_dynamic_num_ignoring_minus<Target, Source>,
                     lexical_cast_dynamic_num_not_ignoring_minus<Target, Source>
@@ -2348,26 +2341,30 @@
         typedef BOOST_DEDUCED_TYPENAME boost::detail::array_to_pointer_decay<Source>::type src;
 
         typedef BOOST_DEDUCED_TYPENAME boost::type_traits::ice_or<
- boost::detail::is_xchar_to_xchar<Target, src >::value,
- boost::detail::is_char_array_to_stdstring<Target, src >::value,
- boost::type_traits::ice_and<
- boost::is_same<Target, src >::value,
- boost::detail::is_stdstring<Target >::value
- >::value
+ boost::detail::is_xchar_to_xchar<Target, src >::value,
+ boost::detail::is_char_array_to_stdstring<Target, src >::value,
+ boost::type_traits::ice_and<
+ boost::is_same<Target, src >::value,
+ boost::detail::is_stdstring<Target >::value
+ >::value
> shall_we_copy_t;
 
- typedef BOOST_DEDUCED_TYPENAME
- boost::detail::is_arithmetic_and_not_xchars<Target, src > shall_we_copy_with_dynamic_check_t;
+ typedef boost::detail::is_arithmetic_and_not_xchars<Target, src >
+ shall_we_copy_with_dynamic_check_t;
 
+ // We do evaluate second `if_` lazily to avoid unnecessary instantiations
+ // of `shall_we_copy_with_dynamic_check_t` and improve compilation times.
         typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
             shall_we_copy_t::value,
- boost::detail::lexical_cast_copy<src >,
- BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
- shall_we_copy_with_dynamic_check_t::value,
+ boost::mpl::identity<boost::detail::lexical_cast_copy<src > >,
+ boost::mpl::if_<
+ shall_we_copy_with_dynamic_check_t,
                  boost::detail::lexical_cast_dynamic_num<Target, src >,
                  boost::detail::lexical_cast_do_cast<Target, src >
- >::type
- >::type caster_type;
+ >
+ >::type caster_type_lazy;
+
+ typedef BOOST_DEDUCED_TYPENAME caster_type_lazy::type caster_type;
 
         return caster_type::lexical_cast_impl(arg);
     }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk