Boost logo

Boost-Commit :

From: steven_at_[hidden]
Date: 2008-06-24 23:15:09


Author: steven_watanabe
Date: 2008-06-24 23:15:08 EDT (Tue, 24 Jun 2008)
New Revision: 46673
URL: http://svn.boost.org/trac/boost/changeset/46673

Log:
Save about 3000 out of 28000 template instantiations in example/systems.cpp by replacing is_base_and_derived with integral constant members and inlining base_unit_converter_is_undefined
Text files modified:
   trunk/boost/units/absolute.hpp | 1
   trunk/boost/units/conversion.hpp | 4 +++
   trunk/boost/units/detail/absolute_impl.hpp | 16 ++++--------
   trunk/boost/units/detail/conversion_impl.hpp | 50 +++++++++++++++------------------------
   4 files changed, 29 insertions(+), 42 deletions(-)

Modified: trunk/boost/units/absolute.hpp
==============================================================================
--- trunk/boost/units/absolute.hpp (original)
+++ trunk/boost/units/absolute.hpp 2008-06-24 23:15:08 EDT (Tue, 24 Jun 2008)
@@ -133,6 +133,7 @@
         reduce_unit<From::unit_type>::type, \
         reduce_unit<To::unit_type>::type> \
     { \
+ static const bool is_defined = true; \
         typedef type_ type; \
         static type value() { return(value_); } \
     }; \

Modified: trunk/boost/units/conversion.hpp
==============================================================================
--- trunk/boost/units/conversion.hpp (original)
+++ trunk/boost/units/conversion.hpp 2008-06-24 23:15:08 EDT (Tue, 24 Jun 2008)
@@ -70,6 +70,7 @@
     template<> \
     struct base_unit_converter<Source, reduce_unit<Destination::unit_type>::type> \
     { \
+ static const bool is_defined = true; \
         typedef type_ type; \
         static type value() { return(value_); } \
     }; \
@@ -95,6 +96,7 @@
         BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Destination, typename Source::dimension_type)\
> \
     { \
+ static const bool is_defined = true; \
         typedef type_ type; \
         static type value() { return(value_); } \
     }; \
@@ -112,6 +114,7 @@
     template<> \
     struct unscaled_get_default_conversion<unscale<Source>::type> \
     { \
+ static const bool is_defined = true; \
         typedef Dest type; \
     }; \
     } \
@@ -130,6 +133,7 @@
     template<BOOST_PP_SEQ_ENUM(Params)> \
     struct unscaled_get_default_conversion<Source> \
     { \
+ static const bool is_defined = true; \
         typedef Dest type; \
     }; \
     } \

Modified: trunk/boost/units/detail/absolute_impl.hpp
==============================================================================
--- trunk/boost/units/detail/absolute_impl.hpp (original)
+++ trunk/boost/units/detail/absolute_impl.hpp 2008-06-24 23:15:08 EDT (Tue, 24 Jun 2008)
@@ -13,8 +13,6 @@
 
 #include <iosfwd>
 
-#include <boost/type_traits/is_base_and_derived.hpp>
-
 #include <boost/units/config.hpp>
 #include <boost/units/conversion.hpp>
 #include <boost/units/heterogeneous_system.hpp>
@@ -33,7 +31,9 @@
 
 namespace detail {
 
-struct undefined_affine_conversion_base { };
+struct undefined_affine_conversion_base {
+ static const bool is_defined = false;
+};
 
 } // namespace detail
 
@@ -89,14 +89,8 @@
         return(
             to_quantity_type::from_value(
                 detail::affine_conversion_impl<
- !boost::is_base_and_derived<
- detail::undefined_affine_conversion_base,
- affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>
- >::value,
- !boost::is_base_and_derived<
- detail::undefined_affine_conversion_base,
- affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>
- >::value
+ affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::is_defined,
+ affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::is_defined
>::template apply<Unit1, Unit2, T1, T2>::value(source.value())
             )
         );

