Boost logo

Boost-Commit :

From: steven_at_[hidden]
Date: 2007-07-30 19:07:17


Author: steven_watanabe
Date: 2007-07-30 19:07:16 EDT (Mon, 30 Jul 2007)
New Revision: 7597
URL: http://svn.boost.org/trac/boost/changeset/7597

Log:
restore fine-grained implicit conversions
Added:
   sandbox/units/boost/units/implicit_conversion.hpp
      - copied, changed from r7565, /sandbox/units/boost/units/detail/unit_impl.hpp
Removed:
   sandbox/units/boost/units/detail/unit_impl.hpp
Text files modified:
   sandbox/units/boost/units/conversion.hpp | 47 -------
   sandbox/units/boost/units/heterogeneous_system.hpp | 18 +++
   sandbox/units/boost/units/implicit_conversion.hpp | 220 +++++++++++++++++----------------------
   sandbox/units/boost/units/unit.hpp | 7
   sandbox/units/boost/units/units_fwd.hpp | 7 +
   sandbox/units/libs/units/doc/Jamfile.v2 | 12 +-
   6 files changed, 138 insertions(+), 173 deletions(-)

Modified: sandbox/units/boost/units/conversion.hpp
==============================================================================
--- sandbox/units/boost/units/conversion.hpp (original)
+++ sandbox/units/boost/units/conversion.hpp 2007-07-30 19:07:16 EDT (Mon, 30 Jul 2007)
@@ -160,15 +160,7 @@
 template<class Source, class Dest>
 struct base_unit_converter<
     Source,
- unit<
- typename Source::dimension_type,
- heterogeneous_system<
- heterogeneous_system_pair<
- dimension_list<heterogeneous_system_dim<Dest, static_rational<1> >, dimensionless_type>,
- typename Source::dimension_type
- >
- >
- >
+ BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Dest, typename Source::dimension_type)
> : detail::inverse_base_unit_converter_impl<
         detail::use_inverse_conversion<Source, Dest>::value,
         boost::is_same<Source, Dest>::value
@@ -184,37 +176,16 @@
     template<> \
     struct select_base_unit_converter< \
         unscale<Source>::type, \
- unit< \
- Source::dimension_type, \
- heterogeneous_system< \
- heterogeneous_system_pair< \
- unscale<Destination>::type, \
- Source::dimension_type \
- > \
- > \
- > \
+ BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(unscale<Destination>::type, Source::dimension_type)\
> \
     { \
         typedef Source source_type; \
- typedef unit< \
- Source::dimension_type, \
- heterogeneous_system< \
- heterogeneous_system_pair< \
- Destination, \
- Source::dimension_type> > > destination_type; \
+ typedef BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Destination, Source::dimension_type) destination_type;\
     }; \
     template<> \
     struct base_unit_converter< \
         Source, \
