瀏覽代碼

Clarify auto usage.

Pāvels Nadtočajevs 8 月之前
父節點
當前提交
593264ca8e
共有 1 個文件被更改,包括 20 次插入2 次删除
  1. 20 2
      contributing/development/cpp_usage_guidelines.rst

+ 20 - 2
contributing/development/cpp_usage_guidelines.rst

@@ -84,8 +84,26 @@ Keep in mind hover documentation often isn't readily available for pull request
 reviewers. Most of the time, reviewers will use GitHub's online viewer to review
 reviewers. Most of the time, reviewers will use GitHub's online viewer to review
 pull requests.
 pull requests.
 
 
-We chose to forbid ``auto`` instead of allowing it on a case-by-case basis to
-avoid having to decide on difficult edge cases. Thank you for your understanding.
+The ``auto`` keyword can be used in some special cases, like C++ lambda or Objective-C block
+definitions and C++ templates. Please ask before using templates with ``auto`` in a pull request.
+
+.. code-block:: cpp
+
+    // Full type definitions.
+    void (*mult64to128)(uint64_t, uint64_t, uint64_t &, uint64_t &) = [](uint64_t u, uint64_t v, uint64_t &h, uint64_t &l) { ... }
+    void (^JOYSTICK_LEFT)(GCControllerDirectionPad *__strong, float, float) = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) { ... }
+
+    // Less clutter with auto.
+    auto mult64to128 = [](uint64_t u, uint64_t v, uint64_t &h, uint64_t &l) { ... }
+    auto JOYSTICK_LEFT = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) { ... }
+
+    // Compare function for different types.
+    template <typename T1, typename T2>
+    constexpr auto MIN(const T1 m_a, const T2 m_b) {
+        return m_a < m_b ? m_a : m_b;
+    }
+
+We chose to forbid ``auto`` in all other cases. Thank you for your understanding.
 
 
 Lambdas
 Lambdas
 ~~~~~~~
 ~~~~~~~