From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113390 invoked by alias); 16 Jan 2017 11:19:24 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 113366 invoked by uid 89); 16 Jan 2017 11:19:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1536, ui_out-related, gdb_option.h, ui_outrelated X-HELO: paperclip.tbsaunde.org Received: from tbsaunde.org (HELO paperclip.tbsaunde.org) (66.228.47.254) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jan 2017 11:19:20 +0000 Received: from ball (unknown [IPv6:2607:f0c8:8000:80e8:124a:7dff:fe34:eb17]) by paperclip.tbsaunde.org (Postfix) with ESMTPSA id 26E59C08E; Mon, 16 Jan 2017 11:19:19 +0000 (UTC) Date: Mon, 16 Jan 2017 11:19:00 -0000 From: Trevor Saunders To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 1/5] Remove some ui_out-related cleanups from Python Message-ID: <20170116113021.sar3yh5ivykpqmbw@ball> References: <20170115134253.24018-1-tom@tromey.com> <20170115134253.24018-2-tom@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170115134253.24018-2-tom@tromey.com> User-Agent: NeoMutt/20161126 (1.7.1) X-SW-Source: 2017-01/txt/msg00296.txt.bz2 > +++ 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 in some object that lives on the heap. > +template > +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 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