Boost logo

Boost :

Subject: [boost] Boost.Iterator filter_iterator issues
From: Christoph Heindl (christoph.heindl_at_[hidden])
Date: 2009-09-26 11:42:18


Hi,

I think I've found an issue with boost::filter_iterator when
decrementing a valid iterator without having any predicate evaluating
to true on its way back.

filter_iterator.hpp line# 93 states

void decrement()
{
  while(!this->m_predicate(*--(this->base_reference()))){};
}

which will ?clearly? pass beyond the initial start iterator if no
predicate evaluates to true. Is it a requirement for the iterator
being adapted by filter_iterator to catch decrements past the
containers begin range? The following test will iterate 'iter' past
containers begin iterator which will trigger a debug assertion on
MSVC.

template<class _Iterator>
void dec_iterator(_Iterator iter)
{
  BOOST_CHECK(*iter == 2);
  --iter; // iterates past begin
}

BOOST_AUTO_TEST_CASE(test_filter_iterator)
{
  using namespace boost::assign;
  typedef std::vector<int> container_type;

  container_type values = list_of(0)(1)(2);
  dec_iterator(boost::make_filter_iterator(std::bind2nd(std::greater<int>(),
1), values.begin(), values.end()));
}

Please help me clarifying this issue.

Best regards,
christoph


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk