Date: Tue, 26 Nov 2024 05:35:57 +0000
> On Monday, November 25th, 2024 at 9:48 PM, Yongwei Wu <wuyongwei_at_[hidden]> wrote:
>
> On Tue, 26 Nov 2024 at 04:13, Smith, Jim via Std-Discussion <std-discussion_at_[hidden]> wrote:
>
>> Hi All,
>>
>> Is there already a proposal for making the C++ for loop generic, for example able to print a function parameter pack?
> As Andrey said, fold expressions can usually do. Specifically, with the comma operator.
>
> This is an example I usually use in training:
>
> template <typename T, typename... Args>
>
> void printWithSeparator(const T& sep, const Args&... args)
>
> {
>
> ((cout << args << sep), ...);
>
> }
>
> Replace with the `(cout << args << sep)` part with what you want to do with the arguments.
I appreciate the feedback.
I'm familiar with how to access the function parameter pack, it was mentioned here as example application for generic loop.
My question was about a proposal for implementing generic for loop.
This link wg21.link/p1306 as Ville Voutilainen mentioned in his reply provided the answer.
- James Smith
>
> On Tue, 26 Nov 2024 at 04:13, Smith, Jim via Std-Discussion <std-discussion_at_[hidden]> wrote:
>
>> Hi All,
>>
>> Is there already a proposal for making the C++ for loop generic, for example able to print a function parameter pack?
> As Andrey said, fold expressions can usually do. Specifically, with the comma operator.
>
> This is an example I usually use in training:
>
> template <typename T, typename... Args>
>
> void printWithSeparator(const T& sep, const Args&... args)
>
> {
>
> ((cout << args << sep), ...);
>
> }
>
> Replace with the `(cout << args << sep)` part with what you want to do with the arguments.
I appreciate the feedback.
I'm familiar with how to access the function parameter pack, it was mentioned here as example application for generic loop.
My question was about a proposal for implementing generic for loop.
This link wg21.link/p1306 as Ville Voutilainen mentioned in his reply provided the answer.
- James Smith
Received on 2024-11-26 05:36:10