Boost logo

Boost :

From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2005-08-17 08:30:02


----Original Message----
From: Jonathan Wakely [mailto:cow_at_[hidden]]
Sent: 17 August 2005 14:17
To: boost_at_[hidden]
Subject: Re: [boost] Propose adding Clone Smart Pointer (clone_ptr) to
theboost library

> Axter wrote:
>
>> It does not need a clone member if you apply strict pointer
>> ownership logic, which is what a clone pointer normally does.
>

> clone_ptr also needs the definitions of all derived classes to be
> visible, whereas something like ptr_container that uses a clone()
> member function only needs to see the definition of the base
> class and can do everything through the base class' interface.

I think it only needs the definition available for the constructor (which is
where a class derived from his "copier" class is instantiated).

[snip]
> This would not be possible with std::vector<clone_ptr<Base> >:
>
> // pc.h
> #include <boost/ptr_container/ptr_vector.hpp>
> struct Base {
> ~Base() {}
> virtual Base* clone() = 0;
> virtual void f() = 0;
> };
> void fill(boost::ptr_vector<Base>&);
>
> // pc.cc
> #include "pc.h"
> #include <boost/bind.hpp>
> #include <algorithm>
>
> int main()
> {
> boost::ptr_vector<Base> v;
> fill(v);
> std::for_each(v.begin(), v.end(), boost::bind(&Base::f, _1));
> return 0;
> }
>
> The fill() function can now be implemented in another file and
> populate the vector with any type derived from Base, without
> recompiling pc.cc

I think that is supported with clone_ptr. The file implementing fill would
need the full definition of the derived type(s) of course, but that is less
restrictive.

-- 
Martin Bonner
Martin.Bonner_at_[hidden]
Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ,
ENGLAND Tel: +44 (0)1223 441434

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk