Boost logo

Boost :

Subject: [boost] [Gauge for interest] Surrogate template
From: Alan sinde (alantsd_at_[hidden])
Date: 2011-02-27 01:56:16

Hi all,

Recently I've an surrogate/proxy pattern implemented for storing related type as value.
It is based on chapter 5 of Rumination on C++ by Andrew Koenig and Barbara moo.
Original version required stored object to define their own virtual copy constructor.

I have updated it to template version.

Besides, it also relief user from defining virtual copy constructor by moving virtual copy inside surrogate. Thanks to template constructor making this possible.
1) Each copy construction of surrogate incurs 2 virtual calls instead of 1 in the original.
2) Object compositing surrogate that has interface taking derived class must change to template member function in order to use template constructor of surrogate.

Does anybody interested to include it as boost::surrogate?

Example Usage:

class boy
    virtual void tell() = 0;

class happy_boy : public boy
class study_boy : public boy

void say_hi(boy& the_boy)

int main()
    std::cout << "Hello boost::surrogate!" << std::endl;
    happy_boy Terry;
    study_boy Thomas;

    std::vector<boost::surrogate<boy> > boy_list;

    std::for_each(boy_list.begin(), boy_list.end(), say_hi);


Alan Tong

Boost list run by bdawes at, gregod at, cpdaniel at, john at