Not sure if it is relevant but, boost::iostreams::copy() closes the stream and calls destructor on it.  So my guess is states are reset upon destruction.
-Anand

On Thu, Apr 29, 2010 at 1:00 PM, Nicola <nvitacolonna@gmail.com> wrote:
Hi,
can someone tell me if the behaviour of the enclosed example is a bug?
In my test, the last two assertions fail, but I don't understand why
(Boost 1.42.0).

Thanks,
Nicola

#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <cassert>
#include <fstream>
#include <sstream>

struct bz2istream :
public boost::iostreams::filtering_stream<boost::iostreams::input>
{
public:
  bz2istream(std::string const& path) :
     pBz2file(path.c_str(), std::ios_base::in | std::ios_base::binary)
  {
     push(boost::iostreams::bzip2_decompressor());
     push(pBz2file);
  }
private:
  std::ifstream pBz2file;
};

int main() {
  bz2istream bzippedfile("foo.bz2");
  std::ostringstream os;
  boost::iostreams::copy(bzippedfile, os);

  assert(!(bzippedfile.rdstate() & std::ios_base::goodbit)); // Ok
  assert(bzippedfile.rdstate() & std::ios_base::eofbit); // Fails
  assert(!(bzippedfile.good())); // Fails
}

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users