forked from boostorg/tuple
Compare commits
25 Commits
boost-1.46
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
671495a8ce | |||
f904cd5d69 | |||
2b30eb2225 | |||
9fbc9b4cc6 | |||
9d64187c34 | |||
7b6203747a | |||
1b07c1a2d4 | |||
052b3db77f | |||
d908a5d566 | |||
a75a686fae | |||
b7c2e00b64 | |||
e89ea11d63 | |||
08277fd057 | |||
70e04d2965 | |||
451415ebce | |||
e9dc95ae93 | |||
1d1970d81d | |||
4e452cb734 | |||
776be602e5 | |||
a30a7f9604 | |||
62d366fa68 | |||
d08c9bfab1 | |||
19b8004830 | |||
0af5b76442 | |||
defe1c94d6 |
@ -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);
|
||||
|
@ -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");
|
||||
|
||||
|
Reference in New Issue
Block a user