定义vs名称空间

Max*_*rai 1 c++ macros templates typedef

我有一个代码:

namespace My
{
    #define sptr std::shared_ptr;
}
Run Code Online (Sandbox Code Playgroud)

它被用在很多地方.现在我已将此代码作为库包含到qt项目中,并且无法加载,因为它sptr在某处用作变量名称.

我可以修改Qt标头并重命名变量,但这在可移植性方面并不好.解决这个问题的最佳方法是什么?typedef不能与模板一起使用.我知道模板结构的黑客,但我仍然需要修改我的代码.

eq-*_*eq- 8

namespace ns {
  template<typename T>
  using sptr = std::shared_ptr<T>;
}
Run Code Online (Sandbox Code Playgroud)

另请参阅@Kerrek SB对有关此特定用例的问题的评论.