Compare commits

..

2 Commits

Author SHA1 Message Date
0503056f41 Release 1.51.0
[SVN r80098]
2012-08-20 22:07:05 +00:00
72cd223130 Merge [67751] from the trunk.
[SVN r71382]
2011-04-19 20:10:43 +00:00
2 changed files with 45 additions and 0 deletions

View File

@ -29,6 +29,8 @@
#include <ostream>
#endif
#include <sstream>
#include "boost/tuple/tuple.hpp"
// This is ugly: one should be using twoargument isspace since whitspace can
@ -244,6 +246,22 @@ print(std::ostream& o, const cons<T1, T2>& t) {
}
template<class T>
inline bool handle_width(std::ostream& o, const T& t) {
std::streamsize width = o.width();
if(width == 0) return false;
std::ostringstream ss;
ss.copyfmt(o);
ss.tie(0);
ss.width(0);
ss << t;
o << ss.str();
return true;
}
#else
@ -280,6 +298,23 @@ print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
return print(o, t.tail);
}
template<class CharT, class Traits, class T>
inline bool handle_width(std::basic_ostream<CharT, Traits>& o, const T& t) {
std::streamsize width = o.width();
if(width == 0) return false;
std::basic_ostringstream<CharT, Traits> ss;
ss.copyfmt(o);
ss.tie(0);
ss.width(0);
ss << t;
o << ss.str();
return true;
}
#endif // BOOST_NO_TEMPLATED_STREAMS
} // namespace detail
@ -288,6 +323,7 @@ print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
inline std::ostream& operator<<(std::ostream& o, const null_type& t) {
if (!o.good() ) return o;
if (detail::handle_width(o, t)) return o;
const char l =
detail::format_info::get_manipulator(o, detail::format_info::open);
@ -303,6 +339,7 @@ inline std::ostream& operator<<(std::ostream& o, const null_type& t) {
template<class T1, class T2>
inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
if (!o.good() ) return o;
if (detail::handle_width(o, t)) return o;
const char l =
detail::format_info::get_manipulator(o, detail::format_info::open);
@ -325,6 +362,7 @@ inline std::basic_ostream<CharType, CharTrait>&
operator<<(std::basic_ostream<CharType, CharTrait>& o,
const null_type& t) {
if (!o.good() ) return o;
if (detail::handle_width(o, t)) return o;
const CharType l =
detail::format_info::get_manipulator(o, detail::format_info::open);
@ -342,6 +380,7 @@ inline std::basic_ostream<CharType, CharTrait>&
operator<<(std::basic_ostream<CharType, CharTrait>& o,
const cons<T1, T2>& t) {
if (!o.good() ) return o;
if (detail::handle_width(o, t)) return o;
const CharType l =
detail::format_info::get_manipulator(o, detail::format_info::open);

View File

@ -20,6 +20,7 @@
#include <iterator>
#include <algorithm>
#include <string>
#include <iomanip>
#if defined BOOST_NO_STRINGSTREAM
#include <strstream>
@ -77,6 +78,11 @@ int test_main(int argc, char * argv[] ) {
os3 << set_close(']');
os3 << make_tuple();
BOOST_CHECK (os3.str() == std::string("()[]") );
// check width
useThisOStringStream os4;
os4 << std::setw(10) << make_tuple(1, 2, 3);
BOOST_CHECK (os4.str() == std::string(" (1 2 3)") );
std::ofstream tmp("temp.tmp");