|
Boost Users : |
From: Andrew McDonald (andrew.mcdonald_at_[hidden])
Date: 2006-05-11 03:46:34
Hi,
I have just recently started using the boost::iostreams library, so apologies if my question is obvious.
I have tried checking doco and mailing list to see if this issue is already covered.
I am using boost_1_33_1, in Microsoft Visual C++ 2005 Express Edition version 8.0.50727.42.
Boost has been built with the vc-8_0 toolset.
When attempting to use pipelines with filtering_streams I get an error when attempting to add an ostream as the (terminating) device for the pipeline
The following (inline) test program illustrates various combinations that compile with the problem usage as the last example
===============================================================
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/regex.hpp>
#include <boost/iostreams/device/file.hpp>
#include <iostream>
using namespace boost::iostreams;
void test(std::ostream& os, regex_filter& f)
{
// pipeline with no device - ok
{
filtering_ostream out( f | f );
out.push(os);
}
// explicitly pushing file sink - ok
{
filtering_ostream out( f | f );
out.push(file_sink("test.txt"));
}
// explicitly pushing ostream - ok
{
filtering_ostream out( f | f );
out.push(os);
}
// only a file sink - ok
{
filtering_ostream out(file_sink("test.txt"));
}
// only an ostream - ok
{
filtering_ostream out(os);
}
// pipeline with file sink - ok
{
filtering_ostream out( f | f | file_sink("test.txt") );
}
// pipline with ostream - not ok !!
{
// compilation error
filtering_ostream out( f | f | os );
}
}
===============================================================
The error generated is:
boost/iostreams/pipeline.hpp(107) : error C2664: 'void boost::iostreams::detail::chain_client<Chain>::push<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,int,int)' : cannot convert parameter 1 from 'const std::ostream' to 'std::basic_ostream<_Elem,_Traits> &'
with
[
Chain=boost::iostreams::chain<boost::iostreams::output,char,std::char_traits<char>,std::allocator<char>>,
_Elem=char,
_Traits=std::char_traits<char>
]
and
[
_Elem=char,
_Traits=std::char_traits<char>
]
Conversion loses qualifiers
This appears to be caused by the fact that the implementation of the push() method on struct pipeline
calls chn.push(component_);
where the component_ member is held by const ref.
The push() method on Chain is generated with
BOOST_IOSTREAMS_DEFINE_PUSH(push, mode, char_type, push_impl)
which is commented with a cut-and-paste of the comment for the preceding macro, as
//
// Macro: BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(mode, name, helper).
// Description: Defines constructors which forward to a function
// 'helper' which takes a filter or device by const reference.
However via BOOST_IOSTREAMS_DEFINE_PUSH_IMPL this appears to generate a method requiring a non-const reference;
::std::basic_streambuf<CharType, TraitsType>& sb
Am I missing something here ?
I was wondering whether this was intentional and whether the syntactic form
filtering_ostream out( f | f | os )
was meant to be supported.
Andrew McDonald
System Architect
> Norwood Systems Australia Pty Ltd
Level 1, 71 Troy Terrace
PO Box 1281
Subiaco, WA 6904
> Tel +61 8 9380 7766
> Fax +61 8 9380 7733
andrew.mcdonald_at_[hidden]
>
> The information in this email, and any attachments, may contain confidential information and is intended solely for the attention and use of the named addressee (s). It must not be disclosed to any person(s) without authorization. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorized to, and must not, disclose, copy, distribute, or retain this message or any part of> it. If you have received this communication in error, please notify the sender immediately.
>
>
>
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net