Non-Terminal Variadic Parameters and Default Values--Bartlomiej Filipek

How to best use source_location?

Non-Terminal Variadic Parameters and Default Values

by Bartlomiej Filipek

From the article:

Currently, as of C++20, there’s no support for so called non-terminal variadic arguments. For example, we cannot write:

template <class ...Args> void func(Args&& ...args, int num=42);
func(10, 20); // error

As you can see, I wanted 10 and 20 to be passed as ...args and 42 as a default value for num. Compilers currently cannot resolve this code.

In this blog post, I’d like to show you a couple of tricks you can implement to avoid this issue. Knowing those techniques might help with things like logging functions where we could have std::source_location at the end of a function declaration...

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.