* [review] Introduce basic_safe_range
@ 2019-11-04 1:35 Tom Tromey (Code Review)
2019-12-12 23:50 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
0 siblings, 2 replies; 3+ messages in thread
From: Tom Tromey (Code Review) @ 2019-11-04 1:35 UTC (permalink / raw)
To: gdb-patches
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/498
......................................................................
Introduce basic_safe_range
This introduces the basic_safe_range class, which can be used to
create a basic_safe_iterator. This also changes basic_safe_iterator
in two ways.
First, it simplifies the constructor. This seemed unnecessarily
complicated to me, and keeping it this way would prevent the second
change...
... which is to add a second constructor for initializing the
one-past-the-end iterator that is stored in basic_safe_iterator.
2019-11-03 Tom Tromey <tom@tromey.com>
* gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify. Add
second constructor.
(basic_safe_range): New class.
Change-Id: Ib351ef6fd435129a5053c64e5561877e1459ab37
---
M gdb/ChangeLog
M gdb/gdbsupport/safe-iterator.h
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 94bbb25..6a3afe3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2019-11-03 Tom Tromey <tom@tromey.com>
+ * gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify. Add
+ second constructor.
+ (basic_safe_range): New class.
+
+2019-11-03 Tom Tromey <tom@tromey.com>
+
* progspace.c (program_space::multi_objfile_p): New method.
* printcmd.c (info_symbol_command): Update.
* maint.c (maintenance_translate_address): Update.
diff --git a/gdb/gdbsupport/safe-iterator.h b/gdb/gdbsupport/safe-iterator.h
index 89aec01..1a98b42 100644
--- a/gdb/gdbsupport/safe-iterator.h
+++ b/gdb/gdbsupport/safe-iterator.h
@@ -48,17 +48,29 @@
typedef typename Iterator::iterator_category iterator_category;
typedef typename Iterator::difference_type difference_type;
- /* Construct by forwarding all arguments to the underlying
- iterator. */
- template<typename... Args>
- explicit basic_safe_iterator (Args &&...args)
- : m_it (std::forward<Args> (args)...),
+ /* Construct using the given argument; the end iterator is default
+ constructed. */
+ template<typename Arg>
+ explicit basic_safe_iterator (Arg &&arg)
+ : m_it (std::forward<Arg> (arg)),
m_next (m_it)
{
if (m_it != m_end)
++m_next;
}
+ /* Construct the iterator using the first argument, and construct
+ the end iterator using the second argument. */
+ template<typename Arg>
+ explicit basic_safe_iterator (Arg &&arg, Arg &&arg2)
+ : m_it (std::forward<Arg> (arg)),
+ m_next (m_it),
+ m_end (std::forward<Arg> (arg2))
+ {
+ if (m_it != m_end)
+ ++m_next;
+ }
+
/* Create a one-past-end iterator. */
basic_safe_iterator ()
{}
@@ -90,4 +102,34 @@
Iterator m_end {};
};
+/* A range adapter that wraps another range, and then returns safe
+ iterators wrapping the original range's iterators. */
+
+template<typename Range>
+class basic_safe_range
+{
+public:
+
+ typedef basic_safe_iterator<typename Range::iterator> iterator;
+
+ explicit basic_safe_range (Range range)
+ : m_range (range)
+ {
+ }
+
+ iterator begin () const
+ {
+ return iterator (m_range.begin (), m_range.end ());
+ }
+
+ iterator end () const
+ {
+ return iterator (m_range.end (), m_range.end ());
+ }
+
+private:
+
+ Range m_range;
+};
+
#endif /* COMMON_SAFE_ITERATOR_H */
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib351ef6fd435129a5053c64e5561877e1459ab37
Gerrit-Change-Number: 498
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newchange
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pushed] Introduce basic_safe_range
2019-11-04 1:35 [review] Introduce basic_safe_range Tom Tromey (Code Review)
2019-12-12 23:50 ` [pushed] " Sourceware to Gerrit sync (Code Review)
@ 2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
1 sibling, 0 replies; 3+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-12 23:50 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
The original change was created by Tom Tromey.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/498
......................................................................
Introduce basic_safe_range
This introduces the basic_safe_range class, which can be used to
create a basic_safe_iterator. This also changes basic_safe_iterator
in two ways.
First, it simplifies the constructor. This seemed unnecessarily
complicated to me, and keeping it this way would prevent the second
change...
... which is to add a second constructor for initializing the
one-past-the-end iterator that is stored in basic_safe_iterator.
gdb/ChangeLog
2019-12-12 Tom Tromey <tom@tromey.com>
* gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify. Add
second constructor.
(basic_safe_range): New class.
Change-Id: Ib351ef6fd435129a5053c64e5561877e1459ab37
---
M gdb/ChangeLog
M gdb/gdbsupport/safe-iterator.h
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 26f764e..368d7f0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2019-12-12 Tom Tromey <tom@tromey.com>
+ * gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify. Add
+ second constructor.
+ (basic_safe_range): New class.
+
+2019-12-12 Tom Tromey <tom@tromey.com>
+
* progspace.c (program_space::multi_objfile_p): New method.
* printcmd.c (info_symbol_command): Update.
* maint.c (maintenance_translate_address): Update.
diff --git a/gdb/gdbsupport/safe-iterator.h b/gdb/gdbsupport/safe-iterator.h
index 89aec01..1a98b42 100644
--- a/gdb/gdbsupport/safe-iterator.h
+++ b/gdb/gdbsupport/safe-iterator.h
@@ -48,17 +48,29 @@
typedef typename Iterator::iterator_category iterator_category;
typedef typename Iterator::difference_type difference_type;
- /* Construct by forwarding all arguments to the underlying
- iterator. */
- template<typename... Args>
- explicit basic_safe_iterator (Args &&...args)
- : m_it (std::forward<Args> (args)...),
+ /* Construct using the given argument; the end iterator is default
+ constructed. */
+ template<typename Arg>
+ explicit basic_safe_iterator (Arg &&arg)
+ : m_it (std::forward<Arg> (arg)),
m_next (m_it)
{
if (m_it != m_end)
++m_next;
}
+ /* Construct the iterator using the first argument, and construct
+ the end iterator using the second argument. */
+ template<typename Arg>
+ explicit basic_safe_iterator (Arg &&arg, Arg &&arg2)
+ : m_it (std::forward<Arg> (arg)),
+ m_next (m_it),
+ m_end (std::forward<Arg> (arg2))
+ {
+ if (m_it != m_end)
+ ++m_next;
+ }
+
/* Create a one-past-end iterator. */
basic_safe_iterator ()
{}
@@ -90,4 +102,34 @@
Iterator m_end {};
};
+/* A range adapter that wraps another range, and then returns safe
+ iterators wrapping the original range's iterators. */
+
+template<typename Range>
+class basic_safe_range
+{
+public:
+
+ typedef basic_safe_iterator<typename Range::iterator> iterator;
+
+ explicit basic_safe_range (Range range)
+ : m_range (range)
+ {
+ }
+
+ iterator begin () const
+ {
+ return iterator (m_range.begin (), m_range.end ());
+ }
+
+ iterator end () const
+ {
+ return iterator (m_range.end (), m_range.end ());
+ }
+
+private:
+
+ Range m_range;
+};
+
#endif /* COMMON_SAFE_ITERATOR_H */
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib351ef6fd435129a5053c64e5561877e1459ab37
Gerrit-Change-Number: 498
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newpatchset
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pushed] Introduce basic_safe_range
2019-11-04 1:35 [review] Introduce basic_safe_range Tom Tromey (Code Review)
@ 2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
1 sibling, 0 replies; 3+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-12 23:50 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
Sourceware to Gerrit sync has submitted this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/498
......................................................................
Introduce basic_safe_range
This introduces the basic_safe_range class, which can be used to
create a basic_safe_iterator. This also changes basic_safe_iterator
in two ways.
First, it simplifies the constructor. This seemed unnecessarily
complicated to me, and keeping it this way would prevent the second
change...
... which is to add a second constructor for initializing the
one-past-the-end iterator that is stored in basic_safe_iterator.
gdb/ChangeLog
2019-12-12 Tom Tromey <tom@tromey.com>
* gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify. Add
second constructor.
(basic_safe_range): New class.
Change-Id: Ib351ef6fd435129a5053c64e5561877e1459ab37
---
M gdb/ChangeLog
M gdb/gdbsupport/safe-iterator.h
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 26f764e..368d7f0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2019-12-12 Tom Tromey <tom@tromey.com>
+ * gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify. Add
+ second constructor.
+ (basic_safe_range): New class.
+
+2019-12-12 Tom Tromey <tom@tromey.com>
+
* progspace.c (program_space::multi_objfile_p): New method.
* printcmd.c (info_symbol_command): Update.
* maint.c (maintenance_translate_address): Update.
diff --git a/gdb/gdbsupport/safe-iterator.h b/gdb/gdbsupport/safe-iterator.h
index 89aec01..1a98b42 100644
--- a/gdb/gdbsupport/safe-iterator.h
+++ b/gdb/gdbsupport/safe-iterator.h
@@ -48,17 +48,29 @@
typedef typename Iterator::iterator_category iterator_category;
typedef typename Iterator::difference_type difference_type;
- /* Construct by forwarding all arguments to the underlying
- iterator. */
- template<typename... Args>
- explicit basic_safe_iterator (Args &&...args)
- : m_it (std::forward<Args> (args)...),
+ /* Construct using the given argument; the end iterator is default
+ constructed. */
+ template<typename Arg>
+ explicit basic_safe_iterator (Arg &&arg)
+ : m_it (std::forward<Arg> (arg)),
m_next (m_it)
{
if (m_it != m_end)
++m_next;
}
+ /* Construct the iterator using the first argument, and construct
+ the end iterator using the second argument. */
+ template<typename Arg>
+ explicit basic_safe_iterator (Arg &&arg, Arg &&arg2)
+ : m_it (std::forward<Arg> (arg)),
+ m_next (m_it),
+ m_end (std::forward<Arg> (arg2))
+ {
+ if (m_it != m_end)
+ ++m_next;
+ }
+
/* Create a one-past-end iterator. */
basic_safe_iterator ()
{}
@@ -90,4 +102,34 @@
Iterator m_end {};
};
+/* A range adapter that wraps another range, and then returns safe
+ iterators wrapping the original range's iterators. */
+
+template<typename Range>
+class basic_safe_range
+{
+public:
+
+ typedef basic_safe_iterator<typename Range::iterator> iterator;
+
+ explicit basic_safe_range (Range range)
+ : m_range (range)
+ {
+ }
+
+ iterator begin () const
+ {
+ return iterator (m_range.begin (), m_range.end ());
+ }
+
+ iterator end () const
+ {
+ return iterator (m_range.end (), m_range.end ());
+ }
+
+private:
+
+ Range m_range;
+};
+
#endif /* COMMON_SAFE_ITERATOR_H */
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib351ef6fd435129a5053c64e5561877e1459ab37
Gerrit-Change-Number: 498
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: merged
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-12 23:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 1:35 [review] Introduce basic_safe_range Tom Tromey (Code Review)
2019-12-12 23:50 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
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).