【发布时间】:2012-11-02 14:12:09
【问题描述】:
我正在将我的项目迁移到 C++11,并尝试尽可能多地使用标准库。
在完成迁移之前,我需要一种快速的方法来在 shared_ptr 的 boost 和 STL 实现之间切换(进行基准测试、单元测试等)。
所以我为shared_ptr 定义了一个别名,如下所示:
#ifdef _USE_BOOST_
template <class C>
using shared_ptr = boost::shared_ptr<C>
#else
template <class C>
using shared_ptr = std::shared_ptr<C>
#endif
现在我需要为make_shared 做同样的事情...但是怎么做呢?宏?一个包装?我真的不喜欢他们中的任何一个。有哪些替代方案?
【问题讨论】:
-
你别无选择,只能写一个快速包装器。