Skip to content

Commit 593264c

Browse files
committed
Clarify auto usage.
1 parent 4f4b681 commit 593264c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

contributing/development/cpp_usage_guidelines.rst

+20-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,26 @@ Keep in mind hover documentation often isn't readily available for pull request
8484
reviewers. Most of the time, reviewers will use GitHub's online viewer to review
8585
pull requests.
8686

87-
We chose to forbid ``auto`` instead of allowing it on a case-by-case basis to
88-
avoid having to decide on difficult edge cases. Thank you for your understanding.
87+
The ``auto`` keyword can be used in some special cases, like C++ lambda or Objective-C block
88+
definitions and C++ templates. Please ask before using templates with ``auto`` in a pull request.
89+
90+
.. code-block:: cpp
91+
92+
// Full type definitions.
93+
void (*mult64to128)(uint64_t, uint64_t, uint64_t &, uint64_t &) = [](uint64_t u, uint64_t v, uint64_t &h, uint64_t &l) { ... }
94+
void (^JOYSTICK_LEFT)(GCControllerDirectionPad *__strong, float, float) = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) { ... }
95+
96+
// Less clutter with auto.
97+
auto mult64to128 = [](uint64_t u, uint64_t v, uint64_t &h, uint64_t &l) { ... }
98+
auto JOYSTICK_LEFT = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) { ... }
99+
100+
// Compare function for different types.
101+
template <typename T1, typename T2>
102+
constexpr auto MIN(const T1 m_a, const T2 m_b) {
103+
return m_a < m_b ? m_a : m_b;
104+
}
105+
106+
We chose to forbid ``auto`` in all other cases. Thank you for your understanding.
89107

90108
Lambdas
91109
~~~~~~~

0 commit comments

Comments
 (0)