Boost logo

Boost Users :

Subject: Re: [Boost-users] zip_iterator and sTL algorithms like random_shuffle
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-03-31 09:02:33


This is not standard conform to introduce overloaded functions into std
namespace. This posting might answer your question:
http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/b396fedad7dcdc81/f90aa60e9c22bde6

It is pretty long, but worth reading it all. And that is what Steven means
in his previous post, that there is no C++03 standard way to fix it.

Greetings,
Ovanes

On Tue, Mar 31, 2009 at 12:59 PM, Andreas Fabri <
andreas.fabri_at_[hidden]> wrote:

> Hi Steven,
>
> Adding a specialization for iter_swap
>
> typedef boost::tuple<
> std::vector<int>::iterator,
> std::vector<int>::iterator
> > iterator_tuple;
>
> typedef boost::zip_iterator<
> iterator_tuple
> > ziterator;
>
>
> namespace std {
>
> void
> iter_swap(ziterator a, ziterator b)
> {
> std::swap(a->get<0>(), b->get<0>());
> std::swap(a->get<1>(), b->get<1>());
> }
>
> }
>
>
> solved the problem for std::random_shuffle.
>
> For std::sort I provide a comparison functor for the tuple.
> but the compiler (VC8) complains about no match for _Rotate
>
> Any hint would be appreciated.
>
> andreas
>
>
> C:\Program Files (x86)\Microsoft Visual Studio 8\VC\INCLUDE\algorithm(1719)
> : error C2665: 'std::_Rotate' : none of the 3 overloads could convert all
> the argument types
> C:\Program Files (x86)\Microsoft Visual Studio
> 8\VC\INCLUDE\algorithm(1649): could be 'void
> std::_Rotate<_FwdIt>(_FwdIt,_FwdIt,_FwdIt,std::forward_iterator_tag)'
> with
> [
> _FwdIt=boost::zip_iterator<iterator_tuple>
> ]
> C:\Program Files (x86)\Microsoft Visual Studio
> 8\VC\INCLUDE\algorithm(1666): or 'void
> std::_Rotate<_FwdIt>(_BidIt,_BidIt,_BidIt,std::bidirectional_iterator_tag)'
> with
> [
> _FwdIt=boost::zip_iterator<iterator_tuple>,
> _BidIt=boost::zip_iterator<iterator_tuple>
> ]
> C:\Program Files (x86)\Microsoft Visual Studio
> 8\VC\INCLUDE\algorithm(1709): or 'void
> std::_Rotate<_FwdIt>(_RanIt,_RanIt,_RanIt,std::random_access_iterator_tag)'
> with
> [
> _FwdIt=boost::zip_iterator<iterator_tuple>,
> _RanIt=boost::zip_iterator<iterator_tuple>
> ]
> while trying to match the argument list
> '(boost::zip_iterator<IteratorTuple>, boost::zip_iterator<IteratorTuple>,
> boost::zip_iterator<IteratorTuple>,
> boost::detail::iterator_category_with_traversal<Category,Traversal>)'
> with
> [
> IteratorTuple=iterator_tuple
> ]
> and
> [
> IteratorTuple=iterator_tuple
> ]
> and
> [
> IteratorTuple=iterator_tuple
> ]
> and
> [
> Category=std::input_iterator_tag,
> Traversal=boost::random_access_traversal_tag
> ]
> C:\Program Files (x86)\Microsoft Visual Studio
> 8\VC\INCLUDE\algorithm(3125) : see reference to function template
> instantiation 'void std::rotate<_BidIt>(_FwdIt,_FwdIt,_FwdIt)' being
> compiled
> with
> [
> _BidIt=boost::zip_iterator<iterator_tuple>,
> _FwdIt=boost::zip_iterator<iterator_tuple>
> ]
> C:\Program Files (x86)\Microsoft Visual Studio
> 8\VC\INCLUDE\algorithm(3252) : see reference to function template
> instantiation 'void std::_Insertion_sort<_RanIt,_Pr>(_BidIt,_BidIt,_Pr)'
> being compiled
> with
> [
> _RanIt=boost::zip_iterator<iterator_tuple>,
> _Pr=Compare,
> _BidIt=boost::zip_iterator<iterator_tuple>
> ]
> C:\Program Files (x86)\Microsoft Visual Studio
> 8\VC\INCLUDE\algorithm(3261) : see reference to function template
> instantiation 'void std::_Sort<_RanIt,__int64,_Pr>(_RanIt,_RanIt,_Diff,_Pr)'
> being compiled
> with
> [
> _RanIt=boost::zip_iterator<iterator_tuple>,
> _Pr=Compare,
> _Diff=__int64
> ]
>
>
> Steven Watanabe wrote:
>
>> AMDG
>>
>> Andreas Fabri wrote:
>>
>>> I have two vectors and want to random_shuffle them the same way
>>> using the zip_iterator. I thought the code below would do it,
>>> but when I execute it I see that both sequences get screwded up.
>>>
>>> What do I wrong?
>>>
>>
>> The problem is that std::iter_swap doesn't work
>> for zip_iterator and there is no standard compliant
>> way to fix it.
>>
>> In Christ,
>> Steven Watanabe
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net