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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:44:38+00:00 2026-06-09T01:44:38+00:00

Here is my code (of which I’m not sure it’s right even): template<typename… list>

  • 0

Here is my code (of which I’m not sure it’s right even):

template<typename... list> struct typeList;

template<typename, typename> struct zipper;
template<typename...L, typename...R> struct zipper<typeList<L...>, typeList<R...>>
{
    typedef std::tuple<std::pair<L,R>...> tuplez;
    static_assert(sizeof...(L)==sizeof...(R), "Mismatch number of Args...");

    static void print()
    {
    std::cout<<"The types are: "<<std::endl;
    for(int i=0; i<std::tuple_size<tuplez>::value ; ++i)
    std::cout<< "first : "<< typeid(typename std::tuple_element<i, tuplez>::type::first_type).name()<<
        "second : "<<typeid(typename std::tuple_element<i, tuplez>::type::second_type).name() <<std::endl;
    }
};

First of all I’m amazed how come my implementation of zipper is so small (must be something wrong I’m damn sure) . If my implementation is wrong, please lemme know why it’s wrong rather than giving me solution.

Also If I run this code (zipper<typeList<int,double>, typeList<char,int>>::print();) , I get tons of error :
the value of 'i' is not usable in a constant expression (from my gcc 4.7.1)

Here is full list of error (from ideone) with complete code:
http://ideone.com/67nxM

P.S : Kindly edit the suitable question title, I couldn’t comeup with any more reasonable.

Edit : Thanks to @KerrekSB and @Ugo for suggestions, here is the solution :

template<typename... list> struct typeList;

template<int n, typename T> struct printer
{
    static void print (){
        std::cout<< "first : "<< typeid(typename std::tuple_element<n, T>::type::first_type).name()<<
        "second : "<<typeid(typename std::tuple_element<n, T>::type::second_type).name() <<std::endl;
        printer<n-1,T>::print();
    }
};

template<typename, typename> struct zipper;
template<typename...L, typename...R> struct zipper<typeList<L...>, typeList<R...>>
{
    typedef std::tuple<std::pair<L,R>...> tuplez;

    static void print(){
    printer<std::tuple_size<tuplez>::value-1, tuplez>::print();
    }
};

template<typename T> struct printer<0,T>
{
    static void print (){
        std::cout<< "first : "<< typeid(typename std::tuple_element<0, T>::type::first_type).name()<<
        "second : "<<typeid(typename std::tuple_element<0, T>::type::second_type).name() <<std::endl;
    }
};
  • 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-09T01:44:40+00:00Added an answer on June 9, 2026 at 1:44 am

    Template non-type arguments must be constant expressions.
    i here is a runtime variable, you cannot use it to as a template argument.

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

Sidebar

Related Questions

I have some code here which works perfectly in firefox but not in chrome
here is code which returns size of struct without using sizeof keyword #include <iostream>
Here is my code which actually does all the GUI work for Domain(right side
Here is code which is not working class WeekDay < ActiveRecord::Base validates_inclusion_of :day, :in
Here is the code which test in IE8: var stack = []; function test()
Here is jquery code which hides my table cells with the ID of .style2:
Here is my code which checks if the file exists : #include<stdio.h> #include<zlib.h> #include<unistd.h>
Here is my code which is doing the conversion from hex to decimal. The
I have this piece of Open MP code here which performs an integeration of
I need help with a weird runtime error. Here's the code which gives it:

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.