problem with permuation_iterator (constness)

This simple test illustrates the problem: #include <boost/iterator/permutation_iterator.hpp> #include <vector> #include <boost/range.hpp> template<typename in_t> void F (in_t const& in) { typename boost::range_const_iterator<in_t>::type inp = boost::begin (in); } int main () { std::vector<int> x, y; F (boost::make_permutation_iterator (boost::begin (x), boost::begin (y))); } /usr/local/src/boost.hg/boost/range/const_iterator.hpp:37: error: no type named const_iterator in class boost::permutation_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >

On Mon, 6 Nov 2006, Neal Becker wrote:
This simple test illustrates the problem:
#include <boost/iterator/permutation_iterator.hpp> #include <vector> #include <boost/range.hpp>
template<typename in_t> void F (in_t const& in) { typename boost::range_const_iterator<in_t>::type inp = boost::begin (in); }
int main () { std::vector<int> x, y; F (boost::make_permutation_iterator (boost::begin (x), boost::begin (y))); }
/usr/local/src/boost.hg/boost/range/const_iterator.hpp:37: error: no type named const_iterator in class boost::permutation_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >
The problem has nothing to do with constness. make_permutation_iterator return's an iterator (a permutation_iterator), not a range. But you try to use it as a range. To get the range, to need to call make_permutation_iterator twice: once as you did, and another time with 'end'. -- François Duranleau LIGUM, Université de Montréal "The real source of wealth is correct ideas: workable ideas: that is, negative entropy -- Information." - Robert Anton Wilson, _Prometheus Rising_, 1983

Neal Becker <ndbecker2@gmail.com> writes:
This simple test illustrates the problem:
#include <boost/iterator/permutation_iterator.hpp> #include <vector> #include <boost/range.hpp>
template<typename in_t> void F (in_t const& in) { typename boost::range_const_iterator<in_t>::type inp = boost::begin (in); }
int main () { std::vector<int> x, y; F (boost::make_permutation_iterator (boost::begin (x), boost::begin (y))); }
/usr/local/src/boost.hg/boost/range/const_iterator.hpp:37: error: no type named const_iterator in class boost::permutation_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >
This has nothing to do with permutation iterator at all. An iterator is not expected to have a const_iterator member. It looks for all the world like user error: F expects a model of Range, and you're just passing a model of Iterator. -- Dave Abrahams Boost Consulting www.boost-consulting.com

David Abrahams wrote:
Neal Becker <ndbecker2@gmail.com> writes:
This simple test illustrates the problem:
#include <boost/iterator/permutation_iterator.hpp> #include <vector> #include <boost/range.hpp>
template<typename in_t> void F (in_t const& in) { typename boost::range_const_iterator<in_t>::type inp = boost::begin (in); }
int main () { std::vector<int> x, y; F (boost::make_permutation_iterator (boost::begin (x), boost::begin (y))); }
/usr/local/src/boost.hg/boost/range/const_iterator.hpp:37: error: no type named const_iterator in class boost::permutation_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> >
This has nothing to do with permutation iterator at all. An iterator is not expected to have a const_iterator member. It looks for all the world like user error: F expects a model of Range, and you're just passing a model of Iterator.
Yes, thanks, I meant to pass a range. I should stop posting early Monday morning.
participants (3)
-
David Abrahams
-
François Duranleau
-
Neal Becker