Boost logo

Boost Users :

Subject: [Boost-users] [iostreams] problems with operator<<
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2009-08-25 18:02:43


Hello,
I'm using the container_device class provided in the documentation. I'm
creating my stream and device like so:

typedef boost::iostreams::stream<
  container_device<std::vector<boost::uint8_t > >
> ByteStream;

  ByteStream stream;
  stream << "Hello";

This compiles fine, however when I run this code I get an assertion deep
inside of the << operator, which is in the std namespace. I thought that
boost::iostreams would have its own global << and >> operators? I was
expecting the << operator to directly call my device's write() method, but
it doesn't. Perhaps I just don't understand how this works. I'm trying to
write out binary data. The string should translate to a series of bytes in
the container.

The assertion I'm hitting is in optional.hpp in Boost. I'm using MSVC9 as my
compiler:

    T& operator*()
    {
        assert(initialized_);
        return *static_cast<T*>(address());
    }

Above contains the code snippet where the assertion is happening. I have no
idea what this assert means. Below is my callstack:

> VFDTester.exe!boost::iostreams::detail::optional<boost::iostreams::detail::concept_adapter<container_device<std::vector<unsigned
char,std::allocator<unsigned char> > > > >::operator*() Line 55 + 0x1f
bytes C++
  VFDTester.exe!boost::iostreams::detail::indirect_streambuf<container_device<std::vector<unsigned
char,std::allocator<unsigned char> > >,std::char_traits<unsigned
char>,std::allocator<unsigned char>,boost::iostreams::seekable>::obj() Line
104 + 0x19 bytes C++
  VFDTester.exe!boost::iostreams::detail::indirect_streambuf<container_device<std::vector<unsigned
char,std::allocator<unsigned char> > >,std::char_traits<unsigned
char>,std::allocator<unsigned
char>,boost::iostreams::seekable>::overflow(long c=72) Line 301 + 0x15
bytes C++
  VFDTester.exe!std::basic_streambuf<unsigned char,std::char_traits<unsigned
char> >::sputc(unsigned char _Ch='H') Line 163 + 0x4c bytes C++
  VFDTester.exe!std::operator<<<unsigned char,std::char_traits<unsigned
char> >(std::basic_ostream<unsigned char,std::char_traits<unsigned char> > &
_Ostr={...}, const char * _Val=0x0074a7b0) Line 679 + 0x32 bytes C++
  VFDTester.exe!MainFrame::OnConnectPressed(wxCommandEvent & event={...})
 Line 82 + 0x36 bytes C++

---------
Robert Dailey



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