Skip to content

[libc++][NFC] Comment cleanup for <type_traits> #130422

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

Merged
merged 1 commit into from
Mar 9, 2025

Conversation

frederick-vs-ja
Copy link
Contributor

  • Aligns all version comments to line 65.
  • Consistently uses // since C++ instead of // C++, in lowercase as used in most version comments.
  • Consistently uses class to introduce type template parameters.
  • Consistently uses inline constexpr for variable templates.
  • Corrects the comment for bool_constant to // since C++17 as it's a C++17 feature.
  • Changes the class-key of result_of to struct, which follows N4659 [depr.meta.types] and the actual usage in libc++.
  • Adds missed // since C++17 for is_(nothrow_)invocable(_r).
  • Moves the comments for is_nothrow_convertible_v to the part for variable templates.
  • Removes duplicated comments for true_type and false_type.

- Aligns all version comments to line 65.
- Consistently uses `// since C++` instead of `// C++`, in lowercase as used in most version comments.
- Consistently uses `class` to introduce type template parameters.
- Consistently uses `inline constexpr` for variable templates.
- Corrects the comment for `bool_constant` to `// since C++17` as it's a C++17 feature.
- Changes the class-key of `result_of` to `struct`, which follows N4659 [depr.meta.types] and the actual usage in libc++.
- Adds missed `// since C++17` for `is_(nothrow_)invocable(_r)`.
- Moves the comments for `is_nothrow_convertible_v` to the part for variable templates.
- Removes duplicated comments for `true_type` and `false_type`.
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner March 8, 2025 15:52
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 8, 2025

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes
  • Aligns all version comments to line 65.
  • Consistently uses // since C++ instead of // C++, in lowercase as used in most version comments.
  • Consistently uses class to introduce type template parameters.
  • Consistently uses inline constexpr for variable templates.
  • Corrects the comment for bool_constant to // since C++17 as it's a C++17 feature.
  • Changes the class-key of result_of to struct, which follows N4659 [depr.meta.types] and the actual usage in libc++.
  • Adds missed // since C++17 for is_(nothrow_)invocable(_r).
  • Moves the comments for is_nothrow_convertible_v to the part for variable templates.
  • Removes duplicated comments for true_type and false_type.

Patch is 34.89 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/130422.diff

1 Files Affected:

  • (modified) libcxx/include/type_traits (+180-155)
diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index e09a911eeb313..a03a60917cd54 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -18,13 +18,11 @@ namespace std
 
     // helper class:
     template <class T, T v> struct integral_constant;
-    typedef integral_constant<bool, true>  true_type;   // C++11
-    typedef integral_constant<bool, false> false_type;  // C++11
+    typedef integral_constant<bool, true>  true_type;           // since C++11
+    typedef integral_constant<bool, false> false_type;          // since C++11
 
-    template <bool B>                                   // C++14
-    using bool_constant = integral_constant<bool, B>;   // C++14
-    typedef bool_constant<true> true_type;              // C++14
-    typedef bool_constant<false> false_type;            // C++14
+    template <bool B>
+    using bool_constant = integral_constant<bool, B>;           // since C++17
 
     // helper traits
     template <bool, class T = void> struct enable_if;
@@ -32,7 +30,7 @@ namespace std
 
     // Primary classification traits:
     template <class T> struct is_void;
-    template <class T> struct is_null_pointer;  // C++14
+    template <class T> struct is_null_pointer;                  // since C++14
     template <class T> struct is_integral;
     template <class T> struct is_floating_point;
     template <class T> struct is_array;
@@ -51,7 +49,7 @@ namespace std
     template <class T> struct is_arithmetic;
     template <class T> struct is_fundamental;
     template <class T> struct is_member_pointer;
-    template <class T> struct is_scoped_enum; // C++23
+    template <class T> struct is_scoped_enum;                   // since C++23
     template <class T> struct is_scalar;
     template <class T> struct is_object;
     template <class T> struct is_compound;
@@ -75,9 +73,9 @@ namespace std
     template <class T> struct remove_pointer;
     template <class T> struct add_pointer;
 
-    template<class T> struct type_identity;                     // C++20
+    template<class T> struct type_identity;                     // since C++20
     template<class T>
-      using type_identity_t = typename type_identity<T>::type;  // C++20
+      using type_identity_t = typename type_identity<T>::type;  // since C++20
 
     // Integral properties:
     template <class T> struct is_signed;
@@ -91,20 +89,20 @@ namespace std
     template <class T> struct remove_extent;
     template <class T> struct remove_all_extents;
 
-    template <class T> struct is_bounded_array;                 // C++20
-    template <class T> struct is_unbounded_array;               // C++20
+    template <class T> struct is_bounded_array;                 // since C++20
+    template <class T> struct is_unbounded_array;               // since C++20
 
     // Member introspection:
     template <class T> struct is_trivial;
-    template <class T> struct is_pod;          // Deprecated in C++20
+    template <class T> struct is_pod;                           // deprecated in C++20
     template <class T> struct is_trivially_copyable;
     template <class T> struct is_standard_layout;
-    template <class T> struct is_literal_type; // Deprecated in C++17; removed in C++20
+    template <class T> struct is_literal_type;                  // deprecated in C++17; removed in C++20
     template <class T> struct is_empty;
     template <class T> struct is_polymorphic;
     template <class T> struct is_abstract;
-    template <class T> struct is_final; // C++14
-    template <class T> struct is_aggregate; // C++17
+    template <class T> struct is_final;                         // since C++14
+    template <class T> struct is_aggregate;                     // since C++17
 
     template <class T, class... Args> struct is_constructible;
     template <class T>                struct is_default_constructible;
@@ -113,8 +111,8 @@ namespace std
     template <class T, class U>       struct is_assignable;
     template <class T>                struct is_copy_assignable;
     template <class T>                struct is_move_assignable;
-    template <class T, class U>       struct is_swappable_with;       // C++17
-    template <class T>                struct is_swappable;            // C++17
+    template <class T, class U>       struct is_swappable_with; // since C++17
+    template <class T>                struct is_swappable;      // since C++17
     template <class T>                struct is_destructible;
 
     template <class T, class... Args> struct is_trivially_constructible;
@@ -133,301 +131,328 @@ namespace std
     template <class T, class U>       struct is_nothrow_assignable;
     template <class T>                struct is_nothrow_copy_assignable;
     template <class T>                struct is_nothrow_move_assignable;
-    template <class T, class U>       struct is_nothrow_swappable_with; // C++17
-    template <class T>                struct is_nothrow_swappable;      // C++17
+    template <class T, class U>
+      struct is_nothrow_swappable_with;                         // since C++17
+    template <class T>
+      struct is_nothrow_swappable;                              // since C++17
     template <class T>                struct is_nothrow_destructible;
 
-    template<class T> struct is_implicit_lifetime;                     // Since C++23
+    template <class T> struct is_implicit_lifetime;             // since C++23
 
     template <class T> struct has_virtual_destructor;
 
-    template<class T> struct has_unique_object_representations;         // C++17
+    template <class T>
+      struct has_unique_object_representations;                 // since C++17
 
-    template<class T, class U> struct reference_constructs_from_temporary; // Since C++23
-    template<class T, class U> struct reference_converts_from_temporary;   // Since C++23
+    template<class T, class U>
+      struct reference_constructs_from_temporary;               // since C++23
+    template<class T, class U>
+      struct reference_converts_from_temporary;                 // since C++23
 
     // Relationships between types:
     template <class T, class U> struct is_same;
     template <class Base, class Derived> struct is_base_of;
-    template <class Base, class Derived> struct is_virtual_base_of;     // C++26
+    template <class Base, class Derived>
+      struct is_virtual_base_of;                                // since C++26
 
     template <class From, class To> struct is_convertible;
-    template <typename From, typename To> struct is_nothrow_convertible;                  // C++20
-    template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20
+    template <class From, class To>
+      struct is_nothrow_convertible;                            // since C++20
 
-    template <class Fn, class... ArgTypes> struct is_invocable;
-    template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
+    template <class Fn, class... ArgTypes> struct is_invocable; // since C++17
+    template <class R, class Fn, class... ArgTypes>
+      struct is_invocable_r;                                    // since C++17
 
-    template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
-    template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
+    template <class Fn, class... ArgTypes>
+      struct is_nothrow_invocable;                              // since C++17
+    template <class R, class Fn, class... ArgTypes>
+      struct is_nothrow_invocable_r;                            // since C++17
 
     // Alignment properties and transformations:
     template <class T> struct alignment_of;
     template <size_t Len, size_t Align = most_stringent_alignment_requirement>
-        struct aligned_storage;                                 // deprecated in C++23
+      struct aligned_storage;                                   // deprecated in C++23
     template <size_t Len, class... Types> struct aligned_union; // deprecated in C++23
-    template <class T> struct remove_cvref; // C++20
+    template <class T> struct remove_cvref;                     // since C++20
 
     template <class T> struct decay;
     template <class... T> struct common_type;
     template <class T> struct underlying_type;
-    template <class> class result_of; // undefined; deprecated in C++17; removed in C++20
-    template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20
-    template <class Fn, class... ArgTypes> struct invoke_result;  // C++17
+    template <class> struct result_of;                          // undefined; deprecated in C++17; removed in C++20
+    template <class Fn, class... ArgTypes>
+      struct result_of<Fn(ArgTypes...)>;                        // deprecated in C++17; removed in C++20
+    template <class Fn, class... ArgTypes>
+      struct invoke_result;                                     // since C++17
 
     // const-volatile modifications:
     template <class T>
