Opened 8 years ago

Last modified 8 years ago

#10769 new Bugs

iterator_adaptor does not properly inherit "pointer" typedef from the base iterator

Reported by: Matei David <matei@…> Owned by: jeffrey.hellrung
Milestone: To Be Determined Component: iterator
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc:

Description

I'm trying to define a Derived_Iterator class using a Base_Iterator class and the glue class iterator_adaptor< Derived_Class, Base_Class, ...> (as base of Derived_Iterator). In my use case, neither pointers nor references are plain:

Base_Iterator::pointer != Base_Iterator::value_type*
Base_Iterator::reference != Base_Iterator::value_type&

I found 2 possibly related problems, which I think are bugs:

  1. The typedef iterator_adaptor<>::pointer is incorrect. Specifically, it produces a plain pointer, when I expect it to produce Base_Iterator::pointer.
  1. There is something wrong with iterator_adaptor<>::operator->(). I would expect Derived_Iterator to behave exactly like Base_Iterator. So, if I don't explicitly define Derived_Iterator::operator->(), I would expect the version inherited from iterator_adaptor<> to do something similar to:
    Base_Iterator operator->() const { return this->base(); }
    

But this doesn't happen. If I put in this definition explicitly in Derived_Iterator, then the code works.

Attachments (1)

iterator-example.cpp (5.8 KB ) - added by Matei David <matei@…> 8 years ago.
example file

Download all attachments as: .zip

Change History (3)

by Matei David <matei@…>, 8 years ago

Attachment: iterator-example.cpp added

example file

comment:1 by Matei David <matei@…>, 8 years ago

In the example, I'm using the bounded_pointer and bounded_reference classes that are part of the boost::intrusive test suite, available in the github repo.

I compile with gcc-4.9.1 or clang-3.5:

[g++|clang++] -std=c++11 -Wall -Wextra -pedantic -I${BOOST_INCLUDE_1_57} iterator-example.cpp -o iterator-example

comment:2 by Matei David <matei@…>, 8 years ago

I also posted a message about this on the boost-users mailing list, but Trac doesn't allow me to put the link here. (It thinks it's spam, then asks me solve a captcha without displaying one...)

Note: See TracTickets for help on using tickets.