|
Boost : |
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2004-07-21 07:16:54
Hello,
I tried to use boost::zip_iterator to sort 2 parallel arrays. Unfortunatly gcc
does not compile the appended example because it can not convert
boost::detail::iterator_category_with_traversal<std::input_iterator_tag,
boost::random_access_traversal_tag>
to either
std::bidirectional_iterator_tag
or
std::random_access_iterator_tag.
Thus it cannot dispatch the correct stl::__copy_backward() procedure.
Is sort() not yet supported?
mfg
Gunter
PS: please CC your replies to my eMail.
8<-----------part of error log---------------
/usr/include/c++/3.3/bits/stl_algobase.h: In static member function `static
_BidirectionalIter2 std::__copy_backward_dispatch<_BidirectionalIter1,
_BidirectionalIter2, _BoolType>::copy(_BidirectionalIter1,
_BidirectionalIter1, _BidirectionalIter2) [with _BidirectionalIter1 =
boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type> >, _BidirectionalIter2 =
boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type> >, _BoolType = __false_type]':
[...]
/usr/include/c++/3.3/bits/stl_algobase.h:392: error: no matching function for
call to `__copy_backward(
boost::zip_iterator<...>&,
boost::zip_iterator<...>&,
boost::detail::iterator_category_with_traversal<std::input_iterator_tag,
boost::random_access_traversal_tag>)'
/usr/include/c++/3.3/bits/stl_algobase.h:360: error: candidates are:
_BidirectionalIter2 std::__copy_backward(_BidirectionalIter1,
_BidirectionalIter1, _BidirectionalIter2, std::bidirectional_iterator_tag)
/usr/include/c++/3.3/bits/stl_algobase.h:371: error:
_BidirectionalIter std::__copy_backward(_RandomAccessIter,
_RandomAccessIter, _BidirectionalIter, std::random_access_iterator_tag)
8<-----------zip_iter.cpp------------
// sort 2 parallel arrays
#include <boost/iterator.hpp>
#include <boost/iterator/zip_iterator.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <vector>
#include <iostream>
int main(int argc, char *argv[])
{
typedef std::vector<int> VEC;
typedef boost::zip_iterator<
boost::tuple<VEC::iterator, VEC::iterator> > zip_iter;
VEC v1(10);
VEC v2(10);
zip_iter iter( boost::make_tuple(v1.begin(), v2.begin()) );
zip_iter iter_end( boost::make_tuple(v1.end(), v2.end()) );
std::sort(iter, iter_end);
return EXIT_SUCCESS;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk