From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by sourceware.org (Postfix) with ESMTPS id 6D26C385781D for ; Mon, 5 Jul 2021 15:41:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D26C385781D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f50.google.com with SMTP id t15so19232268wry.11 for ; Mon, 05 Jul 2021 08:41:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=hqeiTTXr714nNnRhT3cDxraFPbj1qP6IDPM4Pq1ni14=; b=jVOyZTdqRCnLnzjO6n+TzhXKu0DJLblx1s70uTckYbCs3QWuhzsENGgZPXzWKYndjT XAD91KIRJEhvcAdBmKXjya/ZolPY+NF9oB9jbxCKROnMUfV7ewMGXm6jac7AcaPEQ6Qc EQ4lNTm1p9ZsCfzKd27mEKCuboeBQuM3onDvzseS3qbLR0iVT0uq0FaaWE4Z+Ig3gYyt hWL7clkDo9elwrki7Q/sxXU/NRwOAuBFrcDKRnhRPl7sMZBh+PoowOIxOtTZsjwJKKBi AEchHFimCcn75tYXGFGdP31WNgDUDJTrVJepe7Fgqt9FaOGJiQCXFGOJPX0IEh13GBbs vByg== X-Gm-Message-State: AOAM531EwTARhG+DM6qFwBRtl0jGw0hc4Q27NNKxqnKUKfwga2c2+ejL Q7lODSp2qQ85ksHwC2L3KFlBlG+6vBwxlw== X-Google-Smtp-Source: ABdhPJxk2/GMZ5doxvzn+K/X7XizuLEvMaS6AYr8mWGjyEUx62LPCe22GwAq13P2JznKO8DNHzn4lA== X-Received: by 2002:adf:f949:: with SMTP id q9mr5720889wrr.178.1625499706965; Mon, 05 Jul 2021 08:41:46 -0700 (PDT) Received: from ?IPv6:2001:8a0:f932:6a00:46bc:d03b:7b3a:2227? ([2001:8a0:f932:6a00:46bc:d03b:7b3a:2227]) by smtp.gmail.com with ESMTPSA id i11sm24400358wmg.18.2021.07.05.08.41.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Jul 2021 08:41:46 -0700 (PDT) Subject: Re: [PATCH 01/11] gdb: introduce iterator_range, remove next_adapter From: Pedro Alves To: Simon Marchi , gdb-patches@sourceware.org References: <20210622165704.2404007-1-simon.marchi@polymtl.ca> <20210622165704.2404007-2-simon.marchi@polymtl.ca> Message-ID: <95009c05-bc89-6ad1-682d-b3b5c07d0f45@palves.net> Date: Mon, 5 Jul 2021 16:41:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210622165704.2404007-2-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jul 2021 15:41:49 -0000 On 2021-06-22 5:56 p.m., Simon Marchi via Gdb-patches wrote: > I was always a bit confused by next_adapter, because it kind of mixes > the element type and the iterator type. In reality, it is not much more > than a class that wraps two iterators (begin and end). However, it > assumes that: > > - you can construct the begin iterator by passing a pointer to the > first element of the iterable > - you can default-construct iterator to make the end iterator > > I think that by generalizing it a little bit, we can re-use it at more > places. > > Rename it to "iterator_range". I think it describes a bit better: it's > a range made by wrapping a begin and end iterator. Move it to its own > file, since it's not related to next_iterator anymore. > > iterator_range has two constructors. The variadic one, where arguments > are forwarded to construct the underlying begin iterator. The end > iterator is constructed through default construction. This is a > generalization of what we have today. > > There is another constructor which receives already constructed begin > and end iterators, useful if the end iterator can't be obtained by > default-construction. Or, if you wanted to make a range that does not > end at the end of the container, you could pass any iterator as the > "end". > > This generalization allows removing some "range" classes, like > all_inferiors_range. These classes existed only to pass some arguments > when constructing the begin iterator. With iterator_range, those same > arguments are passed to the iterator_range constructed and then > forwarded to the constructed begin iterator. > > There is a small functional difference in how iterator_range works > compared to next_adapter. next_adapter stored the pointer it received > as argument and constructeur an iterator in the `begin` method. > iterator_range constructs the begin iterator and stores it as a member. > Its `begin` method returns a copy of that iterator. > > With just iterator_range, uses of next_adapter would be replaced > with: > > using foo_iterator = next_iterator; > using foo_range = iterator_range; > > However, I added a `next_range` wrapper as a direct replacement for > next_adapter. IMO, next_range is a slightly better name than > next_adapter. > > The rest of the changes are applications of this new class. LGTM.