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

  • Home
  • SEARCH
  • 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 8613503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:53:37+00:00 2026-06-12T04:53:37+00:00

Somehow I don’t get how variadic template parameter packs are expanded. What’s wrong with

  • 0

Somehow I don’t get how variadic template parameter packs are expanded. What’s wrong with thie following code?

#include <iostream>

template <typename T>
struct print_one
{
    static void run(const T& t)
    {
        std::cout << t << ' ';
    }
};

template<typename... Args>
void print_all(Args&&... args)
{
    // the next line doesn't compile:
    print_one<Args>::run(std::forward<Args>(args))...;
}

int main()
{
    print_all(1.23, "foo");
}

Clang says, Expression contains unexpanded parameter packs 'Args' and 'args'. Why?

  • 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-12T04:53:38+00:00Added an answer on June 12, 2026 at 4:53 am

    The ... has to go inside the function call parentheses:

    print_one<Args>::run(std::forward<Args>(args)...);
    

    Obviously, that won’t work for your function that takes only a single argument, so you need to find a way to expand the calls into a function call or other allowed construct:

    // constructing a dummy array via uniform initialization
    // the extra 0 at the start is to make it work when the pack is empty
    int dummy[]{0, (print_one<Args>::run(std::forward<Args>(args)), 0)...};
    
    // or, if your compiler doesn't support uniform initialization
    int dummy[] = {0, (print_one<Args>::run(std::forward<Args>(args)), 0)...};
    
    // or, calling a dummy function
    template<typename... Args> void dummy(Args...) {}
    dummy((print_one<Args>::run(std::forward<Args>(args)), 0)...);
    
    // or, constructing a temporary dummy object
    struct dummy { dummy(std::initializer_list<int>) {} };
    dummy{(print_one<Args>::run(std::forward<Args>(args)), 0)...};
    
    // or, constructing a temporary initializer list
    std::initializer_list<int>{(print_one<Args>::run(std::forward<Args>(args)), 0)...};
    

    Note the use of the comma operator to turn the void return of print_one into a value suitable to place in an argument list or initializer expression.

    The initializer-list forms are preferred to the function call forms, as they are (supposed to be) ordered LTR which function call arguments are not.

    The forms where a parameter pack expansion can occur are covered by 14.5.3 [temp.variadic]:

    4 – […] Pack expansions can occur in the following contexts:

    • […]

    Your original code is illegal because although textually it might appear that it should produce a statement consisting of a number of comma-operator expressions, that is not a context allowed by 14.5.3:4.

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

Sidebar

Related Questions

somehow I don't understand the working concept of the query parameter CALLER_IS_SYNCADAPTER. Its default
Somehow I don't seem to get it. 8-} I have an activity in which
Somehow, i don't get it how i can set the height of jScrollPane. http://tinyw.in/BLrg
This question has been asked more then once, but somehow I don't get things
I don't believe that I am using any 3.0 specific APIs, but somehow whenever
Somehow my master and my origin/master branch have diverged. I actually don't want them
So, i recently found this term related somehow to neural networks, but I don't
Somehow my code doesn't work any more (it did work before with the exact
somehow I get never any results when I call: select * from table_1 t1
Somehow I managed to get QtCreator's text mode into --COMMAND-- or --INSERT-- mode. 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.