|
Boost : |
From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-10-04 14:01:15
Hi boosters,
The following code does not compile with boost 1.25.0:
#include <boost/iterator_adaptors.hpp>
#include <vector>
using namespace boost;
using namespace std;
int main() {
int ints[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
typedef vector<int const *> vect_t;
vect_t v;
for (int i = 9; i >=0; i--) {
v.push_back(ints + i);
}
typedef indirect_iterator_generator<vect_t::iterator>::type
indirector;
for (indirector it = indirector(v.begin()),
end = indirector(v.end()); it != end; ++it) {
const int &ref = *it;
cout << ref << '\n';
}
}
If I change the typedef to typedef vector<int *> vect_t; it works as
expected. The same problem holds when const_iterators are used instead
of const int **'s.
The problem arises because the reference type and pointer type of an
indirected <const int **> are int & and int *, not const int & and const int *.
The following patch fixes the problem ( I think it should be used for
indirect_iterator_pair_generator as well, so both the iterator and
const_iterator in that case will be for a const x.). I took the liberty of
renaming the detail::value_of_value_type template to
detail::traits_of_value_type and using that:
*** /home/georgeh/boost/boost/iterator_adaptors.hpp Fri Sep 28 09:03:33 2001
--- ./iterator_adaptors.hpp Thu Oct 4 14:51:17 2001
***************
*** 891,899 ****
namespace detail {
# if !defined(BOOST_MSVC) // stragely instantiated even when unused! Maybe try a recursive template someday ;-)
template <class T>
! struct value_type_of_value_type {
typedef typename boost::detail::iterator_traits<T>::value_type outer_value;
! typedef typename boost::detail::iterator_traits<outer_value>::value_type type;
};
# endif
}
--- 891,901 ----
namespace detail {
# if !defined(BOOST_MSVC) // stragely instantiated even when unused! Maybe try a recursive template someday ;-)
template <class T>
! struct traits_of_value_type {
typedef typename boost::detail::iterator_traits<T>::value_type outer_value;
! typedef typename boost::detail::iterator_traits<outer_value>::value_type value_type;
! typedef typename boost::detail::iterator_traits<outer_value>::reference reference;
! typedef typename boost::detail::iterator_traits<outer_value>::pointer pointer;
};
# endif
}
***************
*** 901,911 ****
template <class OuterIterator, // Mutable or Immutable, does not matter
class Value
#if !defined(BOOST_MSVC)
! = BOOST_ARG_DEPENDENT_TYPENAME detail::value_type_of_value_type<OuterIterator>::type
#endif
! , class Reference = Value&
, class Category = BOOST_ARG_DEPENDENT_TYPENAME boost::detail::iterator_traits<OuterIterator>::iterator_category
! , class Pointer = Value*
>
struct indirect_iterator_generator
{
--- 903,923 ----
template <class OuterIterator, // Mutable or Immutable, does not matter
class Value
#if !defined(BOOST_MSVC)
! = BOOST_ARG_DEPENDENT_TYPENAME detail::traits_of_value_type<OuterIterator>::value_type
#endif
! , class Reference
! #if !defined(BOOST_MSVC)
! = BOOST_ARG_DEPENDENT_TYPENAME detail::traits_of_value_type<OuterIterator>::reference
! #else
! = Value &
! #endif
, class Category = BOOST_ARG_DEPENDENT_TYPENAME boost::detail::iterator_traits<OuterIterator>::iterator_category
! , class Pointer
! #if !defined(BOOST_MSVC)
! = BOOST_ARG_DEPENDENT_TYPENAME detail::traits_of_value_type<OuterIterator>::pointer
! #else
! = Value*
! #endif
>
struct indirect_iterator_generator
{
***************
*** 916,927 ****
template <class OuterIterator, // Mutable or Immutable, does not matter
class Value
#if !defined(BOOST_MSVC)
! = BOOST_ARG_DEPENDENT_TYPENAME detail::value_type_of_value_type<OuterIterator>::type
#endif
! , class Reference = Value&
, class ConstReference = const Value&
, class Category = BOOST_ARG_DEPENDENT_TYPENAME boost::detail::iterator_traits<OuterIterator>::iterator_category
! , class Pointer = Value*
, class ConstPointer = const Value*
>
struct indirect_iterator_pair_generator
--- 928,949 ----
template <class OuterIterator, // Mutable or Immutable, does not matter
class Value
#if !defined(BOOST_MSVC)
! = BOOST_ARG_DEPENDENT_TYPENAME detail::traits_of_value_type<OuterIterator>::value_type
#endif
! , class Reference
! #if !defined(BOOST_MSVC)
! = BOOST_ARG_DEPENDENT_TYPENAME detail::traits_of_value_type<OuterIterator>::reference
! #else
! = Value &
! #endif
, class ConstReference = const Value&
, class Category = BOOST_ARG_DEPENDENT_TYPENAME boost::detail::iterator_traits<OuterIterator>::iterator_category
! , class Pointer
! #if !defined(BOOST_MSVC)
! = BOOST_ARG_DEPENDENT_TYPENAME detail::traits_of_value_type<OuterIterator>::pointer
! #else
! = Value*
! #endif
, class ConstPointer = const Value*
>
struct indirect_iterator_pair_generator
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk