Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups: Consistently comment enable_if_t definitions #3539

Merged

Conversation

StephanTLavavej
Copy link
Member

For C++17's parallel algorithms, where we separately declare and define many of them, we developed a convention where the declaration is = 0 and the definition is /* = 0 */. This is a reminder that while the default template argument can't be repeated, we haven't simply forgotten it:

STL/stl/inc/algorithm

Lines 1124 to 1125 in 994f941

_EXPORT_STD template <class _ExPo, class _FwdIt, class _Pr, _Enable_if_execution_policy_t<_ExPo> = 0>
_NODISCARD bool all_of(_ExPo&&, _FwdIt _First, _FwdIt _Last, _Pr _Pred) noexcept; // terminates

STL/stl/inc/execution

Lines 1119 to 1120 in 994f941

_EXPORT_STD template <class _ExPo, class _FwdIt, class _Pr, _Enable_if_execution_policy_t<_ExPo> /* = 0 */>
_NODISCARD bool all_of(_ExPo&&, _FwdIt _First, _FwdIt _Last, _Pr _Pred) noexcept /* terminates */ {

Thanks to Michael Grier for noticing that we've accumulated inconsistency elsewhere, with relics of an older convention where we'd name the template parameter in the definition _Enabled. That older convention was less clear and doesn't really provide new information (as we're already using enable_if_t).

  • Change _Enabled = 0 to = 0 for countr_one() and _Popcount().
    • There are no other declarations.
  • Change _Enabled to /* = 0 */ for duration_cast(), rotr(), countl_zero(), and swap() for arrays.
  • Cleanup swap(_Ty&, _Ty&).
    • For C++17, follow the convention where the declaration is = 0 and the definition is /* = 0 */.
    • For C++14, we want to emphasize the purpose of the second template parameter, so the declaration is int _Enabled = 0 and the definition is int _Enabled /* = 0 */.
  • Add /* = 0 */ to tuple's ctors and uses_allocator_construction_args().

After this cleanup, the only remaining uses of _Enabled in product code are in other contexts. I've audited all occurrences where enable_if_t appears in separate declarations and definitions, including through helper typedefs, so this cleanup should be fairly exhaustive.

…untl_zero()`, and `swap()` for arrays.
For C++17, follow the convention where the declaration is ` = 0` and the definition is `/* = 0 */`.

For C++14, we want to emphasize the purpose of the second template parameter, so the declaration is `int _Enabled = 0` and the definition is `int _Enabled /* = 0 */`.
@StephanTLavavej StephanTLavavej added the documentation Related to documentation or comments label Mar 5, 2023
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner March 5, 2023 20:24
@StephanTLavavej
Copy link
Member Author

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 0c16581 into microsoft:main Mar 7, 2023
@StephanTLavavej StephanTLavavej deleted the stl-cleanups-enable-if branch March 7, 2023 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Related to documentation or comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants