Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-07-10 12:57:10


I'm afraid it's not the right approach. The value_type of a constant
iterator to T should just be T, not const T. You need to arrange for T
const* and T const& pointer and reference parameters, respectively.

Also, since your fix uses partial specialization it would break MSVC
compatibility :(.

I think a better approach would change how the default parameters to
indirect_Iterator_generator are computed. I think we could get around the
MSVC problems with value_type_of_value_type by having a special default tag
type which is detected using a small metaprogram, and computing the actual
value_type inside the generator body.

-Dave

----- Original Message -----
From: "Alexander Belopolsky" <belopols_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, July 10, 2001 12:05 PM
Subject: [boost] iterator_adaptor library bug

> 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);
>
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


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