I have created a new shared_ptr class called shared_ptr_embedded. This is based on the code for intrusive_ptr but differs in one important aspect. The struct/class pointed to is required to be derived from shared_ptr_count. The latter class contains an 'int count_' and methods for adding and removing references. This allows you to have the count embedded in your primary data, rather than having a separate allocation for count as shared_ptr does.
Here is an example:
#include <boost/shared_ptr_embedded.hpp>
class SharedName
{
struct Data : public boost::shared_ptr_count
{
std::string name_;
};
boost::shared_ptr_embedded<Data> data_;
public:
SharedName(std::string n) : data_(new Data) { data_->name_ = n; }
const std::string& GetName() { return data_->name_; }
SharedName& operator=(std::string n) { data_->name_ = n; return *this; }
};
I think this would be a valuable addition to the boost suite. How would I go about submitting this?
Scott Maxwell
PocketPurchase, Inc.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost