From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 6A16E3854806 for ; Fri, 17 Feb 2023 11:39:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A16E3854806 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x52a.google.com with SMTP id v11so11881176edx.12 for ; Fri, 17 Feb 2023 03:39:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nw0znHoYqFmlQHfmP9vGaug/4bQeFA2Ii5syqOZRM0w=; b=RsqMI1AMTpMB7FqLWRmorPHbwJN2D2ZaMxkXTB9wnbOh26e6/IFmBKTLVemkrIvKf0 gbVOZG9cKSs7Uccn9nyQowXlYOVdokrXmIX6DHmlVGRyuVwT0pnFvXyKTTxXGZPVoYLe Dolg+nTrx5VXi+O3rkn6i2Z5hYilZdX9t4xJVVx75zj6ULsHR5N1xsBNxoE7JpQVRGKG f61t5hnvfXDainXTIKduAvR/4vFl3/UTh/IBBDqxXth8Ln9prHPaY50X6aPocCVDjRfD fED0O9oG9rUmkl7G7ePDY/VsCOm1NYQssv3uMlFfcj3Q//KdUdUw4y7gC5iM/E4zXikk S5Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nw0znHoYqFmlQHfmP9vGaug/4bQeFA2Ii5syqOZRM0w=; b=pmjQX0JehW4MRgy3g2hGS+qJ5svyORXkqudv6JwE5Dpkrsjxxo6M62BT5+atcCSRBK TiKIiLAhsr1m+XAAow4H+YwVBYfGdRoEEgAsx06awQXTMfyVzqQUbL+772rd7Itwq1u5 InstLpGQf0I42+LH9MVXYLoL+kszX482GPYWyLSJv4ze6pQCT0u9VQdXCMucJwwBSPA4 /jK8xUUaU8KEUKCTUt4dI05D9LFtznxHTPV3HMgb3Z7U3WHNS3IdnDxxmsPNXlLYVJWb IAR6EjlySCxhnJ+VhK/+vKgZ0nXUa9FxggtmQxqP+3CpvtI+R1pEv1N4hHtFUj9UQX+3 N2sA== X-Gm-Message-State: AO0yUKUZ688UpK6rfihDaWW0JTiUKaTlQYhLK6RFJJTgGyYcfen7dT28 4I/tE+IPMOfTzyfRpEZIWAKyF9XdWE+4l1dx6l4= X-Google-Smtp-Source: AK7set8ySyLt7tsWPCV2OPrwF1S0AjANhGGOxOilN3lHPS4RzV0/PFn8kWcqD1pQSnpYmI/9RKiFfbWUEELIe2hBFDw= X-Received: by 2002:a17:906:3688:b0:878:4e40:d3e0 with SMTP id a8-20020a170906368800b008784e40d3e0mr156017ejc.13.1676633944273; Fri, 17 Feb 2023 03:39:04 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 17 Feb 2023 11:38:51 +0000 Message-ID: Subject: Re: Tip to reduce manual template declaration? To: Julien D Arques Cc: gcc-help Content-Type: multipart/alternative; boundary="000000000000aab84a05f4e3c2ca" X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000aab84a05f4e3c2ca Content-Type: text/plain; charset="UTF-8" On Fri, 17 Feb 2023, 07:24 Julien D Arques via Gcc-help, < gcc-help@gcc.gnu.org> wrote: > Hi, > I just finished a project that required to generate a static library out of > heavily templated code. > Why? > It has been a productivity nightmare and will be hard to extend if needs > be. > Many "extern template XXX" in .hpp and corresponding "template XXX" in .cpp > that killed my day (many possible type combinations). > But why did you do that? > That need may happen again in a future project and I really don't want to > reiterate what I did. > > Maybe modules will help but I need a solution that can be applied now. > > Do we have a hack in GCC to avoid this pitfall? > Just don't do it. Templates are implicitly instantiated as needed. Why do you need them defined in the static library, instead of letting users instantiate them as needed when compiling the headers? If you're doing it to make compiling those headers faster, that's a valid choice you've made, but you're trading more work for you when creating the library vs less work for the compiler when using the library. If you choose to do that, then I'm afraid there's no short cut to avoid doing the extra work. One alternative would be to define the entry points to the library API as non-template functions, and then just let the templates be implicitly instantiated for the definitions of those functions in the library. But that would mean designing a different API and that might be just as much work (if it's even practical to do that). --000000000000aab84a05f4e3c2ca--