- unit< \
- Source::dimension_type, \
- heterogeneous_system< \
- heterogeneous_system_pair< \
- Destination, \
- Source::dimension_type \
- > \
- > \
- > \
+ BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Destination, Source::dimension_type)\
> \
     { \
         typedef type_ type; \
@@ -233,15 +204,7 @@
     template<BOOST_PP_SEQ_ENUM(Params)> \
     struct base_unit_converter< \
         Source, \
- unit< \
- typename Source::dimension_type, \
- heterogeneous_system< \
- heterogeneous_system_pair< \
- Destination, \
- typename Source::dimension_type \
- > \
- > \
- > \
+ BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Destination, typename Source::dimension_type)\
> \
     { \
         typedef type_ type; \

Deleted: sandbox/units/boost/units/detail/unit_impl.hpp
==============================================================================
--- sandbox/units/boost/units/detail/unit_impl.hpp 2007-07-30 19:07:16 EDT (Mon, 30 Jul 2007)
+++ (empty file)
@@ -1,145 +0,0 @@
-/// mcs::units - A C++ library for zero-overhead dimensional analysis and
-// unit/quantity manipulation and conversion
-//
-// Copyright (C) 2003-2007 Matthias Christian Schabel
-// Copyright (C) 2007 Steven Watanabe
-//
-// 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)
-
-#ifndef BOOST_UNITS_UNIT_IMPL_HPP
-#define BOOST_UNITS_UNIT_IMPL_HPP
-
-#include <boost/mpl/begin.hpp>
-#include <boost/mpl/size.hpp>
-#include <boost/mpl/bool.hpp>
-
-#include <boost/units/operators.hpp>
-
-#include <boost/units/heterogeneous_system.hpp>
-
-//namespace boost {
-//
-//namespace units {
-//
-//template<class Dim,class System> class unit;
-//
-//namespace detail {
-//
-//// check if implicit conversion is allowed between homogeneous systems
-//template<int N>
-//struct implicit_conversion_homo_to_homo_impl
-//{
-// template<class Begin, class system1_type, class system2_type>
-// struct apply
-// {
-// typedef typename detail::get_tag<typename mpl::deref<Begin>::type>::type dim_tag_type;
-// typedef typename detail::get_value<typename mpl::deref<Begin>::type>::type value_type;
-// typedef typename mpl::next<Begin>::type next;
-//
-// typedef typename detail::get_system_tag_of_dim<system1_type,dim_tag_type>::type system1_tag_type;
-// typedef typename detail::get_system_tag_of_dim<system2_type,dim_tag_type>::type system2_tag_type;
-//
-// typedef base_unit_is_implicitly_convertible<dim_tag_type,
-// system1_tag_type,
-// system2_tag_type> convertible_type;
-//
-// typedef typename implicit_conversion_homo_to_homo_impl<N - 1>::template
-// apply<next, system1_type, system2_type> next_iteration;
-//
-// static const bool value = convertible_type::value && next_iteration::value;
-// };
-//};
-//
-//template<>
-//struct implicit_conversion_homo_to_homo_impl<0>
-//{
-// template<class Begin, class system1_type, class system2_type>
-// struct apply
-// {
-// typedef one type;
-//
-// static const bool value = true;
-// };
-//};
-//
-//// check if implicit conversion is allowed between homogeneous and heterogeneous systems
-//// NB UNTESTED
-//template<int N>
-//struct implicit_conversion_homo_to_hetero_impl
-//{
-// template<class Begin, class system1_type>
-// struct apply
-// {
-// typedef homogeneous_system<typename detail::get_tag<typename mpl::deref<Begin>::type>::type> system2_type;
-// typedef typename detail::get_value<typename mpl::deref<Begin>::type>::type value_type;
-//
-// typedef typename mpl::next<Begin>::type next;
-// typedef typename mpl::begin<value_type>::type begin;
-//
-// typedef typename implicit_conversion_homo_to_homo_impl<mpl::size<value_type>::value>::template
-// apply<begin, system1_type, system2_type> convert_system;
-//
-// typedef typename implicit_conversion_homo_to_hetero_impl<N - 1>::template
-// apply<next, system1_type> next_iteration;
-//
-// static const bool value = convert_system::value && next_iteration::value;
-// };
-//};
-//
-//template<>
-//struct implicit_conversion_homo_to_hetero_impl<0>
-//{
-// template<class Begin, class system1_type, class system2_type>
-// struct apply
-// {
-// typedef one type;
-//
-// static const bool value = true;
-// };
-//};
-//
-//// check if implicit conversion is allowed between homogeneous and heterogeneous systems
-///// NB UNTESTED
-//template<int N>
-//struct implicit_conversion_hetero_to_homo_impl
-//{
-// template<class Begin, class system2_type>
-// struct apply
-// {
-// typedef homogeneous_system<typename detail::get_tag<typename mpl::deref<Begin>::type>::type> system1_type;
-// typedef typename detail::get_value<typename mpl::deref<Begin>::type>::type value_type;
-//
-// typedef typename mpl::next<Begin>::type next;
-// typedef typename mpl::begin<value_type>::type begin;
-//
-// typedef typename implicit_conversion_homo_to_homo_impl<mpl::size<value_type>::value>::template
-// apply<begin, system1_type, system2_type> convert_system;
-//
-// typedef typename implicit_conversion_hetero_to_homo_impl<N - 1>::template
-// apply<next, system2_type> next_iteration;
-//
-// static const bool value = convert_system::value && next_iteration::value;
-// };
-//};
-//
-//template<>
-//struct implicit_conversion_hetero_to_homo_impl<0>
-//{
-// template<class Begin, class system1_type, class system2_type>
-// struct apply
-// {
-// typedef one type;
-//
-// static const bool value = true;
-// };
-//};
-//
-//} // namespace detail
-//
-//} // namespace units
-//
-//} // namespace boost
-
-#endif // BOOST_UNITS_UNIT_IMPL_HPP

Modified: sandbox/units/boost/units/heterogeneous_system.hpp
==============================================================================
--- sandbox/units/boost/units/heterogeneous_system.hpp (original)
+++ sandbox/units/boost/units/heterogeneous_system.hpp 2007-07-30 19:07:16 EDT (Mon, 30 Jul 2007)
@@ -82,6 +82,24 @@
     typedef Exponent value_type;
 };
 
