runtime polymorphism & passing and returning elements

The problem is not boost specific, but probably there is a boost specific solution to it... The usual way of passing and returning elements to/from a function/method is to use a templated function/method, e.g.: template< typename ITER_IN, typename ITER_OUT
void doSomething( ITER_IN inBegin, ITER_IN inEnd, ITER_OUT outIter, int param1, int param2, ... ) { while(inBegin != inEnd) { ... *outIter++ = ...; } } But what to do in case of (pure) virtual methods which can't be templated? One (neither pretty nor efficient) solution would be something like this: struct A { template<typename ITER_IN, typename ITER_OUT> void doSomething( ITER_IN inBegin, ITER_IN inEnd, ITER_OUT outIter, int param1, int param2, ... ) { const std::vector<int> out( doSomething_impl( std::vector<int>(inBegin, inEnd), param1, param2 ) ); std::copy(out.begin(), out.end(), outIter); } virtual std::vector<int> doSomething_impl( std::vector<int>& const in, int param1, int param2, ... ) = 0; }; // struct A Is there a better (boost-ish) solution?
participants (1)
-
Kosta