[libcxx-commits] [libcxx] 0849427 - [libcxx][nfc] Remove <variant>'s dependence on <array>.

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 9 10:14:10 PDT 2021


Author: zoecarver
Date: 2021-07-09T10:13:57-07:00
New Revision: 0849427faeab8d2e88868463496b1a8283e7dcda

URL: https://github.com/llvm/llvm-project/commit/0849427faeab8d2e88868463496b1a8283e7dcda
DIFF: https://github.com/llvm/llvm-project/commit/0849427faeab8d2e88868463496b1a8283e7dcda.diff

LOG: [libcxx][nfc] Remove <variant>'s dependence on <array>.

This will allow us to use variant in common_iterator. We do this by introducing a new `__light_array` type that variant uses instead of `std::array`.

Differential Revision: https://reviews.llvm.org/D105597

Added: 
    

Modified: 
    libcxx/docs/ReleaseNotes.rst
    libcxx/include/variant

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index bda3c646071f9..768741418aa2f 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -69,3 +69,5 @@ API Changes
 - The `LIBCXXABI_ENABLE_PIC` CMake option was removed. If you are building your
   own libc++abi from source and were using `LIBCXXABI_ENABLE_PIC`, please use
   `CMAKE_POSITION_INDEPENDENT_CODE=ON` instead.
+
+- When the header <variant> is included, it will no longer include <array> transitively.

diff  --git a/libcxx/include/variant b/libcxx/include/variant
index 08b64612d133c..7e8b683953d42 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -204,7 +204,6 @@ namespace std {
 #include <__utility/forward.h>
 #include <__variant/monostate.h>
 #include <__tuple>
-#include <array>
 #include <compare>
 #include <exception>
 #include <functional>
@@ -239,6 +238,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 //       Remove this once we drop support for GCC 5.
 #if _LIBCPP_STD_VER > 14 && !(defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW < 6000)
 
+// Light N-dimensional array of function pointers. Used in place of std::array to avoid
+// adding a dependency.
+template<class _Tp, size_t _Size>
+struct __farray {
+  static_assert(_Size > 0, "N-dimensional array should never be empty in std::visit");
+  _Tp __buf_[_Size] = {};
+
+  _LIBCPP_INLINE_VISIBILITY constexpr
+  const _Tp &operator[](size_t __n) const noexcept {
+      return __buf_[__n];
+  }
+};
+
 _LIBCPP_NORETURN
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
@@ -499,7 +511,7 @@ private:
 
   template <class _Tp, size_t _Np, typename... _Indices>
   inline _LIBCPP_INLINE_VISIBILITY
-  static constexpr auto&& __at(const array<_Tp, _Np>& __elems,
+  static constexpr auto&& __at(const __farray<_Tp, _Np>& __elems,
                                size_t __index, _Indices... __indices) {
     return __at(__elems[__index], __indices...);
   }
@@ -515,7 +527,7 @@ private:
   inline _LIBCPP_INLINE_VISIBILITY
   static constexpr auto __make_farray(_Fs&&... __fs) {
     __std_visit_visitor_return_type_check<__uncvref_t<_Fs>...>();
-    using __result = array<common_type_t<__uncvref_t<_Fs>...>, sizeof...(_Fs)>;
+    using __result = __farray<common_type_t<__uncvref_t<_Fs>...>, sizeof...(_Fs)>;
     return __result{{_VSTD::forward<_Fs>(__fs)...}};
   }
 


        


More information about the libcxx-commits mailing list