I am working on cross-platform code that needs shared pointers. For reasons beyond my control we cannot use C++11 just yet. So, I have suggested using boost::shared_ptr. When we do adopt C++11 (maybe a year down the line), we should be able to replace boost smart pointers with std smart pointers. My question is about the best way to use boost so that it is easier to switch later. Template aliasing is not available so the following is out:
namespace my {
template <typename T>
using shared_ptr = boost::shared_ptr<T>;
}
The other technique of wrapping the shared_ptr inside another struct results in ugly and unreadable APIs as I will then have to use it thus my::shared_ptr<int>::type
:
namespace my {
template<typename T>
struct shared_ptr
{
typedef boost::shared_ptr<T> type;
};
}
I am looking for alternatives to this. Any suggestions will be appreciated.
EDIT: Another option I considered was this:
namespace my {
using boost::shared_ptr;
}
And then use my::shared_ptr<int>
. Later I would change boost
to std
in namespace my
. However, I am not able to decide on the pro-s and con-s of each of the approaches to reach a decision.
boost::shared_ptr
->std::shared_ptr
will go wrong anywhere. – Cobaltiteboost
withstd
later :( – Twotoneboost::_1 become
std::placeholders::_1`? – Twotoneboost
on both platforms for now and then move tostd
on both platforms simultaneously later. Unless of course, I have got my facts wrong and I can safely usestd
on Windows andtr1
on Mac without any problem. – Twotoneboost::shared_ptr
will be implemented in terms ofstd::shared_ptr
or thatboost::shared_ptr
will be exactly the same type asstd::shared_ptr
? – Chiropodist