|
Boost : |
Subject: Re: [boost] [Booster] Or boost is useless for library developers
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2010-05-15 11:12:01
On Sat, May 15, 2010 at 10:53 AM, Artyom <artyomtnk_at_[hidden]> wrote:
>
>> OK, can I so something like the following?
>>
>> boost::shared_ptr<int> a(new int(0));
>> booster::shared_ptr<int> b = a;
>>
>> (replace shared_ptr with all the other boost-look-alike
>> classes)
>
> No you can't assign boost::shared_ptr to booster::shared_ptr as you
> can't assign std::tr1::shared_ptr to boost::shared_ptr
>
> But you can freely replace one with other as long as they consistent.
>
But that could then ripple through an entire codebase - 100Ks, most of
it not mine to change.
What might, instead, be possible is to make some bridge classes.
library.h:
inline boost::shared_ptr<int> some_api()
{
boost::abi::shared_ptr<int> asp = some_api_abi(); // call the real function
return boost::shared_ptr<int>(asp, boost::abi::deleter<int>);
}
***Or something like that***
Importantly, note that since this is in your h file, which I include,
I will get *my* version of shared_ptr returned from some_api().
It will be a wrapper around your shared_ptr, thus with extra overhead,
but at least it will work.
Basically your functions return a abi version of shared_ptr, which may
need to be pure interface, if you really want to be sure about abi:
template <typename T>
struct boost::abi::shared_ptr
{
virtual void delete() = 0;
virtual void add_ref() = 0;
//...
};
Or maybe it is something else, but it is a simple bridge that you can
hopefully keep compatible for a number of years, and can be converted
to *my* shared_ptr.
Lather, rinse, repeat for other ABIs. Yes, this may be cumbersome,
but no more than what you are already doing.
Tony
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk