mirror of
https://github.com/boostorg/tuple.git
synced 2025-07-30 20:57:15 +02:00
Allow printing an empty tuple
[SVN r53211]
This commit is contained in:
@ -285,6 +285,21 @@ print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
|
|||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& o, const null_type& t) {
|
||||||
|
if (!o.good() ) return o;
|
||||||
|
|
||||||
|
const char l =
|
||||||
|
detail::format_info::get_manipulator(o, detail::format_info::open);
|
||||||
|
const char r =
|
||||||
|
detail::format_info::get_manipulator(o, detail::format_info::close);
|
||||||
|
|
||||||
|
o << l;
|
||||||
|
o << r;
|
||||||
|
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -305,6 +320,23 @@ inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
template<class CharType, class CharTrait>
|
||||||
|
inline std::basic_ostream<CharType, CharTrait>&
|
||||||
|
operator<<(std::basic_ostream<CharType, CharTrait>& o,
|
||||||
|
const null_type& t) {
|
||||||
|
if (!o.good() ) return o;
|
||||||
|
|
||||||
|
const CharType l =
|
||||||
|
detail::format_info::get_manipulator(o, detail::format_info::open);
|
||||||
|
const CharType r =
|
||||||
|
detail::format_info::get_manipulator(o, detail::format_info::close);
|
||||||
|
|
||||||
|
o << l;
|
||||||
|
o << r;
|
||||||
|
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
template<class CharType, class CharTrait, class T1, class T2>
|
template<class CharType, class CharTrait, class T1, class T2>
|
||||||
inline std::basic_ostream<CharType, CharTrait>&
|
inline std::basic_ostream<CharType, CharTrait>&
|
||||||
operator<<(std::basic_ostream<CharType, CharTrait>& o,
|
operator<<(std::basic_ostream<CharType, CharTrait>& o,
|
||||||
|
@ -70,6 +70,15 @@ int test_main(int argc, char * argv[] ) {
|
|||||||
os1 << make_tuple(1, 2, 3);
|
os1 << make_tuple(1, 2, 3);
|
||||||
BOOST_CHECK (os1.str() == std::string("[1,2,3][1,2,3]") );
|
BOOST_CHECK (os1.str() == std::string("[1,2,3][1,2,3]") );
|
||||||
|
|
||||||
|
// check empty tuple.
|
||||||
|
useThisOStringStream os3;
|
||||||
|
os3 << make_tuple();
|
||||||
|
BOOST_CHECK (os3.str() == std::string("()") );
|
||||||
|
os3 << set_open('[');
|
||||||
|
os3 << set_close(']');
|
||||||
|
os3 << make_tuple();
|
||||||
|
BOOST_CHECK (os3.str() == std::string("()[]") );
|
||||||
|
|
||||||
ofstream tmp("temp.tmp");
|
ofstream tmp("temp.tmp");
|
||||||
|
|
||||||
#if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
#if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
@ -98,12 +107,19 @@ int test_main(int argc, char * argv[] ) {
|
|||||||
|
|
||||||
|
|
||||||
// reading tuple<int, int, int> in format (a b c);
|
// reading tuple<int, int, int> in format (a b c);
|
||||||
useThisIStringStream is("(100 200 300)");
|
useThisIStringStream is1("(100 200 300)");
|
||||||
|
|
||||||
tuple<int, int, int> ti;
|
tuple<int, int, int> ti1;
|
||||||
BOOST_CHECK(bool(is >> ti));
|
BOOST_CHECK(bool(is1 >> ti1));
|
||||||
BOOST_CHECK(ti == make_tuple(100, 200, 300));
|
BOOST_CHECK(ti1 == make_tuple(100, 200, 300));
|
||||||
|
|
||||||
|
useThisIStringStream is2("()");
|
||||||
|
tuple<> ti2;
|
||||||
|
BOOST_CHECK(bool(is2 >> ti2));
|
||||||
|
useThisIStringStream is3("[]");
|
||||||
|
is3 >> set_open('[');
|
||||||
|
is3 >> set_close(']');
|
||||||
|
BOOST_CHECK(bool(is3 >> ti2));
|
||||||
|
|
||||||
// Note that strings are problematic:
|
// Note that strings are problematic:
|
||||||
// writing a tuple on a stream and reading it back doesn't work in
|
// writing a tuple on a stream and reading it back doesn't work in
|
||||||
|
Reference in New Issue
Block a user