forked from boostorg/tuple
@ -29,6 +29,8 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "boost/tuple/tuple.hpp"
|
#include "boost/tuple/tuple.hpp"
|
||||||
|
|
||||||
// This is ugly: one should be using twoargument isspace since whitspace can
|
// 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
|
#else
|
||||||
@ -280,6 +298,23 @@ print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
|
|||||||
return print(o, t.tail);
|
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
|
#endif // BOOST_NO_TEMPLATED_STREAMS
|
||||||
|
|
||||||
} // namespace detail
|
} // 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) {
|
inline std::ostream& operator<<(std::ostream& o, const null_type& t) {
|
||||||
if (!o.good() ) return o;
|
if (!o.good() ) return o;
|
||||||
|
if (detail::handle_width(o, t)) return o;
|
||||||
|
|
||||||
const char l =
|
const char l =
|
||||||
detail::format_info::get_manipulator(o, detail::format_info::open);
|
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>
|
template<class T1, class T2>
|
||||||
inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
|
inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
|
||||||
if (!o.good() ) return o;
|
if (!o.good() ) return o;
|
||||||
|
if (detail::handle_width(o, t)) return o;
|
||||||
|
|
||||||
const char l =
|
const char l =
|
||||||
detail::format_info::get_manipulator(o, detail::format_info::open);
|
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,
|
operator<<(std::basic_ostream<CharType, CharTrait>& o,
|
||||||
const null_type& t) {
|
const null_type& t) {
|
||||||
if (!o.good() ) return o;
|
if (!o.good() ) return o;
|
||||||
|
if (detail::handle_width(o, t)) return o;
|
||||||
|
|
||||||
const CharType l =
|
const CharType l =
|
||||||
detail::format_info::get_manipulator(o, detail::format_info::open);
|
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,
|
operator<<(std::basic_ostream<CharType, CharTrait>& o,
|
||||||
const cons<T1, T2>& t) {
|
const cons<T1, T2>& t) {
|
||||||
if (!o.good() ) return o;
|
if (!o.good() ) return o;
|
||||||
|
if (detail::handle_width(o, t)) return o;
|
||||||
|
|
||||||
const CharType l =
|
const CharType l =
|
||||||
detail::format_info::get_manipulator(o, detail::format_info::open);
|
detail::format_info::get_manipulator(o, detail::format_info::open);
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#if defined BOOST_NO_STRINGSTREAM
|
#if defined BOOST_NO_STRINGSTREAM
|
||||||
#include <strstream>
|
#include <strstream>
|
||||||
@ -77,6 +78,11 @@ int test_main(int argc, char * argv[] ) {
|
|||||||
os3 << set_close(']');
|
os3 << set_close(']');
|
||||||
os3 << make_tuple();
|
os3 << make_tuple();
|
||||||
BOOST_CHECK (os3.str() == std::string("()[]") );
|
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");
|
std::ofstream tmp("temp.tmp");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user