[libcxx-commits] [libcxx] [libc++] Simplify the implementation of std::get for pairs (PR #114984)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 12 09:16:56 PST 2024
================
@@ -633,42 +633,42 @@ get(const pair<_T1, _T2>&& __p) _NOEXCEPT {
#if _LIBCPP_STD_VER >= 14
template <class _T1, class _T2>
inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {
- return __get_pair<0>::get(__p);
+ return __p.first;
}
template <class _T1, class _T2>
inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(pair<_T1, _T2> const& __p) _NOEXCEPT {
- return __get_pair<0>::get(__p);
+ return __p.first;
}
template <class _T1, class _T2>
inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {
- return __get_pair<0>::get(std::move(__p));
+ return std::forward<_T1&&>(__p.first);
}
template <class _T1, class _T2>
inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(pair<_T1, _T2> const&& __p) _NOEXCEPT {
- return __get_pair<0>::get(std::move(__p));
+ return std::forward<_T1 const&&>(__p.first);
}
template <class _T1, class _T2>
inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T2, _T1>& __p) _NOEXCEPT {
- return __get_pair<1>::get(__p);
+ return __p.second;
}
----------------
ldionne wrote:
The way this was originally written is really confusing! `_T1` is sneakily used as the second template argument of `pair`, that's subtle. Could be refactored as a separate patch.
https://github.com/llvm/llvm-project/pull/114984
More information about the libcxx-commits
mailing list