* [PATCH] Fix order and types of members in C++17 insert_return_type structs
@ 2017-05-15 14:02 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2017-05-15 14:02 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 971 bytes --]
Nico Josuttis pointed out that the members were in the wrong order. I
also found that set<T>::insert__return_type::position was using
_Rb_tree_iterator<T> not _Rb_tree_const_iterator<T> as it should have
been.
Finally, with complete structured bindings support in the FE we don't
need the tuple_size and tuple_element partial specializations that I
defined for the insert_return_type structs.
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.
Tested powerpc64le-linux, committed to trunk. Backport to gcc-7 to
follow.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 5860 bytes --]
commit 5ff45f6392071ed0fd7950f24147e2ada9bf058f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon May 15 12:17:51 2017 +0100
Fix order and types of members in C++17 insert_return_type structs
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.
diff --git a/libstdc++-v3/include/bits/node_handle.h b/libstdc++-v3/include/bits/node_handle.h
index 44a9264..c7694a1 100644
--- a/libstdc++-v3/include/bits/node_handle.h
+++ b/libstdc++-v3/include/bits/node_handle.h
@@ -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
diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h
index aedee06..3f133b0 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -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>
diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/extract.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/extract.cc
index 507a708..80eaf01 100644
--- a/libstdc++-v3/testsuite/23_containers/map/modifiers/extract.cc
+++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/extract.cc
@@ -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()
{
diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/extract.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/extract.cc
index c56767a..3fbc6b9 100644
--- a/libstdc++-v3/testsuite/23_containers/set/modifiers/extract.cc
+++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/extract.cc
@@ -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()
{
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/extract.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/extract.cc
index ad87c70..ce50766 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/extract.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/extract.cc
@@ -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()
{
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/extract.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/extract.cc
index 6f77a94..5be8195 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/extract.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/extract.cc
@@ -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()
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-05-15 13:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-15 14:02 [PATCH] Fix order and types of members in C++17 insert_return_type structs 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).