Skip to content

[libc++][modules] Use inline variable instead of true_type #106797

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

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Aug 30, 2024

This allows breaking up a dependency from __fwd/array.h onto __type_traits, which is a circular dependency once __type_traits becomes a module of its own. This is also a small consistency improvement since we've been using inline variables for traits like this elsewhere in the library.

@ldionne ldionne requested a review from a team as a code owner August 30, 2024 21:01
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Aug 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 30, 2024

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

This allows breaking up a dependency from __fwd/array.h onto __type_traits, which is a circular dependency once __type_traits becomes a module of its own. This is also a small consistency improvement since we've been using inline variables for traits like this elsewhere in the library.


Full diff: https://github.com/llvm/llvm-project/pull/106797.diff

2 Files Affected:

  • (modified) libcxx/include/__fwd/array.h (+3-3)
  • (modified) libcxx/include/span (+1-1)
diff --git a/libcxx/include/__fwd/array.h b/libcxx/include/__fwd/array.h
index b429d0c5a95427..6c6461e7276040 100644
--- a/libcxx/include/__fwd/array.h
+++ b/libcxx/include/__fwd/array.h
@@ -35,11 +35,11 @@ template <size_t _Ip, class _Tp, size_t _Size>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&& get(const array<_Tp, _Size>&&) _NOEXCEPT;
 #endif
 
-template <class>
-struct __is_std_array : false_type {};
+template <class _Tp>
+inline const bool __is_std_array_v = false;
 
 template <class _Tp, size_t _Size>
-struct __is_std_array<array<_Tp, _Size> > : true_type {};
+inline const bool __is_std_array_v<array<_Tp, _Size> > = true;
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/libcxx/include/span b/libcxx/include/span
index da631cdc3f90e6..a32f7a372e2ae1 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -210,7 +210,7 @@ concept __span_compatible_range =
     ranges::contiguous_range<_Range> &&                             //
     ranges::sized_range<_Range> &&                                  //
     (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) && //
-    !__is_std_array<remove_cvref_t<_Range>>::value &&               //
+    !__is_std_array_v<remove_cvref_t<_Range>> &&                    //
     !is_array_v<remove_cvref_t<_Range>> &&                          //
     is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>> (*)[], _ElementType (*)[]>;
 

This allows breaking up a dependency from __fwd/array.h onto
__type_traits, which is a circular dependency once __type_traits
becomes a module of its own. This is also a small consistency
improvement since we've been using inline variables for traits
like this elsewhere in the library.
@ldionne ldionne force-pushed the review/modularization-avoid-using-true_type branch from 3677bb7 to 02f97af Compare September 3, 2024 17:23
@ldionne ldionne merged commit 7a785d4 into llvm:main Sep 4, 2024
61 checks passed
@ldionne ldionne deleted the review/modularization-avoid-using-true_type branch September 4, 2024 15:18
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