Boost logo

Boost :

From: Alexander Belopolsky (belopols_at_[hidden])
Date: 2001-07-10 11:05:11


The following code does not compile due to a bug
in make_indirect_iterator:

#include <boost/iterator_adaptors.hpp>
#include <iostream>
#include <vector>

using namespace std;
using namespace boost;
int main()
{
  int arr[] = {1,2,3,4,5,6};
  vector<const int*> vec(6); // Note const !
  
  vec[0] = arr;
  vec[1] = arr+1;
  vec[2] = arr+2;
  vec[3] = arr+3;
  vec[4] = arr+4;
  vec[5] = arr+5;
  
  copy(make_indirect_iterator(vec.begin()),
       make_indirect_iterator(vec.end()),
       ostream_iterator<int>(cout, ","));
  
  cout << endl;
  
  return 0;
}

I suggest the following patch :

cvs diff iterator_adaptors.hpp
Index: iterator_adaptors.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/iterator_adaptors.hpp,v
retrieving revision 1.42
diff -r1.42 iterator_adaptors.hpp
928a929,938
> namespace detail
> {
> template <typename T>
> struct pointee;
> template <typename T>
> struct pointee<T*> {
> typedef T type;
> };
> }
>
931c941,944
< inline typename indirect_iterator_generator<OuterIterator>::type

---
> inline typename indirect_iterator_generator
> <OuterIterator
> , typename detail::pointee<typename
std::iterator_traits<OuterIterator>::value_type>::type 
> >::type
934,936c947,951
<     typedef typename indirect_iterator_generator
<         <OuterIterator>::type result_t;
<     return result_t(base);
---
>   typedef typename indirect_iterator_generator
>     <OuterIterator
>     , typename detail::pointee<typename
std::iterator_traits<OuterIterator>::value_type>::type
>     >::type result_t;
>   return result_t(base);

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