Date: Sun, 1 Dec 2024 12:23:07 +0800
On Wed, 27 Nov 2024 at 00:14, Thiago Macieira via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> On Monday 25 November 2024 18:48:10 Pacific Standard Time Yongwei Wu via
> Std-
> Discussion wrote:
> > 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.
>
> Experience says that fold operations run into compiler-imposed limits
> faster
> than regular template expansions. You can convert one into the other this
> way
> though:
>
> auto print = [&sep](const auto &arg) { cout << arg << sep; return 0; };
> int dummy[] = { print(args)..., 0 };
> (void) dummy;
>
Good transformation.
Just one side-note: Apparently GCC generates much better assembly output
with the fold expression. While Clang generates identical outputs, they are
not close to the GCC fold-expression output.
std-discussion_at_[hidden]> wrote:
> On Monday 25 November 2024 18:48:10 Pacific Standard Time Yongwei Wu via
> Std-
> Discussion wrote:
> > 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.
>
> Experience says that fold operations run into compiler-imposed limits
> faster
> than regular template expansions. You can convert one into the other this
> way
> though:
>
> auto print = [&sep](const auto &arg) { cout << arg << sep; return 0; };
> int dummy[] = { print(args)..., 0 };
> (void) dummy;
>
Good transformation.
Just one side-note: Apparently GCC generates much better assembly output
with the fold expression. While Clang generates identical outputs, they are
not close to the GCC fold-expression output.
-- Yongwei Wu URL: http://wyw.dcweb.cn/
Received on 2024-12-01 04:23:20