Modified: trunk/boost/units/detail/conversion_impl.hpp
==============================================================================
--- trunk/boost/units/detail/conversion_impl.hpp (original)
+++ trunk/boost/units/detail/conversion_impl.hpp 2008-06-24 23:15:08 EDT (Tue, 24 Jun 2008)
@@ -16,7 +16,6 @@
 #include <boost/mpl/divides.hpp>
 #include <boost/preprocessor/seq/enum.hpp>
 #include <boost/type_traits/is_same.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
 
 #include <boost/units/heterogeneous_system.hpp>
 #include <boost/units/homogeneous_system.hpp>
@@ -46,10 +45,14 @@
 }
 
 /// INTERNAL ONLY
-struct undefined_base_unit_converter_base { };
+struct undefined_base_unit_converter_base {
+ static const bool is_defined = false;
+};
 
 /// INTERNAL ONLY
-struct no_default_conversion { };
+struct no_default_conversion {
+ static const bool is_defined = false;
+};
 
 /// INTERNAL ONLY
 template<class BaseUnit>
@@ -86,7 +89,7 @@
 struct get_default_conversion
 {
     typedef typename unscaled_get_default_conversion_impl<
- !boost::is_base_and_derived<no_default_conversion, unscaled_get_default_conversion<typename unscale<BaseUnit>::type> >::value
+ unscaled_get_default_conversion<typename unscale<BaseUnit>::type>::is_defined
>::template apply<BaseUnit>::type type;
 };
 
@@ -100,12 +103,14 @@
 
 /// INTERNAL ONLY
 template<class Source, class Dest>
-struct base_unit_converter_base : undefined_base_unit_converter_base { };
+struct base_unit_converter_base : undefined_base_unit_converter_base {
+};
 
 /// INTERNAL ONLY
 template<class Source>
 struct base_unit_converter_base<Source, BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Source, typename Source::dimension_type)>
 {
+ static const bool is_defined = true;
     typedef one type;
     static type value() {
         return(one());
@@ -152,10 +157,7 @@
 template<class Source, class Dest>
 struct do_call_base_unit_converter :
     do_call_base_unit_converter_impl<
- !boost::is_base_and_derived<
- undefined_base_unit_converter_base,
- base_unit_converter<Source, Dest>
- >::value
+ base_unit_converter<Source, Dest>::is_defined
>::template apply<Source, Dest> {};
 
 template<bool forward_is_defined, bool reverse_is_defined>
@@ -290,36 +292,22 @@
     };
 };
 
-template<class Source, class Dest>
-struct base_unit_converter_scaled_is_undefined :
- boost::is_base_and_derived<
- undefined_base_unit_converter_base,
- base_unit_converter<
- typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::source_type,
- typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::destination_type
- >
- > {};
-
-template<class Source, class Dest>
-struct base_unit_converter_is_undefined :
- mpl::and_<
- boost::is_base_and_derived<
- undefined_base_unit_converter_base,
- base_unit_converter<Source, Dest>
- >,
- base_unit_converter_scaled_is_undefined<Source, Dest>
- > {};
+#define BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, Dest)\
+ base_unit_converter<\
+ typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::source_type,\
+ typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::destination_type\
+ >::is_defined
 
 template<class Source, class Dest>
-struct call_base_unit_converter : call_base_unit_converter_impl<!base_unit_converter_is_undefined<Source, Dest>::value>::template apply<Source, Dest>
+struct call_base_unit_converter : call_base_unit_converter_impl<BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, Dest)>::template apply<Source, Dest>
 {
 };
 
 template<class Source, class Dest>
 struct call_base_unit_converter<Source, BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Dest, typename Source::dimension_type)> :
     call_base_unit_converter_base_unit_impl<
- !base_unit_converter_is_undefined<Source, typename Dest::unit_type>::value,
- !base_unit_converter_is_undefined<Dest, typename Source::unit_type>::value
+ BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, typename Dest::unit_type),
+ BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Dest, typename Source::unit_type)
>::template apply<Source, Dest>
 {
 };


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