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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:11:07+00:00 2026-06-04T17:11:07+00:00

Here is a short program to print tuples using code adapted from answers from

  • 0

Here is a short program to print tuples using code adapted from answers from Johannes Schaub – litb and Luc Danton.

#include <iostream>
#include <tuple>

template<int ...>
struct seq { };

template<int N, int ...S>
struct gens : gens<N-1, N-1, S...> { };

template<int ...S>
struct gens<0, S...> {
  typedef seq<S...> type;
};

template <int ...S, typename ...T>
void print(const std::tuple<T...> & tup, seq<S...> s) {
  int res[] = { (std::cout << std::get<S>(tup) << " ", 0)... };
  std::cout << std::endl;
}

int main() {
  std::tuple<double, int, char> tup(1.5, 100, 'c');
  print(tup, gens<std::tuple_size<decltype(tup)>::value >::type());
  return 0;
}

The second argument of print will always be always be gens<N>::type(), where N is the size of the tuple. I am trying to eschew the second argument to print by providing a default argument:

template <int ...S, typename ...T>
void print(const std::tuple<T...> & tup, seq<S...> s = gens<std::tuple_size<decltype(tup)>::value >::type()) {
  int res[] = { (std::cout << std::get<S>(tup) << " ", 0)... };
  std::cout << std::endl;
}

However, the result is a compiler error:

tmp5.cpp: In function ‘void print(const std::tuple<_Elements …>&, seq) [with int …S = {}; T = {double, int, char}]’:
tmp5.cpp:23:12: error: incomplete type ‘std::tuple_size&>’ used in nested name specifier

Do you know of any way to provide S... without the second argument to functions like print?

  • 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-04T17:11:08+00:00Added an answer on June 4, 2026 at 5:11 pm

    No, there is not.

    As a matter of fact, this issue is not restricted to variadic template, it occurs for all template functions: the template type of an argument cannot be deduced from its default value.

    template <typename T>
    void func(T = 0) {} // expected-note {candidate template ignored:\
                                          couldn't infer template argument 'T'}
    
    int main() {
      func(); // expected-error {no matching function for call to 'func'}
    }
    

    You need to switch gears.

    The easiest way to do so would be to provide an overload that would be tasked with passing the second argument. After all, default arguments are just syntactic sugar to avoid writing a forwarding function.

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

Sidebar

Related Questions

Here is my short assembly program: ; This code has been generated by the
So here's a snippet of my code: struct dv_nexthop_cost_pair { unsigned short nexthop; unsigned
I am currently using the below code to run a process and print its
Here's a short test program: sub foo($;@) { my $sql = shift; my @params
Here is a C program: int main() { short int i = 0; for(
For those who haven't worked with the Google Docs editor here's a short explanation
First question here: it is a very short yet fundamental thing in Java that
Here's the following algorithm: int encryption(int a, int b) { short int c, c2;
Short question - how do you define your view models? Here are some of
The documentation I am referencing is here, and is fairly short and to the

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.