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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:55:55+00:00 2026-05-26T22:55:55+00:00

So say I define a tuple as such: template<typename… Args> class Tuple { Method

  • 0

So say I define a tuple as such:

template<typename... Args>
class Tuple 
{
    Method () {...};
};

How do I define and access the instance variables for Tuple considering it can have an undefined number of them?

  • 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-26T22:55:56+00:00Added an answer on May 26, 2026 at 10:55 pm

    There are a couple of ways. The easiest one is to use structural recursion the way LISP does: a tuple is either

    • an empty tuple, or
    • a pair (head, tail) where head is the first element of the tuple and tail is a tuple containing the rest of the elements.

    In C++, this would look like the following:

    template <typename... Elems>
    struct tuple; // undefined
    
    template <>
    struct tuple<> { }; // empty tuple
    
    template <typename Head, typename... Tail>
    struct tuple<Head, Tail...> {
        Head first_elem;
        tuple<Tail...> rest;
    };
    

    Then you need a get<n> function template to actually access the elements by index; it should be rather easy to implement if you grok how the tuple itself is recursively defined.

    As I said, there are other, trickier, implementation methods – for various reasons the above is not how most real-world std::tuple implementations do it.

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

Sidebar

Related Questions

Okay, simple template question. Say I define my template class something like this: template<typename
Say I define this descriptor: class MyDescriptor(object): def __get__(self, instance, owner): return self._value def
Say I want to define that an URI such as: myapp://path/to/what/i/want?d=This%20is%20a%20test must be handled
Say you define the following: class Person(name: String, age: Int) { def toXml =
Let's say that I want to define a module Pair in com.mycompany.common such that
I want to know Can I define any function application wide ? like say
If I declare a constant say #define MONTHS =12 in C, I am aware
I am a newbie and just learned that if I define say package my.first.group.here;
Lets say I want to define 2 styles. .color_red { color: Red; } .banner
Say in my web.xml file, I define a servlet like so: <url-pattern>/MyURL/*</url-pattern> How do

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.