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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:14:25+00:00 2026-05-26T11:14:25+00:00

I saw a blog post which used non-type variadic templates (currently not supported by

  • 0

I saw a blog post which used non-type variadic templates (currently not supported by gcc, only by clang).

template <class T, size_t... Dimensions>
struct MultiDimArray { /* ... */ };

The example in the post compiles fine but I failed to get it to work with function templates.

Can anyone help figuring out the correct syntax (if such exists)?

int max(int n) { return n; } // end condition

template <int... N> // replacing int... with typename... works
int max(int n, N... rest) // !! error: unknown type name 'N'
{
    int tmp = max(rest...);
    return n < tmp? tmp : n;
}

#include <iostream>
int main() 
{
   std::cout << max(3, 1, 4, 2, 5, 0) << 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-05-26T11:14:26+00:00Added an answer on May 26, 2026 at 11:14 am

    You are simply confusing type names and non-type names. What you want simply doesn’t work.

    You can probably use variadic non-type templates in functions, but not as (non-template) arguments:

    template <int N, int... Rest>
    int max()
    {
        int tmp = max<Rest...>();
        return N < tmp ? tmp : N;
    }
    
    std::cout << max<3, 1, 4, 2, 5, 0>() << std::endl;
    

    … although I haven’t tested this and I’m not sure how this should work given that you need to have a partial specialisation as the base case. You could solve this by dispatching to a partially specialised struct:

    template <int N, int... Rest>
    struct max_t {
        static int const value = max_t<Rest...>::value > N ? max_t<Rest...>::value : N;
    };
    
    template <int N>
    struct max_t<N> {
        static int const value = N;
    };
    
    
    template <int... NS>
    int max()
    {
        return max_t<NS...>::value;
    }
    

    This will work.

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

Sidebar

Related Questions

I saw a blog post the other day that had a screen shot of
I recently saw a blog post showing off different displays that some software development
So I saw this great blog post, Experimenting with Node.js . I decided to
I was reading a blog post and saw a groovy snippet that looked lik
i am confused by the concept of on-demand loading I saw this blog post
I like the pattern I saw in this blog post ( http://marekblotny.blogspot.com/2009/04/conventions-after-rewrite.html ), where
I saw Jeff Atwood's post on his blog about Exception Driven Programming and I
I saw Scott Guthrie's post about helper methods via his blog . Specifically this:
So a while back (6 months+) I saw a blog post where the author
I saw a comment on Ben Nadel's blog where Stephen Rushing posted a loader,

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.