On Wed, 27 Nov 2024 at 00:14, Thiago Macieira via Std-Discussion <std-discussion@lists.isocpp.org> 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/