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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:16:33+00:00 2026-06-12T00:16:33+00:00

<>I use C++ and plan a library with classes that have about 100 template

  • 0

<>I use C++ and plan a library with classes that have about 100 template parameters. Of course, I worried that having n template parameters, if the user needs every combination, we have 2^n different classes, which is a kind of code explosion. However, a user would need to do 2^n instantiations for that.

My question is: What are the main technical issues with so many template parameters?

Notes:

  • With technical, I am not interested in subjective answers concerning readability, design etc. I mean facts like
    • runtime
    • code size
    • maximum number of templates allowed

Code sample:

// here we have 2, but I have 100 template parameters
template<typename T1, typename T2>
class Class
{
    T1 x;
    T2 y;
    int add(T1 _x, T2 _y) { return _x+_y; } // 4 instanciations possible?
    Class<T2, T1>* swap() { return new Class<T2, T1>(); } // always 2 instanciations?
};
  • 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-12T00:16:34+00:00Added an answer on June 12, 2026 at 12:16 am

    The main consideration would be code size, and that can have an impact on performance. Each different template instantiation will require the generation of all of the member functions that are used (or all, if the user does manual template instantiation). There will be no code reuse among the different template instantiations.

    Besides that, any element for which you provide a large number of arguments is hard to deal with. From the maintenance point of view, a declaration with 10 arguments is already hard to read. It will either extend multiple lines or else extend very wide in the line and it will be hard to determine by inspection that all arguments are in the correct position. Is that X the 7th or 8th argument? Yes, you can count them, but it becomes painful. If the number of arguments is 100, the problem is just exacerbated.

    Why do you want all those to be template arguments? Without any more information you will not get other suggestions, but there are most probably other designs for the same problem that don’t require that level of complexity. Maybe the arguments need not be known at compile time (they can be passed to functions/constructors in the form of arrays/vectors for non-type arguments), or maybe they can be grouped (one type template argument holding a set of related typedefs)…

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

Sidebar

Related Questions

In a project that makes heavy use of reflection to select classes based on
I have created a Windows Store class library. This contains some user controls and
I have a plan to make a network redirector on android. I’m considering use
I made a static library that was coded using ARC. I plan to distribute
I am writing a combinatorial test library that I plan to release into the
After the suggestion to use a library for my ajax needs I am going
I am writing a library that works alongside XNA. I have a base class
I had download Xenofex-MultiColumnTableViewForiOS-0b3fa88 library and plan to use it in my iOS project.
I Have is C Static Library for Camera. Now Plan is to develop C#/WPF
I'd like to use aspectj to profile a library. My plan was to mark

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.