Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2008-03-01 10:50:07


On 03/01/08 09:40, Roland Schwarz wrote:
> Larry Evans wrote:
>> I couldn't resist trying it now;
> ;-)
>
>> however, I'm getting wrong output :(
>
> Hmm, I did not test it, but from looking at your source:
>
> marg_ostream& mout(void)
> {
> return std::cout;
> }
>
> gives you back std::cout, while it should hand back
> ; boost::iostreams::filtering_ostream out
>
> The state is stored in out instance of course,
> not cout.
>
Right. So, should:

<-- cut here --
#include "indent.hpp"
typedef boost::iostreams::filtering_ostream marg_ostream;
marg_ostream out;
#include <iostream>
marg_ostream& mout(void)
{
     return out;
}
//#define DEBUG_PRINT
void operator++(marg_ostream& sout)
{
     #ifdef DEBUG_PRINT
     sout<<"operator++(marg_ostream&)\n";
     #endif
     sout<<indent_in;
}
void operator--(marg_ostream& sout)
{
     sout<<indent_out;
     #ifdef DEBUG_PRINT
     sout<<"operator--(marg_ostream&)\n";
     #endif
}
...
int main(void)
   {
   ; indent_filter::push(out,2)
   ; out.push(std::cout)
   ; mout()<<"line1\n"
...
>-- cut here --
work? With this change, I get compile errors like:

indent_test.cpp: In function 'marg_ostream& operator<<(marg_ostream&,
const test*)':
indent_test.cpp:60: error: no match for 'operator<<' in 'std::operator<<
[with _Traits = std::char_traits<char>](((std::basic_ostream<char,
std::char_traits<char>
>&)(&((marg_ostream*)sout)->boost::iostreams::filtering_stream<boost::iostreams::output,
char, std::char_traits<char>, std::allocator<char>,
boost::iostreams::public_>::<anonymous>.boost::iostreams::detail::filtering_stream_base<boost::iostreams::chain<boost::iostreams::output,
char, std::char_traits<char>, std::allocator<char> >,
boost::iostreams::public_>::<anonymous>)), ((const char*)"*(test*)="))
<< * a_test'
/usr/include/c++/4.1.3/bits/ostream.tcc:67: note: candidates are:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&
(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits
= std::char_traits<char>]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk