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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:22:30+00:00 2026-05-23T05:22:30+00:00

If I have a class called Tuple<T, SIZE> and I want, let’s say, 20

  • 0

If I have a class called Tuple<T, SIZE> and I want, let’s say, 20 different float templates instantiated when compiling the library (so that the user does not encounter linking errors):

template Tuple<float, 1>;
template Tuple<float, 2>;
...
template Tuple<float, 20>;

Is there any way to recursively perform the above? And maybe allow it to be flexible so that I can put it any number I would like and it instantiates the classes for me?

EDIT: What I have tried so far (does not seem to work):

template <typename T, unsigned int MAX_RANGE>
class AllTuples
{
  Tuple<T, MAX_RANGE> y;
  AllTuples<T, MAX_RANGE - 1> x;
};

template <typename T>
class AllTuples<T, 1>
{
  Tuple<T, 1> x;
};
AllTuples<float, 10>;
  • 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-23T05:22:30+00:00Added an answer on May 23, 2026 at 5:22 am

    I’m sorry you are out of luck. Unless you use a preprocessor metaprogramming library (boost.pp), there is no way to automate that. Not with template metaprogramming.

    What you have produced there are implicit instantiations of Tuple<float, N>. But implicit instantiations have two important differences to explicit instantiations

    1. They won’t instantiate all member definitions (only those that are immediately needed are instantiated). Other definitions are only instantiated when they are used.
    2. The implicit instantiation of used member definitions cannot be used as a definition source for other translation units.

    For the latter, since I’m not aware of the reason for that, I will just quote the spec.

    A non-exported template must be defined in every translation unit in which it is implicitly instantiated (14.7.1), unless the corresponding specialization is explicitly instantiated (14.7.2) in some translation unit; no diagnostic is required.

    That may have to do with linker complications, because implicit instantiations for the same template can occur multiple times in multiple translation units, so they need special handling. Explicit instantiations and non-inline functions can’t.

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

Sidebar

Related Questions

I have a class called Trial which has_many results. Now What I want to
I have a Ruby class called LibraryItem . I want to associate with every
I have a class called myClass, which returns cv::Scalar type, and I want to
I have class called GroupItem, i can store any type here say int, string,
I have a container class (called Atom) that I want to store objects of
I have a simple class called Tuple. which looks like this : class tuple
I have a class called: ComplexNumber and I have a string that I need
I have a class called Account public class Account { public double balance =
I have a class called Metadata, which is declared within the namespace A::B::C ,
I have a class called Flamethrower which naturally has its own ammunition that is

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.