Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51961 - in trunk: boost/units/systems/detail libs/units/test
From: steven_at_[hidden]
Date: 2009-03-24 13:00:11


Author: steven_watanabe
Date: 2009-03-24 13:00:09 EDT (Tue, 24 Mar 2009)
New Revision: 51961
URL: http://svn.boost.org/trac/boost/changeset/51961

Log:
Fix return type for division by a constant
Added:
   trunk/libs/units/test/test_constants.cpp (contents, props changed)
Text files modified:
   trunk/boost/units/systems/detail/constants.hpp | 2 +-
   trunk/libs/units/test/Jamfile.v2 | 1 +
   2 files changed, 2 insertions(+), 1 deletions(-)

Modified: trunk/boost/units/systems/detail/constants.hpp
==============================================================================
--- trunk/boost/units/systems/detail/constants.hpp (original)
+++ trunk/boost/units/systems/detail/constants.hpp 2009-03-24 13:00:09 EDT (Tue, 24 Mar 2009)
@@ -69,7 +69,7 @@
 } \
                                                                 \
 template<class T, class Arg1, class Arg2> \
-typename name ## _typeof_helper<typename T::value_type, template_name<Arg1, Arg2> >::type \
+typename name ## _typeof_helper<template_name<Arg1, Arg2>, typename T::value_type>::type \
 operator symbol(const template_name<Arg1, Arg2>& u, const constant<T>& t)\
 { \
     return(u symbol t.value()); \

Modified: trunk/libs/units/test/Jamfile.v2
==============================================================================
--- trunk/libs/units/test/Jamfile.v2 (original)
+++ trunk/libs/units/test/Jamfile.v2 2009-03-24 13:00:09 EDT (Tue, 24 Mar 2009)
@@ -23,6 +23,7 @@
 compile test_complicated_system.cpp ;
 compile test_reduce_unit.cpp ;
 compile test_unscale.cpp ;
+compile test_constants.cpp ;
 
 run test_dimensionless_quantity.cpp ;
 run test_implicit_conversion.cpp ;

Added: trunk/libs/units/test/test_constants.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/units/test/test_constants.cpp 2009-03-24 13:00:09 EDT (Tue, 24 Mar 2009)
@@ -0,0 +1,74 @@
+// Boost.Units - A C++ library for zero-overhead dimensional analysis and
+// unit/quantity manipulation and conversion
+//
+// Copyright (C) 2003-2009 Matthias Christian Schabel
+// Copyright (C) 2007-2009 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 test_constants.cpp
+
+\detailed
+Test all combinations of operators with the constants.
+
+**/
+
+#include <boost/units/systems/detail/constants.hpp>
+#include <boost/units/quantity.hpp>
+#include <boost/units/systems/si/length.hpp>
+#include <boost/units/systems/si/time.hpp>
+
+using boost::units::quantity;
+using boost::units::si::length;
+using boost::units::si::meters;
+using boost::units::si::seconds;
+
+BOOST_UNITS_PHYSICAL_CONSTANT(length_constant, quantity<length>, 2.0 * meters, 0.5 * meters);
+
+template<class T>
+void check_same(const T&, const T&);
+
+template<class T>
+typename T::value_type unwrap(const boost::units::constant<T>&);
+
+template<class T>
+T unwrap(const T&);
+
+#define BOOST_UNITS_CHECK_RESULT(arg1, op, arg2) check_same((arg1) op (arg2), unwrap(arg1) op unwrap(arg2));
+
+void test_add() {
+ BOOST_UNITS_CHECK_RESULT(length_constant, +, length_constant);
+ BOOST_UNITS_CHECK_RESULT(length_constant, +, 1.0 * meters);
+ BOOST_UNITS_CHECK_RESULT(1.0* meters, +, length_constant);
+}
+
+void test_subtract() {
+ BOOST_UNITS_CHECK_RESULT(length_constant, -, length_constant);
+ BOOST_UNITS_CHECK_RESULT(length_constant, -, 1.0 * meters);
+ BOOST_UNITS_CHECK_RESULT(1.0* meters, -, length_constant);
+}
+
+void test_multiply() {
+ BOOST_UNITS_CHECK_RESULT(length_constant, *, length_constant);
+ BOOST_UNITS_CHECK_RESULT(length_constant, *, 1.0 * seconds);
+ BOOST_UNITS_CHECK_RESULT(1.0 * seconds, *, length_constant);
+ BOOST_UNITS_CHECK_RESULT(length_constant, *, 1.0);
+ BOOST_UNITS_CHECK_RESULT(1.0, *, length_constant);
+ BOOST_UNITS_CHECK_RESULT(length_constant, *, seconds);
+ BOOST_UNITS_CHECK_RESULT(seconds, *, length_constant);
+}
+
+void test_divide() {
+ BOOST_UNITS_CHECK_RESULT(length_constant, /, length_constant);
+ BOOST_UNITS_CHECK_RESULT(length_constant, /, 1.0 * seconds);
+ BOOST_UNITS_CHECK_RESULT(1.0 * seconds, /, length_constant);
+ BOOST_UNITS_CHECK_RESULT(length_constant, /, 1.0);
+ BOOST_UNITS_CHECK_RESULT(1.0, /, length_constant);
+ BOOST_UNITS_CHECK_RESULT(length_constant, /, seconds);
+ BOOST_UNITS_CHECK_RESULT(seconds, /, length_constant);
+}


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