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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:05:20+00:00 2026-06-08T01:05:20+00:00

I wish to do something like this: template<typename …T> struct foo { bar<0 /*to

  • 0

I wish to do something like this:

template<typename ...T> struct foo
{
  bar<0 /*to index through types in pack*/ ,T...>::type var1;
  bar<1 /*to index through types in pack*/ ,T...>::type var2;
  ...
}

But how would I define bar? No recursion technique comes to mind to do this.

I want a general technique so that I could typedef any particular type from a type pack, not just the two shown in the example.

  • 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-08T01:05:21+00:00Added an answer on June 8, 2026 at 1:05 am
    #include <iostream>
    #include <typeinfo>
    
    template<class T, class T2, class... Args>
    class C
    {
    public:
       typedef T type1;
       typedef T2 type2;
    };
    
    int main()
    {
       typedef C<int, double, int, float> c;
       std::cout << typeid(c::type1).name() << " " << typeid(c::type2).name() << std::endl;
    }
    

    or mb something like this.

    #include <iostream>
    #include <typeinfo>
    
    template<int N, class T, class... Args>
    struct expand
    {
    public:
       typedef typename expand<N - 1, Args...>::type type;
    };
    
    template<class T, class... Args>
    struct expand<1, T, Args...>
    {
    public:
       typedef T type;
    };
    
    template<class... Args>
    class argsExpander
    {
    public:
       typedef typename expand<1, Args...>::type type1;
       typedef typename expand<2, Args...>::type type2;
    };
    
    template<class... Args>
    class C
    {
    public:
        typename argsExpander<Args...>::type1 var1;
        typename argsExpander<Args...>::type2 var2;
    };
    
    int main()
    {
       C<int, double, int, float> c;
       std::cout << typeid(c.var1).name() << " " << typeid(c.var2).name() << std::endl;
    }
    

    http://liveworkspace.org/code/7de289f128e86eb6006f576cbaf98991

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

Sidebar

Related Questions

Having trouble inheriting from a template class. Looks something like this: template<typename type> class
I wish to do something like this: return RedirectToAction<SomeController>(c => Index(someparameter)); How to do
I wish to do something like this: DECLARE @IgnoreNulls = 1; SELECT Col1, Col2
I wish to make something looking like this: http://img291.imageshack.us/img291/5571/bartablestyling.png (Right now i only have
I develop in C++, and sometimes I wish I could say something like this:
I wish to replace spaces in something like this: <span>5</span>SPACE<image href=mtgsymbol.png /> but when
I wish HTML could do something semantically equivalent to this; <dl class=main-list> <definitionitem> <dt>Some
I want to create something like this at run-time: <CWS> <Case name=10-040-00022> <CaseDetailsSet> <CaseDetail
I dream of creating a control which works something like this: <asp:SqlDataSource id=dsFoo runat=server
Is there any work around to do something like this work as expected? I

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.