public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Simplify _Node_insert_return to avoid including <tuple>
@ 2017-10-27 18:04 Jonathan Wakely
  2017-11-02 22:00 ` Tim Song
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2017-10-27 18:04 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 228 bytes --]

We can use auto return types and if constexpr to do this without
including <tuple>.

	* include/bits/node_handle.h (_Node_insert_return::get): Avoid
	use of std::tie and std::get.

Tested powerpc64le-linux, committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2147 bytes --]

commit 397d3b68eb53ff6b229ac777a05dff4ae842a19b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Oct 27 18:07:35 2017 +0100

    Simplify _Node_insert_return to avoid including <tuple>
    
            * include/bits/node_handle.h (_Node_insert_return::get): Avoid
            use of std::tie and std::get.

diff --git a/libstdc++-v3/include/bits/node_handle.h b/libstdc++-v3/include/bits/node_handle.h
index c7694a1e0ef..f93bfd7f686 100644
--- a/libstdc++-v3/include/bits/node_handle.h
+++ b/libstdc++-v3/include/bits/node_handle.h
@@ -37,7 +37,6 @@
 # define __cpp_lib_node_extract 201606
 
 #include <optional>
-#include <tuple>
 #include <bits/alloc_traits.h>
 #include <bits/ptr_traits.h>
 
@@ -286,22 +285,50 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       template<size_t _Idx>
 	decltype(auto) get() &
-	{ return std::get<_Idx>(std::tie(inserted, position, node)); }
+	{
+	  static_assert(_Idx < 3);
+	  if constexpr (_Idx == 0)
+	    return inserted;
+	  else if constexpr (_Idx == 1)
+	    return position;
+	  else if constexpr (_Idx == 2)
+	    return node;
+	}
 
       template<size_t _Idx>
 	decltype(auto) get() const &
-	{ return std::get<_Idx>(std::tie(inserted, position, node)); }
+	{
+	  static_assert(_Idx < 3);
+	  if constexpr (_Idx == 0)
+	    return inserted;
+	  else if constexpr (_Idx == 1)
+	    return position;
+	  else if constexpr (_Idx == 2)
+	    return node;
+	}
 
       template<size_t _Idx>
 	decltype(auto) get() &&
 	{
-	  return std::move(std::get<_Idx>(std::tie(inserted, position, node)));
+	  static_assert(_Idx < 3);
+	  if constexpr (_Idx == 0)
+	    return std::move(inserted);
+	  else if constexpr (_Idx == 1)
+	    return std::move(position);
+	  else if constexpr (_Idx == 2)
+	    return std::move(node);
 	}
 
       template<size_t _Idx>
 	decltype(auto) get() const &&
 	{
-	  return std::move(std::get<_Idx>(std::tie(inserted, position, node)));
+	  static_assert(_Idx < 3);
+	  if constexpr (_Idx == 0)
+	    return std::move(inserted);
+	  else if constexpr (_Idx == 1)
+	    return std::move(position);
+	  else if constexpr (_Idx == 2)
+	    return std::move(node);
 	}
     };
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Simplify _Node_insert_return to avoid including <tuple>
  2017-10-27 18:04 [PATCH] Simplify _Node_insert_return to avoid including <tuple> Jonathan Wakely
@ 2017-11-02 22:00 ` Tim Song
  2017-11-03  9:29   ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Song @ 2017-11-02 22:00 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

Um, why are those member get's there at all (and with an index mapping
that doesn't agree with the member order)? [container.insert.return]
says that "It has no base classes or members other than those
specified."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Simplify _Node_insert_return to avoid including <tuple>
  2017-11-02 22:00 ` Tim Song
@ 2017-11-03  9:29   ` Jonathan Wakely
  2017-11-03 11:06     ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2017-11-03  9:29 UTC (permalink / raw)
  To: Tim Song; +Cc: libstdc++, gcc-patches

On 02/11/17 18:00 -0400, Tim Song wrote:
>Um, why are those member get's there at all (and with an index mapping
>that doesn't agree with the member order)? [container.insert.return]
>says that "It has no base classes or members other than those
>specified."

Because I forgot to implement https://wg21.link/p0508r0 which changed
the spec, including the order of the members.

I'll do that shortly, thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Simplify _Node_insert_return to avoid including <tuple>
  2017-11-03  9:29   ` Jonathan Wakely
@ 2017-11-03 11:06     ` Jonathan Wakely
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2017-11-03 11:06 UTC (permalink / raw)
  To: Tim Song; +Cc: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 537 bytes --]

On 03/11/17 09:29 +0000, Jonathan Wakely wrote:
>On 02/11/17 18:00 -0400, Tim Song wrote:
>>Um, why are those member get's there at all (and with an index mapping
>>that doesn't agree with the member order)? [container.insert.return]
>>says that "It has no base classes or members other than those
>>specified."
>
>Because I forgot to implement https://wg21.link/p0508r0 which changed
>the spec, including the order of the members.
>
>I'll do that shortly, thanks.
>

Fixed by this patch, tested powerpc64le-linux, committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1827 bytes --]

commit a13d8a5a5620bbcc44ac6d6a1065e9c5d425b629
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Nov 3 09:48:59 2017 +0000

    Remove _Node_insert_return::get() member functions (P0508R0)
    
            * include/bits/node_handle.h (_Node_insert_return::get): Remove, as
            per P0508R0.

diff --git a/libstdc++-v3/include/bits/node_handle.h b/libstdc++-v3/include/bits/node_handle.h
index f93bfd7f686..4a830630c89 100644
--- a/libstdc++-v3/include/bits/node_handle.h
+++ b/libstdc++-v3/include/bits/node_handle.h
@@ -282,54 +282,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _Iterator		position = _Iterator();
       bool		inserted = false;
       _NodeHandle	node;
-
-      template<size_t _Idx>
-	decltype(auto) get() &
-	{
-	  static_assert(_Idx < 3);
-	  if constexpr (_Idx == 0)
-	    return inserted;
-	  else if constexpr (_Idx == 1)
-	    return position;
-	  else if constexpr (_Idx == 2)
-	    return node;
-	}
-
-      template<size_t _Idx>
-	decltype(auto) get() const &
-	{
-	  static_assert(_Idx < 3);
-	  if constexpr (_Idx == 0)
-	    return inserted;
-	  else if constexpr (_Idx == 1)
-	    return position;
-	  else if constexpr (_Idx == 2)
-	    return node;
-	}
-
-      template<size_t _Idx>
-	decltype(auto) get() &&
-	{
-	  static_assert(_Idx < 3);
-	  if constexpr (_Idx == 0)
-	    return std::move(inserted);
-	  else if constexpr (_Idx == 1)
-	    return std::move(position);
-	  else if constexpr (_Idx == 2)
-	    return std::move(node);
-	}
-
-      template<size_t _Idx>
-	decltype(auto) get() const &&
-	{
-	  static_assert(_Idx < 3);
-	  if constexpr (_Idx == 0)
-	    return std::move(inserted);
-	  else if constexpr (_Idx == 1)
-	    return std::move(position);
-	  else if constexpr (_Idx == 2)
-	    return std::move(node);
-	}
     };
 
 _GLIBCXX_END_NAMESPACE_VERSION

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-03 11:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-27 18:04 [PATCH] Simplify _Node_insert_return to avoid including <tuple> Jonathan Wakely
2017-11-02 22:00 ` Tim Song
2017-11-03  9:29   ` Jonathan Wakely
2017-11-03 11:06     ` Jonathan Wakely

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).