Boost logo

Boost :

From: Rainer Deyke (root_at_[hidden])
Date: 2001-11-16 14:37:48


----- Original Message -----
From: "Jeff King" <peff-boost_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, November 16, 2001 12:18 PM
Subject: RE: [boost] polymorphic containers

> Because I didn't require that the type be Clonable; I only required that
> it be CopyConstructible. Thus, construction was something like this:
>
> template <class Base>
> class poly_ptr {
> public:
> typedef Base* (*clone_function)(const Base& b);
>
> template <class Derived>
> struct copier {
> static Base* clone(const Base& b) {
> return new Derived(dynamic_cast<Derived&>(b));
> }
> };
>
> template <class Derived>
> static poly_ptr<Base> create(Derived* d) {
> return poly_ptr<Base>(d, copier<Derived>::clone);
> }
>
> private:
> poly_ptr(Base* b, clone_function c) : ptr(b), cloner(c) { }

    public:
      template<class Derived> poly_ptr(Derived *p)
        : ptr(p), cloner(copier<Derived>::clone) {}

> };

--
Rainer Deyke (root_at_[hidden])
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

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