Modify

Ticket #7261 (new Bugs)

Opened 5 years ago

Boost.Units quantity output overflows ostream width field

Reported by: pbristow Owned by: steven_watanabe
Milestone: To Be Determined Component: units
Version: Boost 1.52.0 Severity: Problem
Keywords: units ostream width overflow Cc: boost@…

Description

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).

Attachments

io.hpp.diff (1.8 KB) - added by pbristow 5 years ago.
Unified diff for units/boost/io.hpp
units_measure_width_test.cpp (3.3 KB) - added by pbristow 5 years ago.
Test file for changes to IO.hpp to correct width overflow
measurement.hpp.diff (9.7 KB) - added by pbristow 5 years ago.
Diff for changes to /example/measurement.hpp to honor width

Change History

Changed 5 years ago by pbristow

Unified diff for units/boost/io.hpp

Changed 5 years ago by pbristow

Test file for changes to IO.hpp to correct width overflow

Changed 5 years ago by pbristow

Diff for changes to /example/measurement.hpp to honor width

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.