+/// INTERNAL ONLY
+#define BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(BaseUnit, Dimensions) \
+ boost::units::unit< \
+ Dimensions, \
+ boost::units::heterogeneous_system< \
+ boost::units::heterogeneous_system_pair< \
+ boost::units::dimension_list< \
+ boost::units::heterogeneous_system_dim< \
+ BaseUnit, \
+ boost::units::static_rational<1> \
+ >, \
+ boost::units::dimensionless_type \
+ >, \
+ Dimensions \
+ > \
+ > \
+ >
+
 } // namespace units
 
 } // namespace boost

Copied: sandbox/units/boost/units/implicit_conversion.hpp (from r7565, /sandbox/units/boost/units/detail/unit_impl.hpp)
==============================================================================
--- /sandbox/units/boost/units/detail/unit_impl.hpp (original)
+++ sandbox/units/boost/units/implicit_conversion.hpp 2007-07-30 19:07:16 EDT (Mon, 30 Jul 2007)
@@ -13,133 +13,109 @@
 
 #include <boost/mpl/begin.hpp>
 #include <boost/mpl/size.hpp>
+#include <boost/mpl/next.hpp>
+#include <boost/mpl/deref.hpp>
 #include <boost/mpl/bool.hpp>
 
 #include <boost/units/operators.hpp>
 
 #include <boost/units/heterogeneous_system.hpp>
 
