From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59858 invoked by alias); 1 Oct 2016 11:47:26 -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 59838 invoked by uid 89); 1 Oct 2016 11:47:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=cleanups, U*simon.marchi, simonmarchipolymtlca, Marchi X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 01 Oct 2016 11:47:15 +0000 Received: by simark.ca (Postfix, from userid 112) id E19491E130; Sat, 1 Oct 2016 07:47:13 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 1F5421E107; Sat, 1 Oct 2016 07:47:13 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 01 Oct 2016 11:47:00 -0000 From: Simon Marchi To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 03/22] Use scoped_restore for ui_file In-Reply-To: <87bmz4fxtt.fsf@tromey.com> References: <1474949330-4307-1-git-send-email-tom@tromey.com> <1474949330-4307-4-git-send-email-tom@tromey.com> <7417a71f254c7f42026408c5e143b374@simark.ca> <87bmz4fxtt.fsf@tromey.com> Message-ID: <1bbab702396db2da51e21ad0b6f1937a@simark.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.0 X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00008.txt.bz2 On 2016-10-01 01:22, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi writes: > > Simon> shared_ptr< scoped_restore > save_file; > > Why shared_ptr and not unique_ptr? Right, I am not used yet to think about their differences, and which one applies to a particular situation. unique_ptr is clearler a better choice. > Simon> We can't use std::shared_ptr, since it's only in c++11, but I > think > Simon> it's just a matter of time before we define our own version of > it. > > ... Pedro's branch has unique_ptr :) Oh, right! > Simon> An alternative would be to have a default constructor for > Simon> scoped_restore, that creates an inactive scoped_restore, and > then > Simon> assign it a variable to restore later with acquire(T* > var)/acquire(T* > Simon> var, T value) methods or something. I am not sure which one is > Simon> better. > > FWIW Mozilla uses an Option class for this kind of thing. > It works like: > > Option< scoped_restore > save_file; > if (mumble) { > save_file.emplace (make_scoped_restore (&var)); > } > > The main advantage of this over *_ptr is that Option contains the > object, so no heap allocations are required. That sounds good, it ends up with the same behavior, but implemented better. > Simon> To support some use cases where discard_cleanups is used, we > might > Simon> need a way to "release" the scoped_restore, which would > essentially > Simon> cancel it. So if we have a "release" method, maybe having the > Simon> symmetrical "acquire" would make sense. > > Simon> What do you think? > > It seems sensible to me. > > One idea to consider is whether it's better to have a separate > "discardable" variant of scoped_restore (or whatever else); the idea > being that then the type name serves as a signal to look more closely > at > the logic. I think most spots don't need discardable cleanups. Yep, alsop sounds good.