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 9019081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:41:27+00:00 2026-06-16T04:41:27+00:00

Other than the preprocessor, how can I conditionally enable/disable explicit template instantiations? Consider: template

  • 0

Other than the preprocessor, how can I conditionally enable/disable explicit template instantiations?

Consider:

template <typename T> struct TheTemplate{ /* blah */ };

template struct TheTemplate<Type1>;
template struct TheTemplate<Type2>;
template struct TheTemplate<Type3>;
template struct TheTemplate<Type4>;

Under some compilation conditions, Type3 is the same as Type1 and Type4 is the same as Type2. When this happens, I get an error. I’d like to detect that the types are the same and not instantiate on Type3 and Type4 as in

// this does not work
template struct TheTemplate<Type1>;
template struct TheTemplate<Type2>;
template struct TheTemplate<enable_if<!is_same<Type1, Type3>::value, Type3>::type>;
template struct TheTemplate<enable_if<!is_same<Type2, Type4>::value, Type4>::type>;

I’ve diverted myself trying enable_if and SFINAE (and I believe I know why they fail), but only the preprocessor has worked (ugh). I’m thinking about putting the types in a tuple or variadic, removing duplicates, and then use the remainder for instantiation.

Is there a way to conditionally enable/disable explicit template instantiation based on template argument types?

  • 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-06-16T04:41:28+00:00Added an answer on June 16, 2026 at 4:41 am
    template <typename T> struct TheTemplate{ /* blah */ };
    
    template<int> struct dummy { };
    
    template struct TheTemplate<Type1>;
    template struct TheTemplate<Type2>;
    template struct TheTemplate<conditional<is_same<Type1, Type3>::value, dummy<3>, Type3>::type>;
    template struct TheTemplate<conditional<is_same<Type2, Type4>::value, dummy<4>, Type4>::type>;
    

    This still produces four explicit instantiations, but they won’t be duplicates in the case where Type3 is the same as Type1 (unless Type1 is dummy<3>!)

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

Sidebar

Related Questions

Other than using browser,How can I get the public key of a websites which
Other than that I don't know if I can reproduce it now that it's
Other than .NET or Java, which language can be used to write an application
Other than turning warnings off.. what can I do in my code to get
Other than the speed, what are the advantages/differences to each? i.e. can assembly do
Other than not being able to build Silverlight, can anyone tell me what the
Other than procmail what Unix tools can read an email via pipe? I have
Other than HTTP PUT and POST, what other methods can a web application designer
Other than using the Column chart and naming appropriately is it possible to create
Other than as a modulus operator, what does the percent sign do in PHP?

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.