-//namespace boost {
-//
-//namespace units {
-//
-//template<class Dim,class System> class unit;
-//
-//namespace detail {
-//
-//// check if implicit conversion is allowed between homogeneous systems
-//template<int N>
-//struct implicit_conversion_homo_to_homo_impl
-//{
-// template<class Begin, class system1_type, class system2_type>
-// struct apply
-// {
-// typedef typename detail::get_tag<typename mpl::deref<Begin>::type>::type dim_tag_type;
-// typedef typename detail::get_value<typename mpl::deref<Begin>::type>::type value_type;
-// typedef typename mpl::next<Begin>::type next;
-//
-// typedef typename detail::get_system_tag_of_dim<system1_type,dim_tag_type>::type system1_tag_type;
-// typedef typename detail::get_system_tag_of_dim<system2_type,dim_tag_type>::type system2_tag_type;
-//
-// typedef base_unit_is_implicitly_convertible<dim_tag_type,
-// system1_tag_type,
-// system2_tag_type> convertible_type;
-//
-// typedef typename implicit_conversion_homo_to_homo_impl<N - 1>::template
-// apply<next, system1_type, system2_type> next_iteration;
-//
-// static const bool value = convertible_type::value && next_iteration::value;
-// };
-//};
-//
-//template<>
-//struct implicit_conversion_homo_to_homo_impl<0>
-//{
-// template<class Begin, class system1_type, class system2_type>
-// struct apply
-// {
-// typedef one type;
-//
-// static const bool value = true;
-// };
-//};
-//
-//// check if implicit conversion is allowed between homogeneous and heterogeneous systems
-//// NB UNTESTED
-//template<int N>
-//struct implicit_conversion_homo_to_hetero_impl
-//{
-// template<class Begin, class system1_type>
-// struct apply
-// {
-// typedef homogeneous_system<typename detail::get_tag<typename mpl::deref<Begin>::type>::type> system2_type;
-// typedef typename detail::get_value<typename mpl::deref<Begin>::type>::type value_type;
-//
-// typedef typename mpl::next<Begin>::type next;
-// typedef typename mpl::begin<value_type>::type begin;
-//
-// typedef typename implicit_conversion_homo_to_homo_impl<mpl::size<value_type>::value>::template
-// apply<begin, system1_type, system2_type> convert_system;
-//
-// typedef typename implicit_conversion_homo_to_hetero_impl<N - 1>::template
-// apply<next, system1_type> next_iteration;
-//
-// static const bool value = convert_system::value && next_iteration::value;
-// };
-//};
-//
-//template<>
-//struct implicit_conversion_homo_to_hetero_impl<0>
-//{
-// template<class Begin, class system1_type, class system2_type>
-// struct apply
-// {
-// typedef one type;
-//
-// static const bool value = true;
-// };
-//};
-//
-//// check if implicit conversion is allowed between homogeneous and heterogeneous systems
-///// NB UNTESTED
-//template<int N>
-//struct implicit_conversion_hetero_to_homo_impl
-//{
-// template<class Begin, class system2_type>
-// struct apply
-// {
-// typedef homogeneous_system<typename detail::get_tag<typename mpl::deref<Begin>::type>::type> system1_type;
-// typedef typename detail::get_value<typename mpl::deref<Begin>::type>::type value_type;
-//
-// typedef typename mpl::next<Begin>::type next;
-// typedef typename mpl::begin<value_type>::type begin;
-//
-// typedef typename implicit_conversion_homo_to_homo_impl<mpl::size<value_type>::value>::template
-// apply<begin, system1_type, system2_type> convert_system;
-//
-// typedef typename implicit_conversion_hetero_to_homo_impl<N - 1>::template
-// apply<next, system2_type> next_iteration;
-//
-// static const bool value = convert_system::value && next_iteration::value;
-// };
-//};
-//
-//template<>
-//struct implicit_conversion_hetero_to_homo_impl<0>
-//{
-// template<class Begin, class system1_type, class system2_type>
-// struct apply
-// {
-// typedef one type;
-//
-// static const bool value = true;
-// };
-//};
-//
-//} // namespace detail
-//
-//} // namespace units
-//
-//} // namespace boost
+namespace boost {
+
+namespace units {
+
+template<class Dim,class System> class unit;
+
+namespace detail {
+
+template<int N>
+struct implicit_conversion_impl;
+
+template<class From, class To>
+struct base_unit_is_implicitly_convertible : mpl::false_ {};
+
+template<class From>
+struct base_unit_is_implicitly_convertible<From, BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(From, typename From::dimension_type)> : mpl::true_ {};
+
+template<bool condition>
+struct implicit_conversion_func;
+
+template<>
+struct implicit_conversion_func<true>
+{
+ template<int N, class Begin, class System>
+ struct apply
+ {
+ enum { value = implicit_conversion_impl<N-1>::template apply<typename mpl::next<Begin>::type, System>::value};
+ };
+};
+
+template<>
+struct implicit_conversion_func<false>
+{
+ template<int N, class Begin, class System>
+ struct apply
+ {
+ enum { value = false };
+ };
+};
+
+template<int N>
+struct implicit_conversion_impl
+{
+ template<class Begin, class System>
+ struct apply
+ {
+ typedef typename mpl::deref<Begin>::type::tag_type current;
+ typedef typename reduce_unit<unit<typename current::dimension_type, System> >::type target_unit;
+ enum { value = (implicit_conversion_func<base_unit_is_implicitly_convertible<current, target_unit>::value>::template apply<N, Begin, System>::value) };
+ };
+};
+
+template<>
+struct implicit_conversion_impl<0>
+{
+ template<class Begin, class System>
+ struct apply
+ {
+ enum { value = true };
+ };
+};
+
+template<class From, class To>
+struct unit_is_implicitly_convertible {
+ typedef typename reduce_unit<From>::type::system_type::type list;
+ typedef mpl::bool_<(implicit_conversion_impl<mpl::size<list>::value>::template apply<typename mpl::begin<list>::type, typename To::system_type>::value)> type;
+};
+
+} // namespace detail
+
+#define BOOST_UNITS_IMPLICIT_CONVERSION(From, To) \
+ namespace boost { \
+ namespace units { \
+ namespace detail { \
+ template<> \
+ struct base_unit_is_implicitly_convertible<From, To> : mpl::true_ {}; \
+ } \
+ } \
+ }
+
+#define BOOST_UNITS_BASE_IMPLICIT_CONVERSION(From, To) \
+ namespace boost { \
+ namespace units { \
+ namespace detail { \
+ template<> \
+ struct base_unit_is_implicitly_convertible< \
+ From, \
+ BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(To, From::dimension_type) \
+ > : mpl::true_ {}; \
+ } \
+ } \
+ }
+
+} // namespace units
+
+} // namespace boost
 
 #endif // BOOST_UNITS_UNIT_IMPL_HPP

