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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:10:23+00:00 2026-06-15T03:10:23+00:00

I want a variadic template that simply accepts unsigned integers. However, I couldn’t get

  • 0

I want a variadic template that simply accepts unsigned integers.
However, I couldn’t get the following to work.

struct Array
{
    template <typename... Sizes> // this works
    // template <unsigned... Sizes> -- this does not work (GCC 4.7.2)
    Array(Sizes... sizes)
    {
        // This causes narrowing conversion warning if signed int is supplied.
        unsigned args[] = { sizes... };
        // ...snipped...
    }
};

int main()
{
    Array arr(1, 1);
}

Any help appreciated.

EDIT: In case you’re wondering, I’m trying to use variadic template to replicate the following.

struct Array
{
    Array(unsigned size1) { ... }
    Array(unsigned size1, unsigned size2) { ... }
    Array(unsigned size1, unsigned size2, unsigned size3) { ... }
    // ...
    Array(unsigned size1, unsigned size2, ..., unsigned sizeN) { ... }
};
  • 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-15T03:10:24+00:00Added an answer on June 15, 2026 at 3:10 am

    I’m not sure why you expected that to work. Clang tells me the error is unknown type name 'Sizes' in the declaration of the constructor. Which is to be expected, since Sizes isn’t a type (or rather, a template pack of types), it’s a template pack of values.

    It’s unclear what exactly you’re trying to do here. If you pass integral values in as template parameters, what are the constructor parameters supposed to be?


    Update: With your new code all you need is a static_cast<unsigned>().

    struct Array
    {
        template <typename... Sizes> // this works
        Array(Sizes... sizes)
        {
            unsigned args[] = { static_cast<unsigned>(sizes)... };
            // ...snipped...
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having hard time using variadic template with the following problem. Suppose that
C++0x thread library or Boost.thread define a non-member variadic template function that locks all
I want to fill the template parameters passed to a variadic template into an
Possible Duplicate: trailing return type using decltype with a variadic template function I want
I have the following class template: template<class T, unsigned N> class MyClass; where T
This example uses a common variadic template and function. I want to print out
The following code is an attempt to write a variadic function that acts like
I have a tuple of types encoded as template<class... T>struct packed; I want to
I want to use type-safe variadic functions introduced in C++11, but not with different
I have a template class Foo that takes two (or more) template arguments. 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.