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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:31:11+00:00 2026-06-17T22:31:11+00:00

Can anyone confirm for me that the following code (which includes nested expansions of

  • 0

Can anyone confirm for me that the following code (which includes nested expansions of a function parameter pack) is allowed in C++11 (I would certainly appreciate any references to the standard):

template<class ... VFTs> int variadic_fun(VFTs ... vfts) { 
  return sizeof ...(vfts); 
}


template<int ... Ns> struct IntPack {
  template<class ... MemTs> static int variadic_memfun(MemTs ... MemArgs) {
    return variadic_fun(([=]() {
      cout << "MemArgs = " <<  MemArgs << "\n";
      cout << "Ns = " << Ns;
      // Note the nested expansion of MemArgs here:
      cout << "variadic_fun(MemArgs...) = " << variadic_fun(MemArgs ...) << "\n";
      cout << "MemArgs[Ns] = " <<  MemArgs[Ns] << "\n";
      return 0;
    })()...);
  }  
};


int main() {
  IntPack<0, 1, 2>::variadic_memfun("123", "ABC", "XYZ");
}

Thanks!
P.S. Since someone asked below, this code works with my patch of clang that implements generic lambdas (Not yet standard C++, still just a proposal) – I have not tried it with any other compilers – and am not sure if it works with the latest clang trunk currently (it probably does) – I would certainly welcome any information on whether it compiles with any of the mainstream compilers that implement variadics and lambdas.

  • 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-17T22:31:12+00:00Added an answer on June 17, 2026 at 10:31 pm

    Yes, this is valid, and Clang supports it.

    $ clang++ your-example.cpp -std=c++11
    $ ./a.out
    MemArgs = 123
    Ns = 0variadic_fun(MemArgs...) = 3
    MemArgs[Ns] = 1
    MemArgs = ABC
    Ns = 1variadic_fun(MemArgs...) = 3
    MemArgs[Ns] = B
    MemArgs = XYZ
    Ns = 2variadic_fun(MemArgs...) = 3
    MemArgs[Ns] = Z
    

    The relevant rule is [temp.variadic]p5:

    An appearance of a name of a parameter pack that is not expanded is ill-formed.

    That does not apply in this case, since

    A parameter pack whose name appears within the pattern of a pack expansion is expanded by that pack expansion.

    … and the uses of the pack within the lambda are within the pattern of the function argument pack expansion.

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

Sidebar

Related Questions

Can anyone tell me why this code would not be working? $('body').on('test', function() {
Can anyone confirm that after changing the Apple Push Certificate to follow the new
Following some excellent help from this forum, can anyone please confirm if this is
Can anyone confirm if there's an access 2003 runtime available to allow users to
My Get confirm isn't triggering the query? Can anyone see what I'm doing wrong?
In MonoDevelop I have the following code which compiles: int[] row = new int[indices.Count]{};
I'm new to Umbraco and MVC - can anyone help with the following? I
Can anyone confirm what the standard says about the default return type of vararg
Does anyone know a way i can achieve the following? When a user enters
I'm hoping someone can confirm whether or not the following scenario is an issue

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.