[RFA 1/5] Remove some ui_out-related cleanups from Python

Trevor Saunders tbsaunde@tbsaunde.org
Mon Jan 16 11:19:00 GMT 2017


> +++ b/gdb/common/gdb_option.h

might be nice to put it in include/ but fine to do that later when
something else actually wants it.

> +/* This class attempts to be a compatible subset of std::optional,
> +   which is slated to be available in C++17.  This class optionally
> +   holds an object of some type -- by default it is constructed not
> +   holding an object, but later the object can be "emplaced".  This is
> +   similar to using std::unique_ptr, but stack allocation is
> +   guaranteed.  */

 wording nit, but stack isn't quiet what you want there, I can imagine
 putting an optional<T> in some object that lives on the heap.

> +template<typename T>
> +class optional
> +{
> +public:
> +
> +  optional ()
> +    : m_instantiated (false)
> +  {
> +  }
> +
> +  ~optional ()
> +  {
> +    if (m_instantiated)
> +      destroy ();
> +  }
> +
> +  /* These aren't deleted in std::optional, but it was simpler to
> +     delete them here, because currently the users of this class don't
> +     need them, and making them depend on the definition of T is
> +     somewhat complicated.  */

I think you can make <type_traits> do most of it, but fair enough.

> +  /* True if the object was ever emplaced.  */
> +  bool m_instantiated;
> +
> +  /* The object.  */
> +  union
> +  {
> +    struct { } m_dummy;
> +    T m_item;
> +  };

It doesn't matter yet, but space wise it would be better to put the bool
last right? For example if sizeof(T) is 6, or if the optional is in some
larger structure with a bool next.

Trev



More information about the Gdb-patches mailing list