[Boost-bugs] [Boost C++ Libraries] #7261: Boost.Units quantity output overflows ostream width field

Subject: [Boost-bugs] [Boost C++ Libraries] #7261: Boost.Units quantity output overflows ostream width field
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-08-22 16:38:37


#7261: Boost.Units quantity output overflows ostream width field
------------------------------------------+---------------------------------
 Reporter: pbristow | Owner: steven_watanabe
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: units
  Version: Boost 1.52.0 | Severity: Problem
 Keywords: units ostream width overflow |
------------------------------------------+---------------------------------
 Boost.Units quantity output overflows ostream width field

      quantity<length> ql = 2345.6 * meters;

      std::cout << std::setw(20) << ql << std::endl;

 outputs 22 chars instead of 20 chars.

 The reason is that the first item value() is output using the ios width
 setting, but the second
 unit() 'm' (and separating space) is not.

 if os.width() > 0 then a way is to build a single string of the quantity
 with the width specified for example using an ostringstream
 (otherwise, outputing value and unit (perhaps autoprefixed to km)
 severally would overflow the width).

 (else if os.width() <= 0 then output directly to ostream os as at
 present).

 A test and a patch to deal with this is attached.

 (This is not necessarily the most efficient way to deal with this but
 appears to work).

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7261>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC