gdb::optional: Add observers
[deliverable/binutils-gdb.git] / gdb / common / gdb_optional.h
index d991da123cf0ee088ba9f10cfca78d5891a23451..fef7a73e02a6ecfb1f37d0e71a43944cbb29c7b6 100644 (file)
@@ -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
   {
This page took 0.05101 seconds and 4 git commands to generate.