Boost logo

Boost-Commit :

From: steven_at_[hidden]
Date: 2007-08-27 18:07:18


Author: steven_watanabe
Date: 2007-08-27 18:07:17 EDT (Mon, 27 Aug 2007)
New Revision: 39023
URL: http://svn.boost.org/trac/boost/changeset/39023

Log:
Specializations for dimensionless_type now handle the special heterogeneous dimensionless unit
Added:
   sandbox/units/boost/units/detail/dimensionless_unit.hpp (contents, props changed)
Text files modified:
   sandbox/units/boost/units/quantity.hpp | 28 ++++++++++++++++++----------
   1 files changed, 18 insertions(+), 10 deletions(-)

Added: sandbox/units/boost/units/detail/dimensionless_unit.hpp
==============================================================================
--- (empty file)
+++ sandbox/units/boost/units/detail/dimensionless_unit.hpp 2007-08-27 18:07:17 EDT (Mon, 27 Aug 2007)
@@ -0,0 +1,49 @@
+// 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_DETAIL_DIMENSIONLESS_UNIT_HPP
+#define BOOST_UNITS_DETAIL_DIMENSIONLESS_UNIT_HPP
+
+#include <boost/utility/enable_if.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/units/units_fwd.hpp>
+#include <boost/units/heterogeneous_system.hpp>
+#include <boost/units/homogeneous_system.hpp>
+
+namespace boost {
+namespace units {
+namespace detail {
+
+template<class T>
+struct is_dimensionless_system : boost::mpl::false_ {};
+
+template<class T>
+struct is_dimensionless_system<boost::units::homogeneous_system<T> > : boost::mpl::true_ {};
+
+template<>
+struct is_dimensionless_system<
+ boost::units::heterogeneous_system<
+ boost::units::heterogeneous_system_pair<
+ boost::units::dimensionless_type,
+ boost::units::dimensionless_type
+ >
+ >
+> : boost::mpl::true_ {};
+
+#define BOOST_UNITS_DIMENSIONLESS_UNIT(T)\
+ boost::units::unit<typename boost::enable_if<boost::units::detail::is_dimensionless_system<T>, boost::units::dimensionless_type>::type, T>
+
+#define BOOST_UNITS_HETEROGENEOUS_DIMENSIONLESS_UNIT(T) boost::units::unit<typename boost::disable_if<boost::units::detail::is_dimensionless_system<T>, boost::units::dimensionless_type>::type, T>
+
+}
+}
+}
+
+#endif

Modified: sandbox/units/boost/units/quantity.hpp
==============================================================================
--- sandbox/units/boost/units/quantity.hpp (original)
+++ sandbox/units/boost/units/quantity.hpp 2007-08-27 18:07:17 EDT (Mon, 27 Aug 2007)
@@ -31,6 +31,7 @@
 #include <boost/units/operators.hpp>
 #include <boost/units/static_rational.hpp>
 #include <boost/units/units_fwd.hpp>
+#include <boost/units/detail/dimensionless_unit.hpp>
 
 namespace boost {
 
@@ -269,11 +270,10 @@
 /// unit systems are allowed because all dimensionless quantities are equivalent.
 /// Implicit construction and assignment from and conversion to @c value_type is
 /// also allowed.
-template<class SystemTag,class Y>
-class quantity<unit<dimensionless_type,homogeneous_system<SystemTag> >,Y>
+template<class System,class Y>
+class quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System),Y>
 {
     public:
- typedef homogeneous_system<SystemTag> System;
         typedef quantity<unit<dimensionless_type,System>,Y> this_type;
                                    
         typedef Y value_type;
@@ -353,9 +353,9 @@
 
         /// implicit conversion between different unit systems is allowed
         template<class System2, class Y2>
- quantity(const quantity<unit<dimensionless_type,homogeneous_system<System2> >,Y2>& source,
+ quantity(const quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System2),Y2>& source,
             typename boost::enable_if<detail::is_non_narrowing_conversion<Y2, Y>,
- typename detail::disable_if_is_same<SystemTag, System2>::type>::type* = 0) :
+ typename detail::disable_if_is_same<System, System2>::type>::type* = 0) :
             val_(source.value())
         {
             BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
@@ -363,9 +363,9 @@
 
         /// implicit conversion between different unit systems is allowed
         template<class System2, class Y2>
- explicit quantity(const quantity<unit<dimensionless_type,homogeneous_system<System2> >,Y2>& source,
+ explicit quantity(const quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System2),Y2>& source,
             typename boost::disable_if<detail::is_non_narrowing_conversion<Y2, Y>,
- typename detail::disable_if_is_same<SystemTag, System2>::type>::type* = 0) :
+ typename detail::disable_if_is_same<System, System2>::type>::type* = 0) :
             val_(static_cast<Y>(source.value()))
         {
             BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
@@ -387,15 +387,15 @@
         /// conversion between different unit systems is explicit when
         /// the units are not equivalent.
         template<class System2, class Y2>
- explicit quantity(const quantity<unit<dimensionless_type,System2>,Y2>& source) :
- val_(conversion_helper<quantity<unit<dimensionless_type,System2>,Y2>, this_type>::convert(source).value())
+ explicit quantity(const quantity<BOOST_UNITS_HETEROGENEOUS_DIMENSIONLESS_UNIT(System2),Y2>& source) :
+ val_(conversion_helper<quantity<BOOST_UNITS_HETEROGENEOUS_DIMENSIONLESS_UNIT(System2),Y2>, this_type>::convert(source).value())
         {
             BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
         }
 
         /// implicit assignment between different unit systems is allowed
         template<class System2>
- this_type& operator=(const quantity<unit<dimensionless_type,homogeneous_system<System2> >,Y>& source)
+ this_type& operator=(const quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System2),Y>& source)
         {
             *this = this_type(source);
             
@@ -426,6 +426,14 @@
         value_type val_;
 };
 
+#ifdef BOOST_MSVC
+// HACK: For some obscure reason msvc 8.0 needs these specializations
+template<class System, class T>
+class quantity<unit<int, System>, T> {};
+template<class T>
+class quantity<int, T> {};
+#endif
+
 } // namespace units
 
 } // namespace boost


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