From fac805ddf671cba6ab6d2f5ac0935f27fe8c8088 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 27 Aug 2013 07:07:15 +0000 Subject: [PATCH] Improved some of the metaprogramming methods (refs #9046) [SVN r85482] --- include/boost/lexical_cast.hpp | 51 ++++++++++++++++------------------ 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index ab1f994..ccbe95f 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -2133,24 +2133,17 @@ namespace boost { /* * is_xchar_to_xchar::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 struct is_xchar_to_xchar { BOOST_STATIC_CONSTANT(bool, value = ( - boost::type_traits::ice_or< - boost::type_traits::ice_and< - boost::is_same::value, - boost::detail::is_character::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::value, - boost::detail::is_character::value - >::value + boost::type_traits::ice_and< + boost::type_traits::ice_eq::value, + boost::detail::is_character::value, + boost::detail::is_character::value >::value ) ); @@ -2321,6 +2314,7 @@ namespace boost { { typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c< boost::type_traits::ice_and< + boost::is_unsigned::value, boost::type_traits::ice_or< boost::is_signed::value, boost::is_float::value @@ -2330,8 +2324,7 @@ namespace boost { >::value, boost::type_traits::ice_not< boost::is_same::value - >::value, - boost::is_unsigned::value + >::value >::value, lexical_cast_dynamic_num_ignoring_minus, lexical_cast_dynamic_num_not_ignoring_minus @@ -2348,26 +2341,30 @@ namespace boost { typedef BOOST_DEDUCED_TYPENAME boost::detail::array_to_pointer_decay::type src; typedef BOOST_DEDUCED_TYPENAME boost::type_traits::ice_or< - boost::detail::is_xchar_to_xchar::value, - boost::detail::is_char_array_to_stdstring::value, - boost::type_traits::ice_and< - boost::is_same::value, - boost::detail::is_stdstring::value - >::value + boost::detail::is_xchar_to_xchar::value, + boost::detail::is_char_array_to_stdstring::value, + boost::type_traits::ice_and< + boost::is_same::value, + boost::detail::is_stdstring::value + >::value > shall_we_copy_t; - typedef BOOST_DEDUCED_TYPENAME - boost::detail::is_arithmetic_and_not_xchars shall_we_copy_with_dynamic_check_t; + typedef boost::detail::is_arithmetic_and_not_xchars + 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, - BOOST_DEDUCED_TYPENAME boost::mpl::if_c< - shall_we_copy_with_dynamic_check_t::value, + boost::mpl::identity >, + boost::mpl::if_< + shall_we_copy_with_dynamic_check_t, boost::detail::lexical_cast_dynamic_num, boost::detail::lexical_cast_do_cast - >::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); }