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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:42:25+00:00 2026-06-04T21:42:25+00:00

I have a tuple of types encoded as template<class… T>struct packed; I want to

  • 0

I have a tuple of types encoded as

template<class... T>struct packed;

I want to unpack it later like

template<class T>struct unpack;
template<class... T>
struct unpack<packed<T...>>{
      //how to define the unpacked type here?
};

So that, I can use it as

template<class Packed>
struct foo : unpack<Packed>::type...{};

Note, I do not want to unpack the elements of the tuple immediately like

template<class... T>
struct unpack<packed<T...>> : T...{};
template<class Packed>
struct foo: unpack<Packed>{};

I am interested to have elements of the tuple ‘packed’ to be direct base classes of ‘foo’ instead of indirect base classes via ‘unack’. Also the elements of the type tuple are distinct non-primitive and non-final types.

To make the example more detailed,

template<class T, T... Values> 
struct variadic_values{};
template<class T,T From,class Encode,T To>
struct value_gen;
template<class T, T From, T... Values, T To>
struct value_gen<T,From,variadic_values<T,Values...>,To>
{
   using type = typename value_gen<T,From+1,variadic_values<T,Values...,From>,To>::type;
};
template<class T,T From,T... Values>
struct value_gen<T,From,variadic_values<T,Values...>,From>
{
    using type = variadic_values<T,Values...>;
};
template<class T, T From,T To>
using values = typename value_gen<T,From,variadic_values<T>,To>::type;
template<unsigned Idx,class T>
struct node{};
template<class Idx,class... Ts>
struct unpack;
template<unsigned... Idx,class...Ts>
struct unpack<variadic_values<unsigned,Idx...>,Ts...> : node<Idx,Ts>...{};
template<class... Ts>
class foo : unpack<values<unsigned,0,sizeof...(ts)>,Ts...>{};

What I am interested to have is that foo should be directly derived from nodes

  • 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-04T21:42:26+00:00Added an answer on June 4, 2026 at 9:42 pm

    Second try …

    Would it be acceptable to specialize foo to accept a special tag type, which passes in the type and corresponding index?

    template<typename T, unsigned N>
    struct tagged_node
    { };
    
    template<typename...>
    struct foo;
    
    // specialize for case where pack is list of special tag types.
    template<typename... T, unsigned... N>
    struct foo<tagged_node<T, N>...> : node<T,N>...
    { };
    
    template<typename T, unsigned N>
    struct wrapped_node
    { typedef node<T, N> type; };
    
    template<typename T, typename U>
    struct make_node_foo_impl;
    
    template<typename... T, unsigned... I>
    struct make_node_foo_impl<packed<T...>, index_tuple<I...>>
    {
      typedef foo<tagged_node<T, I>...> type;
    };   
    
    template<typename... T>
    struct make_node_foo
    : make_node_foo_impl<packed<T...>, to_index_tuple<T...>>
    { };  // inherits 'type'
    

    (Untested, sorry, I have to go out!)

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

Sidebar

Related Questions

I have some generic types, like the following: public struct Tuple<T1, T2> { ...
A hypothetical variadic template tuple class would, as far as I can tell, have
Say you have a tuple and want to generate a new tuple by applying
Suppose I have a tuple of (1, 2, 3) and want to index a
I have a 3-tuple list like the following [I added line breaks for readability]:
I have a 3-tuple data set (X,Y,Z points) that I want to plot using
I have following code: class TR_AgentInfo : public tuple< long long, //AgentId string, //AgentIp
If I have a class that takes a tuple in its constructor among other
I have a tuple, INSTALLED_APPS, and I want to merge extra items into it
That is, I'd like to have a tuple of values. The use case on

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.