The C++20 feature std::source_location is used to capture information about the context in which a function is called.
When I try to use it with a variadic tem
Just put your arguments in a tuple, no macro needed.
#include
#include
template
void debug(
std::tuple args,
const std::source_location& loc = std::source_location::current())
{
std::cout
<< "debug() called from source location "
<< loc.file_name() << ":" << loc.line() << '\n';
}
And this works*.
Technically you could just write:
template
void debug(
T arg,
const std::source_location& loc = std::source_location::current())
{
std::cout
<< "debug() called from source location "
<< loc.file_name() << ":" << loc.line() << '\n';
}
but then you'd probably have to jump through some hoops to get the argument types.
* In the linked-to example, I'm using because that's what compilers accept right now. Also, I added some code for printing the argument tuple.