e r | 20 Aug 05:26

dereference problems with iterator_facade

hello,

i have a build error when i try to use an iterator derived from
iterator_facade<Iter> with Iter an iterator over a const Range. It's the
const that causes the error. See the *.hpp below and an example.

any other suggestion to improve the *hpp also appreciated.

thanks!

///////////////////////////////////////////////////////////////////////////////
// boost::skip_one_step_iterator.hpp
//
//  Copyright 2008 Erwann Rogard. Distributed under the Boost
//  Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_ITERATOR_SKIP_ONE_STEP_ITERATOR_HPP_ER200808
#define BOOST_ITERATOR_SKIP_ONE_STEP_ITERATOR_HPP_ER200808
#include <iterator>
#include <stdexcept>
#include <boost/iterator/iterator_facade.hpp>

#include <boost/iterator/iterator_traits.hpp>
#include <boost/range.hpp>
#include <boost/assert.hpp>
#include <boost/type_traits.hpp>
namespace boost{

namespace{
(Continue reading)

David Abrahams | 22 Aug 03:14
Favicon
Gravatar

Re: dereference problems with iterator_facade


on Tue Aug 19 2008, e r <erwann.rogard-AT-gmail.com> wrote:

> hello,
>
> i have a build error when i try to use an iterator derived from
> iterator_facade<Iter> with Iter an iterator over a const Range. It's the
> const that causes the error. See the *.hpp below and an example.

The problem is that the reference type of Iter is value_type& when it
should be value_type const&.  The value_type of a constant iterator is
still non-const, and you're getting the Value parameter by asking the
value_type of BaseIter.

> any other suggestion to improve the *hpp also appreciated.

Use iterator_adaptor; all your problems will go away and your code will
get smaller.

--

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
e r | 23 Aug 05:37

Re: dereference problems with iterator_facade

David Abrahams wrote:
> on Tue Aug 19 2008, e r <erwann.rogard-AT-gmail.com> wrote:
> 
>> hello,
>>
>> i have a build error when i try to use an iterator derived from
>> iterator_facade<Iter> with Iter an iterator over a const Range. It's the
>> const that causes the error. See the *.hpp below and an example.
> 
> The problem is that the reference type of Iter is value_type& when it
> should be value_type const&.  The value_type of a constant iterator is
> still non-const, and you're getting the Value parameter by asking the
> value_type of BaseIter.
> 
>> any other suggestion to improve the *hpp also appreciated.
> 
> Use iterator_adaptor; all your problems will go away and your code will
> get smaller.
> 

Indeed, it worked. Thanks^2!

Gmane