如果您的团队同意一组别名,则将类型别名用于STL容器是否是不好的做法?

use*_*940 2 c++

这样做会保护代码免受过多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那样。

Bat*_*eba 5

这样做:

  1. 使您的代码难以阅读。

  2. 污染了命名空间(也许是全球性的)与vecu_m

C ++相当简洁。我的建议是习惯std::

using一个typedef范围内,a 或a 没有错class。这甚至可能是有用的。使您可以更改定义的组件,而不必更改相关代码。

  • 假设我和我的团队发现std :: vector &lt;std :: vector &lt;int &gt;&gt;比vec &lt;vec &lt;int &gt;&gt;更难读。您能否举一个示例说明名称空间污染会是一个问题? (2认同)