Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 161201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:10:16+00:00 2026-05-11T11:10:16+00:00

I am using a library that consists almost entirely of templated classes and functions

  • 0

I am using a library that consists almost entirely of templated classes and functions in header files, like this:

// foo.h template<class T> class Foo {   Foo(){}   void computeXYZ() { /* heavy code */ } }; template<class T> void processFoo(const Foo<T>& foo) { /* more heavy code */ } 

Now this is bad because compile times are unbearable whenever I include one of those header files (and actually I include many of them in each of my compilation units).

Since as a template parameter I only use one or two types anyway I am planning to create, for each library header file, a file that contains only declarations, without the heavy code, like this:

// NEW: fwd-foo.h template<class T> class Foo {   Foo();   void computeXYZ(); }; template<class T> void processFoo(const Foo<T>& foo); 

And then one file that creates all the instantiations that I’ll need. That file can be compiled separately once and for all:

// NEW: foo.cpp #include 'foo.h' template class Foo<int>; template class Foo<double>; template void processFoo(const Foo<int>& foo); template void processFoo(const Foo<double>& foo); 

Now I can just include fwd-foo.h in my code and have short compile times. I’ll link against foo.o at the end.

The downside, of course, is that I have to create these new fwd-foo.h and foo.cpp files myself. And of course it’s a maintenance problem: When a new library version is released I have to adapt them to that new version. Are there any other downsides?

And my main question is:

Is there any chance I can create these new files, especially fwd-foo.h, automatically from the original foo.h? I have to do this for many library header files (maybe 20 or so), and an automatic solution would be best especially in case a new library version is released and I have to do this again with the new version. Are any tools available for this task?

EDIT:

Additional question: How can the newly supported extern keyword help me in this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:10:17+00:00Added an answer on May 11, 2026 at 11:10 am

    We use lzz which splits out a single file into a separate header and translation unit. By default, it would normally put the template definitions into the header too, however, you can specify that you don’t want this to happen.

    To show you how you might use it consider the following:

    // t.cc #include 'b.h' #include 'c.h'  template <typename T>  class A {   void foo () {     C c;     c.foo ();     b.foo ();   }   B b; } 

    Take the above file and copy it to ‘t.lzz’ file. Place any #include directives into separate $hdr and $src blocks as necessary:

    // t.lzz $hdr #include 'b.h' $end  $src #include 'c.h' $end  template <typename T>  class A {   void foo () {     C c;     c.foo ();     b.foo ();   }   B b; } 

    Now finally, run lzz over the file specifying that it places the template definitions into the source file. You can either do this using a $pragma in the source file, or you can use the command line option ‘-ts’:

    This will result in the following files being generated:

    // t.h //  #ifndef LZZ_t_h #define LZZ_t_h #include 'b.h' #undef LZZ_INLINE #ifdef LZZ_ENABLE_INLINE #define LZZ_INLINE inline #else #define LZZ_INLINE        #endif template <typename T> class A {   void foo ();   B b; }; #undef LZZ_INLINE #endif 

    And:

    // t.cpp //  #include 't.h' #include 'c.h' #define LZZ_INLINE inline template <typename T> void A <T>::foo ()           {     C c;     c.foo ();     b.foo ();   } #undef LZZ_INLINE 

    You can then run these through some grep/sed commands to remove the LZZ helper macros.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't believe there is a way. My only suggestion… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer The Transit layer is currently not available via the API.… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer EDIT: Okay, I've now tracked it down a lot further… May 12, 2026 at 1:19 am

Related Questions

My question is quite relevant to something asked before but I need some practical
While doing some random experimentation with a factorial program in C, Python and Scheme.
i am writing a game in C++ and have a level consisting of many
I am using a library that has headers without the .h This defeats visual

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.