$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] [units]
From: Thomas Taylor (thomas.taylor_at_[hidden])
Date: 2011-08-30 04:04:04
Could you please review the following patch for inclusion in boost::units?
*WHY*: Obviously this only defines a conversion for boost::units::one to a 
numerical 1. When trying to convert at runtime (aiming for a runtime/dynamic 
unit instead of the compiletime/static unit provided) I use the following 
function:
template <typename U1, typename U2>
double unit_dispatch2t(U1 const& u1, U2 const& u2) {
    return bu::conversion_factor(u1,u2);
}
where U1 and U2 are boost::unit::unit derivatives.
Without a conversion operator the compiler chickens out by claiming to not 
be able to convert boost::units::one to (in my case) double. The added 
conversion operator allows successfull compilation, thus allowing actual 
runtime units (my application needs to handle calculations where some units 
are known at compiletime and some only at runtime (e.g. the user wants the 
calculation to be done in meters or millimeters)).
HTH,
Thomas
--- one.hpp     2011-08-30 09:50:13.000000000 +0200
+++ one2.hpp    2011-08-30 09:50:07.000000000 +0200
@@ -19,3 +19,3 @@
 
-struct one { one() {} };
+struct one { one() {} operator int() { return 1; } };