这样做会保护代码免受过多std ::的攻击吗?
// These underscore_cased type aliases make my code shorter and easier to read for me.
// For Example:
template<class T> using v=std::vector<T>;
template<class T, class U> using u_m=std::unordered_map<T,U>;
template<class T> using p_q=std::priority_queue<T>;
template<class T,class U> using u_mm=unordered_multimap<T,U>;
Run Code Online (Sandbox Code Playgroud)
还是这种冒险行为?
我没有看到这会如何污染我的命名空间,就像使用命名空间std那样。
这样做:
使您的代码难以阅读。
污染了命名空间(也许是全球性的)与vec和u_m。
C ++相当简洁。我的建议是习惯std::。
在using一个typedef范围内,a 或a 没有错class。这甚至可能是有用的。使您可以更改定义的组件,而不必更改相关代码。
| 归档时间: |
|
| 查看次数: |
141 次 |
| 最近记录: |