public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Tip to reduce manual template declaration?
@ 2023-02-17  7:23 Julien D Arques
  2023-02-17 11:38 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Julien D Arques @ 2023-02-17  7:23 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 539 bytes --]

Hi,
I just finished a project that required to generate a static library out of
heavily templated code.

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).

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?

Thanks,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tip to reduce manual template declaration?
  2023-02-17  7:23 Tip to reduce manual template declaration? Julien D Arques
@ 2023-02-17 11:38 ` Jonathan Wakely
  2023-02-17 12:02   ` Julien D Arques
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2023-02-17 11:38 UTC (permalink / raw)
  To: Julien D Arques; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1522 bytes --]

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).

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tip to reduce manual template declaration?
  2023-02-17 11:38 ` Jonathan Wakely
@ 2023-02-17 12:02   ` Julien D Arques
  0 siblings, 0 replies; 3+ messages in thread
From: Julien D Arques @ 2023-02-17 12:02 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 2078 bytes --]

Yes,
Actually the net result is the productivity bump for the devs I pay.
Before that the trend was to take a small break. Now, they are focused
because the compilation of the whole code is almost instant.

I am a business man before being a dev. Every dollar paid must be
productive. I don't regret my move but it was painful to do.

Le ven. 17 févr. 2023 à 12:39, Jonathan Wakely <jwakely.gcc@gmail.com> a
écrit :

>
>
> 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).
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-17 12:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-17  7:23 Tip to reduce manual template declaration? Julien D Arques
2023-02-17 11:38 ` Jonathan Wakely
2023-02-17 12:02   ` Julien D Arques

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).