From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QU28ENm96Wn9QDUAWB0awg (envelope-from ) for ; Thu, 23 Apr 2026 02:36:09 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ktIFkWC3; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=tZu4ulJF; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=nKwohF0c; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AycIR4Qr; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3B8F81E067; Thu, 23 Apr 2026 02:36:09 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 73A591E067 for ; Thu, 23 Apr 2026 02:36:07 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id BFF234BBCDAF for ; Thu, 23 Apr 2026 06:36:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFF234BBCDAF Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ktIFkWC3; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=tZu4ulJF; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=nKwohF0c; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AycIR4Qr Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id AA7A44BBC0C4 for ; Thu, 23 Apr 2026 06:35:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA7A44BBC0C4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AA7A44BBC0C4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776926134; cv=none; b=k+CUqC2iAH+cnZQWVhIpk8EYjWcdR+g1YG7XyT4r/XdM9N0Cmlc1useeZ82/vXnDKuhn9lK35HyBEDgX2e+Tg4pqu8LPLxtzXB62bQCIOeZ90rgUBr76iggTMqXO2Qlg3k0sUhXcqUDm0dKyye6d39eDwUL1I5ecRs8J6XkTdhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776926134; c=relaxed/simple; bh=6Mj1MwoiFGN8ftWc45YFVbLpgjE7gNw3Lzyy2i91ZAY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=qInmUqttqXPSFqVOP1OK7eZSbiD3ZYXJ2qee/RUsHeZdP7aFLtGv5u9ozIg30ux5I8BCN+dY9xid0MTmTas5g28ZAy//v96AuKcBZWaaI75Ei+isvD42TbOP46/5kqyUkyEE1Xvs/X2Qx/J0avmLCqD+OVQAXjrH1mzZl+W8NfE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA7A44BBC0C4 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CB0886A823 for ; Thu, 23 Apr 2026 06:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776926132; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YngYEX8jLEAwxoQFbu+GdmmdtcDeRRbIOLJWUTcxcIE=; b=ktIFkWC32DO7JNX0judJf7/3z1ADuo0KYql3c0aZxsL6v29bvV5GvnxVOi9SQRP3RjQpAx QujO4Jm/Ly4MAGV+HR5x7dSdWius5BT9DW9J8PU0R/BXQZjaBoE13mLa/ryVDGk3iUkXpy ozXsr8aGnDBlrdeao1oJrx8toAs+Jt0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776926132; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YngYEX8jLEAwxoQFbu+GdmmdtcDeRRbIOLJWUTcxcIE=; b=tZu4ulJFwwZ7J/PQAL5NP635fEGzXp3itOGiqWzCGLYIIcoCUGjXPC9iNe9pQFqNv7IOjr N+XBRri3XJQyYSCw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776926131; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YngYEX8jLEAwxoQFbu+GdmmdtcDeRRbIOLJWUTcxcIE=; b=nKwohF0ccy11t4y8r4z7x7JB7BtgYmUKks9aM6gCtF2xXVLmsnvJZvbSqSR2LEp/FDhnAu U8eoKvHK1FTJAI8FF0/zvKmT+LpMwX9hgTXgW0VKskJ0paTsgEkGAw5ft6fjKD9LulX5BW MwW/GqkQqqF8A9teEqk4Mxe6VLub3a4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776926131; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YngYEX8jLEAwxoQFbu+GdmmdtcDeRRbIOLJWUTcxcIE=; b=AycIR4Qr9hyUTxQMl2jeCYV5WfeLSwKuvL5qafsQTK4VfqnDrnnaQKItNAn+XghVu+Uh6f AsytBzwdpubGMQAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B18CA593B2 for ; Thu, 23 Apr 2026 06:35:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id OP5jKbO96WnpAgAAD6G6ig (envelope-from ) for ; Thu, 23 Apr 2026 06:35:31 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 3/7] [gdbsupport] Factor out base_next_iterator Date: Thu, 23 Apr 2026 08:35:26 +0200 Message-ID: <20260423063530.1074175-4-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260423063530.1074175-1-tdevries@suse.de> References: <20260423063530.1074175-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Template struct next_iterator allows iterating over the "next" field of T. I decided to generalize this to be able to use any field. A first thought was to use macros, but nowadays we try to do things more in native c++, so I didn't explore that further. Instead, this patch factors out base_next_iterator, which contains all parts not specific to "next", in other words, everything except the operator++. Finally, I explored using a pointer-to-member template argument T::next, but that meant that using an incomplete T was no longer allowed, so it's not a drop-in replacement. I also didn't explore this option further, and made a note of it in the base_next_iterator comment. --- gdbsupport/next-iterator.h | 59 ++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/gdbsupport/next-iterator.h b/gdbsupport/next-iterator.h index 0c90428d349..1dee941a252 100644 --- a/gdbsupport/next-iterator.h +++ b/gdbsupport/next-iterator.h @@ -21,27 +21,43 @@ #include "gdbsupport/iterator-range.h" -/* An iterator that uses the 'next' field of a type to iterate. This - can be used with various GDB types that are stored as linked - lists. */ +/* An iterator base class for iterating over a field of a type. In order to + form a functioning iterator, classes inheriting this should define an + operator++, which determines the actual field that is iterated over. + + Instead of factoring out a base class, we could use something like this: + + template + struct next_iterator + { + ... + self_type &operator++ () + { + m_item = m_item->*F; + return *this; + } + ... + } + + but that has the drawback that it doesn't work with incomplete T. */ template -struct next_iterator +struct base_next_iterator { - typedef next_iterator self_type; + typedef base_next_iterator self_type; typedef T *value_type; typedef T *&reference; typedef T **pointer; typedef std::forward_iterator_tag iterator_category; typedef int difference_type; - explicit next_iterator (T *item) + explicit base_next_iterator (T *item) : m_item (item) { } /* Create a one-past-the-end iterator. */ - next_iterator () + base_next_iterator () : m_item (nullptr) { } @@ -61,15 +77,34 @@ struct next_iterator return m_item != other.m_item; } - self_type &operator++ () +protected: + + T *m_item; +}; + +/* An iterator that uses the 'next' field of a type to iterate. This + can be used with various GDB types that are stored as linked + lists. */ + +template +struct next_iterator : base_next_iterator { + typedef next_iterator self_type; + typedef T *value_type; + typedef T *&reference; + typedef T **pointer; + + explicit next_iterator (T *item) + : base_next_iterator (item) { - m_item = m_item->next; - return *this; } -private: + next_iterator () = default; - T *m_item; + self_type &operator++ () + { + this->m_item = this->m_item->next; + return *this; + } }; /* A convenience wrapper to make a range type around a next_iterator. */ -- 2.51.0