-      using remove_const_t    = typename remove_const<T>::type;  // C++14
+      using remove_const_t = typename remove_const<T>::type;    // since C++14
     template <class T>
-      using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
+      using remove_volatile_t
+        = typename remove_volatile<T>::type;                    // since C++14
     template <class T>
-      using remove_cv_t       = typename remove_cv<T>::type;  // C++14
+      using remove_cv_t    = typename remove_cv<T>::type;       // since C++14
     template <class T>
-      using add_const_t       = typename add_const<T>::type;  // C++14
+      using add_const_t    = typename add_const<T>::type;       // since C++14
     template <class T>
-      using add_volatile_t    = typename add_volatile<T>::type;  // C++14
+      using add_volatile_t = typename add_volatile<T>::type;    // since C++14
     template <class T>
-      using add_cv_t          = typename add_cv<T>::type;  // C++14
+      using add_cv_t       = typename add_cv<T>::type;          // since C++14
 
     // reference modifications:
     template <class T>
-      using remove_reference_t     = typename remove_reference<T>::type;  // C++14
+      using remove_reference_t
+        = typename remove_reference<T>::type;                   // since C++14
     template <class T>
-      using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
+      using add_lvalue_reference_t
+        = typename add_lvalue_reference<T>::type;               // since C++14
     template <class T>
-      using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
+      using add_rvalue_reference_t
+        = typename add_rvalue_reference<T>::type;               // since C++14
 
     // sign modifications:
     template <class T>
-      using make_signed_t   = typename make_signed<T>::type;  // C++14
+      using make_signed_t   = typename make_signed<T>::type;    // since C++14
     template <class T>
-      using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
+      using make_unsigned_t = typename make_unsigned<T>::type;  // since C++14
 
     // array modifications:
     template <class T>
-      using remove_extent_t      = typename remove_extent<T>::type;  // C++14
+      using remove_extent_t
+        = typename remove_extent<T>::type;                      // since C++14
     template <class T>
-      using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
+      using remove_all_extents_t
+        = typename remove_all_extents<T>::type;                 // since C++14
 
     template <class T>
       inline constexpr bool is_bounded_array_v
-        = is_bounded_array<T>::value;                                     // C++20
+        = is_bounded_array<T>::value;                           // since C++20
       inline constexpr bool is_unbounded_array_v
-        = is_unbounded_array<T>::value;                                   // C++20
+        = is_unbounded_array<T>::value;                         // since C++20
 
     // pointer modifications:
     template <class T>
-      using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
+      using remove_pointer_t
+        = typename remove_pointer<T>::type;                     // since C++14
     template <class T>
-      using add_pointer_t    = typename add_pointer<T>::type;  // C++14
+      using add_pointer_t = typename add_pointer<T>::type;      // since C++14
 
     // other transformations:
     template <size_t Len, size_t Align=default-alignment>
-      using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
+      using aligned_storage_t
+        = typename aligned_storage<Len,Align>::type;            // since C++14
     template <size_t Len, class... Types>
-      using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
+      using aligned_union_t
+        = typename aligned_union<Len,Types...>::type;           // since C++14
     template <class T>
-      using remove_cvref_t    = typename remove_cvref<T>::type;  // C++20
+      using remove_cvref_t
+        = typename remove_cvref<T>::type;                       // since C++20
     template <class T>
-      using decay_t           = typename decay<T>::type;  // C++14
+      using decay_t     = typename decay<T>::type;              // since C++14
     template <bool b, class T=void>
-      using enable_if_t       = typename enable_if<b,T>::type;  // C++14
+      using enable_if_t = typename enable_if<b,T>::type;        // since C++14
     template <bool b, class T, class F>
-      using conditional_t     = typename conditional<b,T,F>::type;  // C++14
+      using conditional_t
+        = typename conditional<b,T,F>::type;                    // since C++14
     template <class... T>
-      using common_type_t     = typename common_type<T...>::type;  // C++14
+      using common_type_t
+        = typename common_type<T...>::type;                     // since C++14
     template <class T>
-      using underlying_type_t = typename underlying_type<T>::type;  // C++14
+      using underlying_type_t
+        = typename underlying_type<T>::type;                    // since C++14
     template <class T>
-      using result_of_t       = typename result_of<T>::type;  // C++14; deprecated in C++17; removed in C++20
+      using result_of_t = typename result_of<T>::type;          // since C++14; deprecated in C++17; removed in C++20
     template <class Fn, class... ArgTypes>
