Boost logo

Boost :

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


> How is that different from clone_ptr and other similar works?

surrogate does not attempts to emulate a concrete type via pointer interface.
Instead, It act as drop in replacement for value type
This is the main idea behind surrogate pattern.
Typically, this is achieve through surrogate<T>::operator T&().

This also implies that most STL function objects can work with std::vector<boost::surrogate<T>>.

Besides, It encapsulate object allocation inside itself.
In my humble opinion, this feel like less error prone.  
 
boost::clone_ptr, on the other hand, emulate a concrete type via pointer interface. 
This implies that most STL function objects is incompatible to std::vector<boost::clone_ptr<T>>.
This also apply to ordinary pointer type, boost::shared_ptr and other similar.
 
Surrogate also differ from value_ptr by Edd Dawson. Surrogate does not need object to have virtual copy function.
I have reviewed Boost.ClonePtr by Rafal Moniuszko, it seems to me pointed objects get sliced during copy construction. Could you please confirm this?

In many ways, surrogate is similar to boost::clone_ptr.
 similar to std::stack adapt std::vector.
It is possible to adapt boost::clone_ptr to surrogate or vice-versa

However, their both serve different purpose as std::stack is to std::vector.
                                                


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