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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:56:55+00:00 2026-06-02T07:56:55+00:00

I was looking at How to properly use references with variadic templates , and

  • 0

I was looking at “How to properly use references with variadic templates,” and wondered how far comma expansion can go.

Here’s a variant of the answer:

inline void inc() { }

template<typename T,typename ...Args>
inline void inc(T& t, Args& ...args) { ++t; inc(args...); }

Since variadic arguments are expanded to a comma-separated list of their elements, are those commas semantically equivalent to template/function-argument separators, or are they inserted lexically, making them suitable for any (post-preprocessor) use, including the comma operator?

This works on my GCC-4.6:

// Use the same zero-argument "inc"

template<typename T,typename ...Args>
inline void inc(T& t, Args& ...args) { ++t, inc(args...); }

But when I tried:

// Use the same zero-argument "inc"

template<typename T,typename ...Args>
inline void inc(T& t, Args& ...args) { ++t, ++args...; }

I kept getting parsing errors, expecting the “;” before the “…”, and that “args” won’t get its pack expanded. Why doesn’t it work? Is it because if “args” is empty, we get an invalid blob of punctuation? Is it legal, and my compiler isn’t good enough?

(I’ve tried surrounding “args” in parentheses, and/or use post-increment; neither worked.)

  • 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-02T07:56:56+00:00Added an answer on June 2, 2026 at 7:56 am

    Unpacking is only allowed in certain contexts, and comma separated statements doesn’t belong to them. Using your words: The expansion is semantically and not lexically. However, it doesn’t matter because there are several other ways of doing it. There are already some kind of patterns/idioms to write simple variadic functions. One way of doing it:

    Use a helper template function, that does nothing at all:

    template <typename ...Args>
    void pass(Args&&...) { }
    

    Instead of using the comma operator, pass the expressions to this function:

    template <typename ...Args>
    void inc(Args&&... args)
    {
        pass(++std::forward<Args>(args)...);
    }
    

    You can use the comma operator within the expansion, if the expressions have to be more complex. This might be useful in your case, if some operator++ have return type void:

        pass((++std::forward<Args>(args), 0)...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just going to use the FileUpload.FileBytes property but looking into the respective
I'm looking for some examples or sample code for properly organizing my code for
in Objective-C if I need to add additional method to UIButton I can use
I'm trying to understand how to properly use mod_rewrite. I have posts in my
Hey, I'm currently looking into how to use AndEngine together with the phone's GPS
I'm looking for some sort of very basic privilege escalation example that I can
My question is about properly binding the property of one element to another. Here
I'm looking to implement a property class for appengine, very similar to the existing
I'm looking for a way to set the checked property based on an integer
I'm looking for a way to allow a property in a C# object to

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.