Boost logo

Boost-Commit :

From: steven_watanabe_at_[hidden]
Date: 2007-05-30 14:17:00


Author: steven_watanabe
Date: 2007-05-30 14:16:59 EDT (Wed, 30 May 2007)
New Revision: 4367
URL: http://svn.boost.org/trac/boost/changeset/4367

Log:
Make addition/subtraction of absolute temperatures fail

Added:
   sandbox/units/libs/units/test/fail_add_temperature.cpp
Text files modified:
   sandbox/units/boost/units/quantity.hpp | 37 ++++++++++++++++++++++++++++++++-----
   sandbox/units/libs/units/example/Jamfile.v2 | 2 --
   sandbox/units/libs/units/test/Jamfile.v2 | 1 +
   3 files changed, 33 insertions(+), 7 deletions(-)

Modified: sandbox/units/boost/units/quantity.hpp
==============================================================================
--- sandbox/units/boost/units/quantity.hpp (original)
+++ sandbox/units/boost/units/quantity.hpp 2007-05-30 14:16:59 EDT (Wed, 30 May 2007)
@@ -202,16 +202,43 @@
         const value_type& value() const { return val_; } ///< constant accessor to value
         
         ///< can add a quantity of the same type if add_typeof_helper<value_type,value_type>::type is convertible to value_type
- this_type& operator+=(const this_type& source) { val_ += source.val_; return *this; }
+ template<class Unit2, class YY>
+ this_type& operator+=(const quantity<Unit2, YY>& source)
+ {
+ BOOST_STATIC_ASSERT((boost::is_same<typename add_typeof_helper<Unit, Unit2>::type, Unit>::value));
+ val_ += source.value();
+ return *this;
+ }
 
         ///< can subtract a quantity of the same type if subtract_typeof_helper<value_type,value_type>::type is convertible to value_type
- this_type& operator-=(const this_type& source) { val_ -= source.val_; return *this; }
+ template<class Unit2, class YY>
+ this_type& operator-=(const quantity<Unit2, YY>& source)
+ {
+ BOOST_STATIC_ASSERT((boost::is_same<typename subtract_typeof_helper<Unit, Unit2>::type, Unit>::value));
+ val_ -= source.val_;
+ return *this;
+ }
 
- ///< can multiply a quantity by a scalar value_type if multiply_typeof_helper<value_type,value_type>::type is convertible to value_type
- this_type& operator*=(const value_type& val) { val_ *= val; return *this; }
+ template<class Unit2, class YY>
+ this_type& operator*=(const quantity<Unit2, YY>& source)
+ {
+ BOOST_STATIC_ASSERT((boost::is_same<typename multiply_typeof_helper<Unit, Unit2>::type, Unit>::value));
+ val_ *= source.value();
+ return *this;
+ }
         
+ template<class Unit2, class YY>
+ this_type& operator/=(const quantity<Unit2, YY>& source)
+ {
+ BOOST_STATIC_ASSERT((boost::is_same<typename divide_typeof_helper<Unit, Unit2>::type, Unit>::value));
+ val_ /= source.value();
+ return *this;
+ }
+
+ ///< can multiply a quantity by a scalar value_type if multiply_typeof_helper<value_type,value_type>::type is convertible to value_type
+ this_type& operator*=(const value_type& source) { val_ *= source; return *this; }
         ///< can divide a quantity by a scalar value_type if divide_typeof_helper<value_type,value_type>::type is convertible to value_type
- this_type& operator/=(const value_type& val) { val_ /= val; return *this; }
+ this_type& operator/=(const value_type& source) { val_ /= source; return *this; }
     
         /// Construct quantity directly from @c value_type (potentially dangerous).
         static this_type from_value(const value_type& val) { return this_type(val); }

Modified: sandbox/units/libs/units/example/Jamfile.v2
==============================================================================
--- sandbox/units/libs/units/example/Jamfile.v2 (original)
+++ sandbox/units/libs/units/example/Jamfile.v2 2007-05-30 14:16:59 EDT (Wed, 30 May 2007)
@@ -9,8 +9,6 @@
 
 UNITS_REQUIREMENTS = <include>$(BOOST_ROOT) <include>../../.. <warnings>all ;
 
-ECHO $(BOOST_ROOT)/libs/serialization/build//boost_serialization ;
-
 import testing ;
 
 {

Modified: sandbox/units/libs/units/test/Jamfile.v2
==============================================================================
--- sandbox/units/libs/units/test/Jamfile.v2 (original)
+++ sandbox/units/libs/units/test/Jamfile.v2 2007-05-30 14:16:59 EDT (Wed, 30 May 2007)
@@ -40,6 +40,7 @@
     [ compile-fail fail_adl_detail.cpp : $(UNIT_REQUIREMENTS) : ]
     [ compile-fail fail_heterogeneous_unit.cpp : $(UNIT_REQUIREMENTS) : ]
     [ compile-fail fail_base_dimension.cpp : $(UNIT_REQUIREMENTS) : ]
+ [ compile-fail fail_add_temperature.cpp : $(UNIT_REQUIREMENTS) : ]
    ;
 
 }

Added: sandbox/units/libs/units/test/fail_add_temperature.cpp
==============================================================================
--- (empty file)
+++ sandbox/units/libs/units/test/fail_add_temperature.cpp 2007-05-30 14:16:59 EDT (Wed, 30 May 2007)
@@ -0,0 +1,37 @@
+// 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)
+
+/**
+\file
+
+\brief fail_add_temperature.cpp
+
+\detailed
+Verify that adding two absolute temeratures fails miserably.
+
+Output:
+@verbatim
+@endverbatim
+**/
+
+#include <boost/units/quantity.hpp>
+#include <boost/units/systems/si/temperature.hpp>
+
+namespace bu = boost::units;
+
+int main(int,char *[])
+{
+
+ bu::quantity<bu::absolute<bu::SI::temperature> > q(2.0 * bu::absolute<bu::SI::temperature>());
+
+ q += q;
+
+ return 0;
+}


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