[libcxx-commits] [PATCH] D105597: [libcxx][nfc] Remove <variant>'s dependence on <array>.
Zoe Carver via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 7 15:27:56 PDT 2021
zoecarver created this revision.
zoecarver added reviewers: cjdb, Quuxplusone, ldionne.
zoecarver requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
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`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105597
Files:
libcxx/include/variant
Index: libcxx/include/variant
===================================================================
--- libcxx/include/variant
+++ libcxx/include/variant
@@ -203,7 +203,6 @@
#include <__config>
#include <__utility/forward.h>
#include <__tuple>
-#include <array>
#include <compare>
#include <exception>
#include <functional>
@@ -238,6 +237,30 @@
// Remove this once we drop support for GCC 5.
#if _LIBCPP_STD_VER > 14 && !(defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW < 6000)
+template<class _Tp, size_t _Size>
+struct __light_array {
+ _Tp __buff_[_Size] = {0};
+
+ inline _LIBCPP_INLINE_VISIBILITY constexpr
+ _Tp &operator[](size_t __n) noexcept {
+ return __buff_[__n];
+ }
+
+ inline _LIBCPP_INLINE_VISIBILITY constexpr
+ const _Tp &operator[](size_t __n) const noexcept {
+ return __buff_[__n];
+ }
+
+ inline _LIBCPP_INLINE_VISIBILITY
+ constexpr friend bool
+ operator==(const __light_array& __x, const __light_array& __y) noexcept {
+ for (size_t __i = 0; __i < _Size; ++__i)
+ if (__x.__buff_[__i] != __y.__buff_[__i])
+ return false;
+ return true;
+ }
+};
+
_LIBCPP_NORETURN
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
@@ -498,7 +521,7 @@
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 __light_array<_Tp, _Np>& __elems,
size_t __index, _Indices... __indices) {
return __at(__elems[__index], __indices...);
}
@@ -514,8 +537,8 @@
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)>;
- return __result{{_VSTD::forward<_Fs>(__fs)...}};
+ using __result = __light_array<common_type_t<__uncvref_t<_Fs>...>, sizeof...(_Fs)>;
+ return __result{_VSTD::forward<_Fs>(__fs)...};
}
template <size_t... _Is>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105597.357096.patch
Type: text/x-patch
Size: 2101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210707/6f59c401/attachment.bin>
More information about the libcxx-commits
mailing list