[asio-users] buffers_iterator<detail::consuming_buffers> yields wrong iterator category
Brought to you by:
chris_kohlhoff
From: Torsten@Robitzki.de <To...@ro...> - 2011-02-26 19:01:01
|
Hello, I don't know if this should be considered to be a bug, but it bugs me and maybe others might stumble over it too. I use my own socket class for testing. I implement the AsyncWriteStream type requirments. The problem is, that when I use the passed buffer and construct a buffer_iterator from it's iterator_category is random access, but the resulting iterator doesn't implement the whole category (just read_iterator, if I got it right). Here is a little reproducer, that should generate a compiler error at the "--i" expression: #include <boost/asio.hpp> #include <vector> #include <iterator> void handler( const boost::system::error_code& error, std::size_t bytes_transferred); template <class Iter> void use_random_access_iterator(Iter i, std::random_access_iterator_tag) { --i; } struct socket { template <class CB, class H> void async_write_some(const CB& cb, H h) { typedef boost::asio::buffers_iterator<CB> iter_t; use_random_access_iterator(iter_t(), typename std::iterator_traits<iter_t>::iterator_category()); } }; void f() { std::vector<boost::asio::const_buffers_1> outbuffer; struct socket sock; boost::asio::async_write(sock, outbuffer, &handler); } Should I fill an error report for this? Can someone see a workaround? I'm not using --i, but insert a sequence into a vector for example, where the stl uses the iterator category. best regards Torsten |