[libcxx-commits] [libcxx] [libc++] Simplify the implementation of std::get for pairs (PR #102740)

Mital Ashok via libcxx-commits libcxx-commits at lists.llvm.org
Sat Aug 10 04:44:37 PDT 2024


================
@@ -635,42 +635,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::move(__p.first);
----------------
MitalAshok wrote:

This should be `std::move(__p).first` no? So `std::pair<int&, int> f(); std::get<0>(f())` is an `int&` and not an `int&&`

https://github.com/llvm/llvm-project/pull/102740


More information about the libcxx-commits mailing list