From patchwork Wed Jun 20 05:34:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 931958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 419YS80tsJz9s4w for ; Wed, 20 Jun 2018 15:34:48 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 419YS76qrczF0wb for ; Wed, 20 Jun 2018 15:34:47 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 419YRb0JdHzF0wq for ; Wed, 20 Jun 2018 15:34:19 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 419YRZ3dwRz9s7c; Wed, 20 Jun 2018 15:34:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 20 Jun 2018 15:34:05 +1000 Message-Id: <20180620053409.14538-5-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180620053409.14538-1-alistair@popple.id.au> References: <20180620053409.14538-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 4/8] ccan/cppmaigc: Add CPPMAGIC_MAP_CNT(...) macro X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" It can be useful to have a count to keep track of which argument number in the list is being expanded. Signed-off-by: Alistair Popple --- ccan/cppmagic/cppmagic.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ccan/cppmagic/cppmagic.h b/ccan/cppmagic/cppmagic.h index ffd5848..4cfb892 100644 --- a/ccan/cppmagic/cppmagic.h +++ b/ccan/cppmagic/cppmagic.h @@ -177,6 +177,25 @@ () /** + * CPPMAGIC_MAP_CNT - iterate antoher macro across arguments adding a count + * @m: name of a two argument macro + * + * CPPMAGIC_MAP_CNT(@m, @a1, @a2, ..., @an) + * expands to the expansion of + * @m(0, @a1) , @m(1, @a2) , ... , @m(n - 1, @an) + */ +#define _CPPMAGIC_MAP_CNT_() _CPPMAGIC_MAP_CNT +#define _CPPMAGIC_MAP_CNT(m_, c_, a_, ...) \ + m_(c_, a_) \ + CPPMAGIC_IFELSE(CPPMAGIC_NONEMPTY(__VA_ARGS__)) \ + (, CPPMAGIC_DEFER2(_CPPMAGIC_MAP_CNT_)()(m_, CPPMAGIC_INC(c_), __VA_ARGS__)) \ + () +#define CPPMAGIC_MAP_CNT(m_, ...) \ + CPPMAGIC_IFELSE(CPPMAGIC_NONEMPTY(__VA_ARGS__)) \ + (CPPMAGIC_EVAL(_CPPMAGIC_MAP_CNT(m_, 0, __VA_ARGS__))) \ + () + +/** * CPPMAGIC_JOIN - separate arguments with given delimiter * @d: delimiter *