Boost logo

Boost Users :

Subject: [Boost-users] [ptr_container] Transferring the Last Element from a ptr_vector
From: Charles Brockman (cmbrockman_at_[hidden])
Date: 2009-09-05 19:17:15


I have two functions which swap elements between ptr_vectors. The first
compiles and apparently works correctly.

typedef boost::ptr_vector<Gene> GeneVectType;
GeneVectType geneVect;

void Gene::swapGene(Gene* other) {
   geneVect.transfer(geneVect.end(), other->geneVect.begin(),
other->geneVect);
   other->geneVect.transfer(other->geneVect.end(), geneVect.begin(),
geneVect);
}

Occasionally I must reverse the swap with this unswap function.

void Gene::unswapGene(Gene* other) {
   // The line below is line 560 referred to in the error message.
   geneVect.transfer(geneVect.begin(), other->geneVect.rbegin(),
other->geneVect);
   other->geneVect.transfer(other->geneVect.begin(), geneVect.rbegin(),
geneVect);
}

This function should take the last element from each container and transfer
it to the beginning of the other container. The unswapGene function will not
compile. Here's the compiler message.

C:\Boost SVN\trunk\boost/range/const_iterator.hpp(37) : error C2039:
'const_iterator' : is not a member of 'boost::reverse_iterator<Iterator>'
   with [Iterator=boost::void_ptr_iterator<std::_Vector_iterator<void
*,std::allocator<void *>>,genprg::Gene>]
   C:\Boost SVN\trunk\boost/mpl/eval_if.hpp(63) : see reference to class
template instantiation 'boost::range_const_iterator<C>' being compiled
   with
[C=boost::reverse_iterator<boost::void_ptr_iterator<std::_Vector_iterator<void
*,std::allocator<void *>>,genprg::Gene>>]
   C:\Boost SVN\trunk\boost/range/iterator.hpp(63) : see reference to class
template instantiation 'boost::mpl::eval_if_c<C,F1,F2>' being compiled
   with [C=true,
F1=boost::range_const_iterator<boost::reverse_iterator<boost::void_ptr_iterator<std::_Vector_iterator<void
*,std::allocator<void *>>,genprg::Gene>>>,
   F2=boost::range_mutable_iterator<const
boost::reverse_iterator<boost::void_ptr_iterator<std::_Vector_iterator<void
*,std::allocator<void *>>,genprg::Gene>>>]
   C:\Boost SVN\trunk\boost/ptr_container/ptr_sequence_adapter.hpp(458) :
see reference to class template instantiation 'boost::range_iterator<C>'
being compiled
   with [C=const
boost::reverse_iterator<boost::void_ptr_iterator<std::_Vector_iterator<void
*,std::allocator<void *>>,genprg::Gene>>]
   ..\..\..\..\GSSTA\gene.cpp(560) : see reference to function template
instantiation 'void
boost::ptr_sequence_adapter<T,VoidPtrSeq,CloneAllocator>::transfer<genprg::Gene::GeneVectType,boost::reverse_iterator<Iterator>>(boost::void_ptr_iterator<VoidIter,T>,const
Range &,PtrSeqAdapter &)' being compiled
   with [T=genprg::Gene, VoidPtrSeq=std::vector<void *,std::allocator<void
*>>, CloneAllocator=boost::heap_clone_allocator,
Iterator=boost::void_ptr_iterator<std::_Vector_iterator<void
*,std::allocator<void *>>,genprg::Gene>, VoidIter=std::_Vector_iterator<void
*,std::allocator<void *>>,
Range=boost::reverse_iterator<boost::void_ptr_iterator<std::_Vector_iterator<void
*,std::allocator<void *>>,genprg::Gene>>,
PtrSeqAdapter=genprg::Gene::GeneVectType]

Can anyone see what I'm doing wrong?

-- 
Charles

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