[units] - overriding output
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
(const boost::units::si::pressure&) { return "Pa"; }
}} // boost::units Also, I note that the operator << in io.hpp has a comment saying "INTERNAL USE ONLY". How would you suggest then that users of the library provide for stream output without running afoul of this implementation we're not meant to use?
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
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
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
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
#include #include #include
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.
participants (2)
-
Matthias Schabel
-
Noah Roberts