[PATCH] Simplify _Node_insert_return to avoid including <tuple>

Jonathan Wakely jwakely@redhat.com
Fri Oct 27 17:53:00 GMT 2017


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.

-------------- next part --------------
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);
 	}
     };
 


More information about the Libstdc++ mailing list