Skip to content

Commit 0849427

Browse files
committed
[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
1 parent 30cce54 commit 0849427

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

libcxx/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ API Changes
6969
- The `LIBCXXABI_ENABLE_PIC` CMake option was removed. If you are building your
7070
own libc++abi from source and were using `LIBCXXABI_ENABLE_PIC`, please use
7171
`CMAKE_POSITION_INDEPENDENT_CODE=ON` instead.
72+
73+
- When the header <variant> is included, it will no longer include <array> transitively.

libcxx/include/variant

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ namespace std {
204204
#include <__utility/forward.h>
205205
#include <__variant/monostate.h>
206206
#include <__tuple>
207-
#include <array>
208207
#include <compare>
209208
#include <exception>
210209
#include <functional>
@@ -239,6 +238,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
239238
// Remove this once we drop support for GCC 5.
240239
#if _LIBCPP_STD_VER > 14 && !(defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW < 6000)
241240

241+
// Light N-dimensional array of function pointers. Used in place of std::array to avoid
242+
// adding a dependency.
243+
template<class _Tp, size_t _Size>
244+
struct __farray {
245+
static_assert(_Size > 0, "N-dimensional array should never be empty in std::visit");
246+
_Tp __buf_[_Size] = {};
247+
248+
_LIBCPP_INLINE_VISIBILITY constexpr
249+
const _Tp &operator[](size_t __n) const noexcept {
250+
return __buf_[__n];
251+
}
252+
};
253+
242254
_LIBCPP_NORETURN
243255
inline _LIBCPP_INLINE_VISIBILITY
244256
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
@@ -499,7 +511,7 @@ private:
499511

500512
template <class _Tp, size_t _Np, typename... _Indices>
501513
inline _LIBCPP_INLINE_VISIBILITY
502-
static constexpr auto&& __at(const array<_Tp, _Np>& __elems,
514+
static constexpr auto&& __at(const __farray<_Tp, _Np>& __elems,
503515
size_t __index, _Indices... __indices) {
504516
return __at(__elems[__index], __indices...);
505517
}
@@ -515,7 +527,7 @@ private:
515527
inline _LIBCPP_INLINE_VISIBILITY
516528
static constexpr auto __make_farray(_Fs&&... __fs) {
517529
__std_visit_visitor_return_type_check<__uncvref_t<_Fs>...>();
518-
using __result = array<common_type_t<__uncvref_t<_Fs>...>, sizeof...(_Fs)>;
530+
using __result = __farray<common_type_t<__uncvref_t<_Fs>...>, sizeof...(_Fs)>;
519531
return __result{{_VSTD::forward<_Fs>(__fs)...}};
520532
}
521533

0 commit comments

Comments
 (0)