aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-04-04 20:03:25 +0100
committerPedro Alves <palves@redhat.com>2017-04-04 20:03:25 +0100
commitd194f1fe51cb85b8a919b7ee9e3a7715b0ec9744 (patch)
tree00c457bd60e59b73e5ea8b42d9de64b8505cbdf1 /gdb
parentfff8551cf549f4047c9276a836408d802db6ce6d (diff)
downloadgdb-d194f1fe51cb85b8a919b7ee9e3a7715b0ec9744.zip
gdb-d194f1fe51cb85b8a919b7ee9e3a7715b0ec9744.tar.gz
gdb-d194f1fe51cb85b8a919b7ee9e3a7715b0ec9744.tar.bz2
gdb::optional: Add observers
Currently, gdb::optional is really minimal and can only be used for lazy initialization. There's no way to get at the value contained inside the optinal. This commit corrects that, by adding observer methods, mostly copied from libstdc++'s implementation of C++17 std::optional. This will be used in the following patch. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * common/gdb_optional.h (gdb::optiona): Add operator->, operator*, operator bool, has_value and get methods.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/common/gdb_optional.h29
2 files changed, 34 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5e124c4..f2b64b9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2017-04-04 Pedro Alves <palves@redhat.com>
+ * common/gdb_optional.h (gdb::optiona): Add operator->, operator*,
+ operator bool, has_value and get methods.
+
+2017-04-04 Pedro Alves <palves@redhat.com>
+
* dwarf2read.c (struct file_entry): Add ctors, and initialize all
fields.
(line_header): Initialize all data fields. Change type of
diff --git a/gdb/common/gdb_optional.h b/gdb/common/gdb_optional.h
index d991da1..fef7a73 100644
--- a/gdb/common/gdb_optional.h
+++ b/gdb/common/gdb_optional.h
@@ -61,6 +61,31 @@ public:
m_instantiated = true;
}
+ /* Observers. */
+ constexpr const T *operator-> () const
+ { return std::addressof (this->get ()); }
+
+ T *operator-> ()
+ { return std::addressof (this->get ()); }
+
+ constexpr const T &operator* () const &
+ { return this->get (); }
+
+ T &operator* () &
+ { return this->get (); }
+
+ T &&operator* () &&
+ { return std::move (this->get ()); }
+
+ constexpr const T &&operator* () const &&
+ { return std::move (this->get ()); }
+
+ constexpr explicit operator bool () const noexcept
+ { return m_instantiated; }
+
+ constexpr bool has_value () const noexcept
+ { return m_instantiated; }
+
private:
/* Destroy the object. */
@@ -71,6 +96,10 @@ private:
m_item.~T ();
}
+ /* The get operations have m_instantiated as a precondition. */
+ T &get () noexcept { return m_item; }
+ constexpr const T &get () const noexcept { return m_item; }
+
/* The object. */
union
{