Boost logo

Boost Users :

From: Michael Rickert (pandamojo_at_[hidden])
Date: 2005-11-21 18:29:29


On 11/21/05, Keith Weintraub <Keith_at_[hidden]> wrote:
>
>
>
> Folks,
>
> I have come up with the following solution in template form. I would be ecstatic to receive any feedback on either my solution or original question. I am not an expert in these things and I can use all the help any generous soul could provide.
>
>
>
> Here is my solution:

*snip*

It would seem you're overengineering things. It'd be simpler just to
use std::vector's iterator constructors:

std::vector< boost::shared_ptr< derived > > data;
...
std::vector< boost::shared_ptr< base > > downcast_data( data.begin() ,
data.end() );

If you wanted to go with your original version, I'd suggest returning
a managed pointer of some sort (std::auto_ptr or boost::shared_ptr) to
decrease the likelyhood of a leak - or having the user pass a
nonconstant reference to a vector to fill.

Sorry if this has allready been covered by the time this is recieved,
my posts seem to still be awaiting moderator approval.

-Mike


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