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

  • Home
  • SEARCH
  • 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 7086133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:30:43+00:00 2026-05-28T07:30:43+00:00

I have a lot of template code. Since bad template code does not throw

  • 0

I have a lot of template code. Since bad template code does not throw a compiler error unless it is compiled, is there any way I can check which template functions the compiler actually ‘compiled’ and which were ignored altogether?

EDIT 2:

If a particular class template or function template is instantiated once, for any parameter types, then that is OK. I want the list of function/class templates that were never instantiated in any form.

One particular example is the following. They are two distinct template functions, and I would like to know if either or both is never instantiated.

template <typename T_InputItr, typename T_Distance>
void advance( T_InputItr& aItr, T_Distance aN, bidirectional_iterator_tag )

template <typename T_InputItr, typename T_Distance>
void advance( T_InputItr& aItr, T_Distance aN, random_access_iterator_tag )

EDIT: Currently, for classes, I instantiate them in the .cpp file manually like this:

template TClass<int>;

for all the types I am interested in. That’s well and good. But that is if I remember to do that. Sometimes I need to write a lot of small template classes/functions where I forget to instantiate some of the function/class templates manually and find out later down the road. I would like the compiler to tell me that.

Alternatively, if I could get the list of function/class templates that were instantiated (for any parameter), then I could compare that to the full list which I might grep for in the code.

Another benefit would be to ‘test’ which methods were compiled in a template class that uses type traits to selectively compile out certain functions. I want to be certain my logic for selecting the correct functions is correct before moving on.

  • 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. Editorial Team
    Editorial Team
    2026-05-28T07:30:44+00:00Added an answer on May 28, 2026 at 7:30 am

    Someone mentioned how “everything can be solved by adding a level of indirection” – you can add a static assert to each function and watch the compilation fail:

    template <typename T>
    struct Asserter
    {
      static const bool value = false;
    };
    
    template <typename T>
    struct Foo
    {
      void foo()
      {
        static_assert(Asserter<T>::value, "Foo::foo() is being compiled.");
      }
      void bar()
      {
        static_assert(Asserter<T>::value, "Foo::bar() is being compiled.");
      }
    };
    
    int main()
    {
      Foo<int> f;
      //f.foo();  // static assertion!
    }
    

    If you don’t want compilation to break at each step, you can instead emit a Boost static warning, or something with a similar effect.

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

Sidebar

Related Questions

At the moment, I have lot's of Java which does all kind of nifty
I have a template code: <html> <head> <title> My page </title> </head> <body> CODEWOULDCOMEHERE
i have already asked this question on asp.net forum, could not find any satisfactory
Is there any Sonar plugin to parse velocity templates to check the code quality?
I have to write a lot of code that's going to generate Knockout JS
Is there any language which has a form of code templating? Let me explain
I have the following code in C++ and I got the compilation error: a.cpp:
I have been using WinForms since the first framework introduced and invested a lot
I have a lot of code like this: #define WITH_FEATURE_X struct A { #ifdef
We have lot of object with this kind of design : Interface and several

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.