C / C++ tell source file location
C has long had the __FILE__ macro, which expands to a string literal containing the name or path to the current source file.
C++ provides a much more powerful mechanism to programmatically determine the source file location via
source_location
in the <source_location> header introduced in C++20.
This capability is particularly powerful for logging and debugging, as shown in the example linked above that a function’s caller can be located by source file and line number without the caller needing to explicitly pass that information.