-      using invoke_result_t   = typename invoke_result<Fn, ArgTypes...>::type;  // C++17
+      using invoke_result_t
+       = typename invoke_result<Fn, ArgTypes...>::type;         // since C++17
 
     template <class...>
-      using void_t = void;   // C++17
+      using void_t = void;                                      // since C++17
 
       // See C++14 20.10.4.1, primary type categories
       template <class T> inline constexpr bool is_void_v
-        = is_void<T>::value;                                             // C++17
+        = is_void<T>::value;                                    // since C++17
       template <class T> inline constexpr bool is_null_pointer_v
-        = is_null_pointer<T>::value;                                     // C++17
+        = is_null_pointer<T>::value;                            // since C++17
       template <class T> inline constexpr bool is_integral_v
-        = is_integral<T>::value;                                         // C++17
+        = is_integral<T>::value;                                // since C++17
       template <class T> inline constexpr bool is_floating_point_v
-        = is_floating_point<T>::value;                                   // C++17
+        = is_floating_point<T>::value;                          // since C++17
       template <class T> inline constexpr bool is_array_v
-        = is_array<T>::value;                                            // C++17
+        = is_array<T>::value;                                   // since C++17
       template <class T> inline constexpr bool is_pointer_v
-        = is_pointer<T>::value;                                          // C++17
+        = is_pointer<T>::value;                                 // since C++17
       template <class T> inline constexpr bool is_lvalue_reference_v
-        = is_lvalue_reference<T>::value;                                 // C++17
+        = is_lvalue_reference<T>::value;                        // since C++17
       template <class T> inline constexpr bool is_rvalue_reference_v
-        = is_rvalue_reference<T>::value;                                 // C++17
+        = is_rvalue_reference<T>::value;                        // since C++17
       template <class T> inline constexpr bool is_member_object_pointer_v
-        = is_member_object_pointer<T>::value;                            // C++17
+        = is_member_object_pointer<T>::value;                   // since C++17
       template <class T> inline constexpr bool is_member_function_pointer_v
-        = is_member_function_pointer<T>::value;                          // C++17
+        = is_member_function_pointer<T>::value;                 // since C++17
       template <class T> inline constexpr bool is_enum_v
-        = is_enum<T>::value;                                             // C++17
+        = is_enum<T>::value;                                    // since C++17
       template <class T> inline constexpr bool is_union_v
-        = is_union<T>::value;                                            // C++17
+        = is_union<T>::value;                                   // since C++17
       template <class T> inline constexpr bool is_class_v
-        = is_class<T>::value;                                            // C++17
+        = is_class<T>::value;                                   // since C++17
       template <class T> inline constexpr bool is_function_v
-        = is_function<T>::value;                                         // C++17
+        = is_function<T>::value;                                // since C++17
 
       // See C++14 20.10.4.2, composite type categories
       template <class T> inline constexpr bool is_reference_v
-        = is_reference<T>::value;                                        // C++17
+        = is_reference<T>::value;                               // since C++17
       template <class T> inline constexpr bool is_arithmetic_v
-        = is_arithmetic<T>::value;                                       // C++17
+        = is_arithmetic<T>::value;                              // since C++17
       template <class T> inline constexpr bool is_fundamental_v
-        = is_fundamental<T>::value;                                      // C++17
+        = is_fundamental<T>::value;                             // since C++17
       template <class T> inline constexpr bool is_object_v
-        = is_object<T>::value;                                           // C++17
+        = is_object<T>::value;                                  // since C++17
       template <class T> inline constexpr bool is_scalar_v
-        = is_scalar<T>::value;                                           // C++17
+        = is_scalar<T>::value;                                  // since C++17
       template <class T> inline constexpr bool is_compound_v
-        = is_compound<T>::value;                                         // C++17
+        = is_compound<T>::value;                                // since C++17
       template <class T> inline constexpr bool is_member_pointer_v
-        = is_member_pointer<T>::value;                                   // C++17
+        = is_member_pointer<T>::value;                          // since C++17
       template <class T> inline constexpr bool is_scoped_enum_v
-        = is_scoped_enum<T>::value;                                      // C++23
+        = is_scoped_enum<T>::value;                             // since C++23
 
       // See C++14 20.10.4.3, type properties
       template <class T> inline constexpr bool is_const_v
-        = is_const<T>::value;                                            // C++17
+        = is_const<T>::value;                                   // since C++17
       template <class T> inline constexpr bool is_volatile_v
-        = is_volatile<T>::value;                                         //...
[truncated]

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this cleanup, LGTM!

@frederick-vs-ja frederick-vs-ja merged commit 9e87caf into llvm:main Mar 9, 2025
83 checks passed
@frederick-vs-ja frederick-vs-ja deleted the type_traits-comments branch March 9, 2025 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants