Fix order and types of members in C++17 insert_return_type structs
authorJonathan Wakely <jwakely@redhat.com>
Mon, 15 May 2017 13:47:40 +0000 (14:47 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 15 May 2017 13:47:40 +0000 (14:47 +0100)
PR libstdc++/80761
* include/bits/node_handle.h (_Node_insert_return): Reorder members.
(tuple_size, tuple_element): Remove partial specializations.
* include/bits/stl_tree.h (_Rb_tree::insert_return_type): Use
const_iterator for std::set.
* testsuite/23_containers/map/modifiers/extract.cc: New.
* testsuite/23_containers/set/modifiers/extract.cc: New.
* testsuite/23_containers/unordered_map/modifiers/extract.cc: New.
* testsuite/23_containers/unordered_set/modifiers/extract.cc: New.

From-SVN: r248062

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/node_handle.h
libstdc++-v3/include/bits/stl_tree.h
libstdc++-v3/testsuite/23_containers/map/modifiers/extract.cc
libstdc++-v3/testsuite/23_containers/set/modifiers/extract.cc
libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/extract.cc
libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/extract.cc

index 8664e8cd52560a2665e4248d21fd301e7d100627..4c6ca4b36beafe646cf3be8090e8514455f1fe58 100644 (file)
@@ -1,3 +1,15 @@
+2017-05-15  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/80761
+       * include/bits/node_handle.h (_Node_insert_return): Reorder members.
+       (tuple_size, tuple_element): Remove partial specializations.
+       * include/bits/stl_tree.h (_Rb_tree::insert_return_type): Use
+       const_iterator for std::set.
+       * testsuite/23_containers/map/modifiers/extract.cc: New.
+       * testsuite/23_containers/set/modifiers/extract.cc: New.
+       * testsuite/23_containers/unordered_map/modifiers/extract.cc: New.
+       * testsuite/23_containers/unordered_set/modifiers/extract.cc: New.
+
 2017-05-12  Jonathan Wakely  <jwakely@redhat.com>
 
        PR libstdc++/78939
index 44a92644cd595df73009d22e4108e741dfa407fc..c7694a1e0ef70e5f84ed4380bcba96273d8634bf 100644 (file)
@@ -280,8 +280,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Iterator, typename _NodeHandle>
     struct _Node_insert_return
     {
-      bool             inserted = false;
       _Iterator                position = _Iterator();
+      bool             inserted = false;
       _NodeHandle      node;
 
       template<size_t _Idx>
@@ -305,22 +305,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        }
     };
 
-  template<typename _Iterator, typename _NodeHandle>
-    struct tuple_size<_Node_insert_return<_Iterator, _NodeHandle>>
-    : integral_constant<size_t, 3> { };
-
-  template<typename _Iterator, typename _NodeHandle>
-    struct tuple_element<0, _Node_insert_return<_Iterator, _NodeHandle>>
-    { using type = bool; };
-
-  template<typename _Iterator, typename _NodeHandle>
-    struct tuple_element<1, _Node_insert_return<_Iterator, _NodeHandle>>
-    { using type = _Iterator; };
-
-  template<typename _Iterator, typename _NodeHandle>
-    struct tuple_element<2, _Node_insert_return<_Iterator, _NodeHandle>>
-    { using type = _NodeHandle; };
-
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
index aedee06be765956f544e81c52774151e1a73f989..3f133b0dad0912ed96e564dee019b2db54d5e605 100644 (file)
@@ -812,7 +812,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus > 201402L
       using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
-      using insert_return_type = _Node_insert_return<iterator, node_type>;
+      using insert_return_type = _Node_insert_return<
+       conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
+       node_type>;
 #endif
 
       pair<_Base_ptr, _Base_ptr>
index 507a708eed8e74fb8cc010877c1097c322e0dfdd..80eaf018a70bd384ae63b928214ba7eb25fa6b21 100644 (file)
@@ -135,6 +135,17 @@ test03()
   static_assert( is_same_v<test_type::node_type, compat_type3::node_type> );
 }
 
+void
+test04()
+{
+  // Check order of members in insert_return_type
+  auto [pos, ins, node] = test_type::insert_return_type{};
+  using std::is_same_v;
+  static_assert( is_same_v<test_type::iterator, decltype(pos)> );
+  static_assert( is_same_v<bool, decltype(ins)> );
+  static_assert( is_same_v<test_type::node_type, decltype(node)> );
+}
+
 int
 main()
 {
index c56767a9a3e185bec9a7c601871d3fc68c88e4bf..3fbc6b9a798baabd998c076d574a5a34985e372e 100644 (file)
@@ -126,6 +126,17 @@ test03()
   static_assert( is_same_v<test_type::node_type, compat_type3::node_type> );
 }
 
+void
+test04()
+{
+  // Check order of members in insert_return_type
+  auto [pos, ins, node] = test_type::insert_return_type{};
+  using std::is_same_v;
+  static_assert( is_same_v<test_type::iterator, decltype(pos)> );
+  static_assert( is_same_v<bool, decltype(ins)> );
+  static_assert( is_same_v<test_type::node_type, decltype(node)> );
+}
+
 int
 main()
 {
index ad87c7096b8ec5187ea85760c0dc5d167d080c9a..ce50766b4968078aa41e7bd3502c8bdb80d85eee 100644 (file)
@@ -136,6 +136,17 @@ test03()
   static_assert( is_same_v<test_type::node_type, compat_type3::node_type> );
 }
 
+void
+test04()
+{
+  // Check order of members in insert_return_type
+  auto [pos, ins, node] = test_type::insert_return_type{};
+  using std::is_same_v;
+  static_assert( is_same_v<test_type::iterator, decltype(pos)> );
+  static_assert( is_same_v<bool, decltype(ins)> );
+  static_assert( is_same_v<test_type::node_type, decltype(node)> );
+}
+
 int
 main()
 {
index 6f77a94d321f4c3543b58ab57290a923405b00cb..5be81951407eeeb3dd5450f034c6cfac095124bc 100644 (file)
@@ -128,6 +128,17 @@ test03()
   static_assert( is_same_v<test_type::node_type, compat_type3::node_type> );
 }
 
+void
+test04()
+{
+  // Check order of members in insert_return_type
+  auto [pos, ins, node] = test_type::insert_return_type{};
+  using std::is_same_v;
+  static_assert( is_same_v<test_type::iterator, decltype(pos)> );
+  static_assert( is_same_v<bool, decltype(ins)> );
+  static_assert( is_same_v<test_type::node_type, decltype(node)> );
+}
+
 int
 main()
 {