I'm still having problems with using the new iterator adaptors, when trying to create
input iterator with the help of 'iterator_facade'. The complete code
is attached. The problems are with 'deference' method.
1. iterator_facade insists on having const 'deference', while it seems that input
iterators frequently
alter internal state during dereferencing. What is the rationale for the current
behaviour.
2. Unless I explicitly specify reference type, iterator_facade will try to use
ValueType& as reference type,
which is wrong in my case, and, I'd think, for all input iterators. Again, what is the
rationale?
TIA,
Volodya
#include <boost/iterator.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <iostream>
#include <sstream>
class adapted_iterator :
public boost::iterator_facade< adapted_iterator, std::string,
std::input_iterator_tag>
{
typedef boost::iterator_facade< adapted_iterator, std::string,
std::input_iterator_tag> base;
public:
adapted_iterator() : is(0) {}
adapted_iterator(std::istream* is) : is(is) {}
private:
friend class boost::iterator_core_access;
base::reference
//std::string
dereference() const
{
std::string s;
getline(*is, s);
return s;
}
void increment()
{
}
bool equal(const adapted_iterator& another) const
{
bool at_eof1 = !is || is->eof();
bool at_eof2 = !another.is || another.is->eof();
return (at_eof1 == at_eof2);
}
private:
std::istream* is;
};
int main()
{
std::stringstream ss("1 \n234\n\n45");
for(adapted_iterator i(&ss), e; i != e; ++i)
{
std::cout << "'" << *i << "'\n";
}
return 0;
}
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost