public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-4419] libstdc++: Simplify variant access functions
Date: Thu, 14 Oct 2021 21:19:51 +0000 (GMT)	[thread overview]
Message-ID: <20211014211951.A528D3858419@sourceware.org> (raw)

https://gcc.gnu.org/g:4f87d4c5aec9a1eaca7be61e5c8aab4d6e61b1d8

commit r12-4419-g4f87d4c5aec9a1eaca7be61e5c8aab4d6e61b1d8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Oct 14 20:37:38 2021 +0100

    libstdc++: Simplify variant access functions
    
    libstdc++-v3/ChangeLog:
    
            * include/std/variant (__variant::__get(in_place_index_t<N>, U&&)):
            Rename to __get_n and remove first argument. Replace pair of
            overloads with a single function using 'if constexpr'.
            (__variant::__get(Variant&&)): Adjust to use __get_n.

Diff:
---
 libstdc++-v3/include/std/variant | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 6377b6731ea..b85a89d0b7b 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -279,27 +279,26 @@ namespace __variant
       __gnu_cxx::__aligned_membuf<_Type> _M_storage;
     };
 
-  template<typename _Union>
-    constexpr decltype(auto)
-    __get(in_place_index_t<0>, _Union&& __u) noexcept
-    { return std::forward<_Union>(__u)._M_first._M_get(); }
-
   template<size_t _Np, typename _Union>
     constexpr decltype(auto)
-    __get(in_place_index_t<_Np>, _Union&& __u) noexcept
+    __get_n(_Union&& __u) noexcept
     {
-      return __variant::__get(in_place_index<_Np-1>,
-			      std::forward<_Union>(__u)._M_rest);
+      if constexpr (_Np == 0)
+	return std::forward<_Union>(__u)._M_first._M_get();
+      else if constexpr (_Np == 1)
+	return std::forward<_Union>(__u)._M_rest._M_first._M_get();
+      else if constexpr (_Np == 2)
+	return std::forward<_Union>(__u)._M_rest._M_rest._M_first._M_get();
+      else
+	return __variant::__get_n<_Np - 3>(
+		 std::forward<_Union>(__u)._M_rest._M_rest._M_rest);
     }
 
   // Returns the typed storage for __v.
   template<size_t _Np, typename _Variant>
     constexpr decltype(auto)
     __get(_Variant&& __v) noexcept
-    {
-      return __variant::__get(std::in_place_index<_Np>,
-			      std::forward<_Variant>(__v)._M_u);
-    }
+    { return __variant::__get_n<_Np>(std::forward<_Variant>(__v)._M_u); }
 
   template<typename... _Types>
     struct _Traits


                 reply	other threads:[~2021-10-14 21:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211014211951.A528D3858419@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).