Modified: sandbox/units/boost/units/unit.hpp
==============================================================================
--- sandbox/units/boost/units/unit.hpp (original)
+++ sandbox/units/boost/units/unit.hpp 2007-07-30 19:07:16 EDT (Mon, 30 Jul 2007)
@@ -21,8 +21,8 @@
 #include <boost/units/units_fwd.hpp>
 #include <boost/units/homogeneous_system.hpp>
 #include <boost/units/heterogeneous_system.hpp>
+#include <boost/units/implicit_conversion.hpp>
 #include <boost/units/static_rational.hpp>
-#include <boost/units/detail/unit_impl.hpp>
 
 namespace boost {
 
@@ -76,10 +76,13 @@
 
 template<class S1,class S2>
 struct is_implicitly_convertible :
- //public mpl::false_
     boost::is_same<typename reduce_unit<S1>::type, typename reduce_unit<S2>::type>
 { };
 
+template<class D, class S1, class S2>
+struct is_implicitly_convertible<unit<D, homogeneous_system<S1> >, unit<D, homogeneous_system<S2> > >
+ : detail::unit_is_implicitly_convertible<unit<D, homogeneous_system<S1> >, unit<D, homogeneous_system<S2> > >::type {};
+
 #endif
 
 /// unit unary plus typeof helper

Modified: sandbox/units/boost/units/units_fwd.hpp
==============================================================================
--- sandbox/units/boost/units/units_fwd.hpp (original)
+++ sandbox/units/boost/units/units_fwd.hpp 2007-07-30 19:07:16 EDT (Mon, 30 Jul 2007)
@@ -11,7 +11,10 @@
 #ifndef BOOST_UNITS_UNITSFWD_HPP
 #define BOOST_UNITS_UNITSFWD_HPP
 
-/// \file Forward declarations of library components.
+/// \file
+/// Forward declarations of library components.
+
+#ifndef BOOST_UNITS_DOXYGEN
 
 namespace boost {
 
@@ -49,4 +52,6 @@
 
 } // namespace boost
 
+#endif
+
 #endif // BOOST_UNITS_UNITSFWD_HPP

Modified: sandbox/units/libs/units/doc/Jamfile.v2
==============================================================================
--- sandbox/units/libs/units/doc/Jamfile.v2 (original)
+++ sandbox/units/libs/units/doc/Jamfile.v2 2007-07-30 19:07:16 EDT (Mon, 30 Jul 2007)
@@ -92,12 +92,12 @@
   :
     units
   :
- <dependency>.//units_reference
- <dependency>.//si_reference
- <dependency>.//cgs_reference
- <dependency>.//trig_reference
- <dependency>.//abstract_reference
- <dependency>.//temperature_reference
+ <dependency>units_reference
+ <dependency>si_reference
+ <dependency>cgs_reference
+ <dependency>trig_reference
+ <dependency>abstract_reference
+ <dependency>temperature_reference
     <xsl:param>toc.max.depth=1
     <xsl:param>toc.section.depth=8
     <xsl:param>chunk.section.depth=8


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