瀏覽代碼

Add style guideline for `using std::foo;` (#263)

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Jon Meow 5 年之前
父節點
當前提交
50fa120c87
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      docs/project/cpp_style_guide.md

+ 8 - 0
docs/project/cpp_style_guide.md

@@ -110,6 +110,14 @@ these.
     imprecise, are at least less confusing over the course of such refactorings.
 
 -   Use the `using`-based type alias syntax instead of `typedef`.
+-   Don't use `using` to support unqualified lookup on `std` types; for example,
+    `using std::vector;`. This also applies to other short namespaces,
+    particularly `llvm` and `clang`.
+    -   Writing `std::` gives clearer diagnostics and avoids any possible
+        ambiguity, particularly for ADL.
+    -   An exception is made for functions like `std::swap` that are
+        intentionally called using ADL. This pattern should be written as
+        `{ using std::swap; swap(thing1, thing2); }`.
 -   Follow the rules for initialization outlined in
     [Abseil's tip #88](https://abseil.io/tips/88#best-practices-for-initialization).
     To summarize, omitting some details from the article: