Boost logo

Boost-Commit :

From: boost_at_[hidden]
Date: 2008-05-25 17:00:33


Author: matthiasschabel
Date: 2008-05-25 17:00:32 EDT (Sun, 25 May 2008)
New Revision: 45751
URL: http://svn.boost.org/trac/boost/changeset/45751

Log:
demo of problem with current method of overloading operator<< for unit output
Text files modified:
   sandbox/units/libs/units/example/composite_output.cpp | 36 +++++++++++++++++++++++++++++++++++-
   1 files changed, 35 insertions(+), 1 deletions(-)

Modified: sandbox/units/libs/units/example/composite_output.cpp
==============================================================================
--- sandbox/units/libs/units/example/composite_output.cpp (original)
+++ sandbox/units/libs/units/example/composite_output.cpp 2008-05-25 17:00:32 EDT (Sun, 25 May 2008)
@@ -12,6 +12,7 @@
 #include <boost/units/systems/cgs.hpp>
 #include <boost/units/io.hpp>
 #include <iostream>
+#include <sstream>
 
 namespace boost {
 
@@ -25,10 +26,43 @@
 
 //]
 
+template<class T>
+std::string symbol_string(const T& x)
+{
+ std::stringstream sstr;
+
+ sstr << symbol_format << x;
+
+ return sstr.str();
 }
 
+template<class T>
+std::string name_string(const T& x)
+{
+ std::stringstream sstr;
+
+ sstr << name_format << x;
+
+ return sstr.str();
 }
 
-int main() {
+template<class Y>
+std::string name_string(const quantity<cgs::force,Y>& x)
+{
+ return "dyne";
+}
+
+}
+
+}
+
+int main()
+{
     std::cout << 2.0 * boost::units::cgs::dyne << std::endl;
+
+ std::cout << boost::units::symbol_format << 2.0 * boost::units::cgs::dyne << std::endl;
+ std::cout << boost::units::name_format << 2.0 * boost::units::cgs::dyne << std::endl;
+
+ std::cout << boost::units::symbol_string(2.0*boost::units::cgs::dyne) << std::endl;
+ std::cout << boost::units::name_string(2.0*boost::units::cgs::dyne) << std::endl;
 }


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