是否有可能以任何方式(使用C++预处理器等)将shared_ptr替换为<T> T$,weak_ptr<T>替换为 T%,unique_ptr<T>替换为 T?
Is it possible in any way (using C++ preprocessor etc) to replace shared_ptr<T> with T$, weak_ptr<T> with T%, and unique_ptr<T> with T?
目前看来答案是否定的。
考虑到shared_ptrs
在视觉上变得更加嘈杂,这是不幸的。
对于c++ 11,现在一种可能的方法是使用别名(这比宏更简洁)。例如,对于共享指针,您可以这样做:
template<typename T>
using Shared = std::shared_ptr<T>;
然后,按如下方式使用:
Shared<int> myInt; // Is in fact a std::shared_ptr<int>
编辑:实例。
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- 如何用转义符替换字符串中的所有特殊字符
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- CLANG 编译器 说:变量"PTR"可能未初始化
- 在一个读写器队列中,我可以用volatile替换原子吗
- 用符号版本替换对函数的所有调用
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 替换基于地图的所有引用
- 按平均值替换数组中的元素
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- 初始化 std::vector 替换为单大括号而不是双大括号
- 删除/替换C++字符串中的多字符 (ÿû)
- 将 malloc 替换为数组
- 如何替换此示例代码片段中已弃用的handler_type_t或 boost::asio::handler_type?
- 如何在C++中用'\'替换''来处理转义序列?
- 替换密码:哪一个?
- 为共享 ptr 向量实现复制 c'tor?