Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] - overriding output
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2009-09-15 19:24:08


Matthias Schabel wrote:
>> What is the correct way to override the << op for a unit so that it
>> say prints "Pa" instead of "m^-1 kg s^-2"?
>>
>> I tried this and no worky:
>>
>> #include <boost/units/io.hpp>
>>
>> namespace boost { namespace units {
>>
>>
>> template<>
>> inline std::string
>> name_string< boost::units::pressure_dimension,
>> boost::units::si::system >(const boost::units::si::pressure&)
>> {
>> return "Pa";
>> }
>>
>> }} // boost::units
>
> "name_string" and "symbol_string" aren't templated - they are overloaded
> functions, so the template is not correct. Also, you defined
> "name_string", which is for fully-formatted unit output (e.g. "pascal"
> vs. "Pa"), so you are overloading the wrong function here. The easy way
> is to include the SI IO header :
>
> #include <boost/units/io.hpp>
> #include <boost/units/quantity.hpp>
> #include <boost/units/systems/si.hpp>
> #include <boost/units/systems/si/io.hpp>

Well, thanks. Unfortunately although this works for every test program
I can imagine that looks like my production code....it just plain
doesn't in the actual code I'm trying to develop. No matter what I do,
it always prints out m^-1 kg s^-2 for the unit and no matter how I wrap
up typedefs and usings inside my own namespace I can't reproduce the
problem in simple code. Some demon from the deepest pit of hell is
keeping the overload resolution from working only in production code.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net